本文整理汇总了TypeScript中bunyan.createLogger函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createLogger函数的具体用法?TypeScript createLogger怎么用?TypeScript createLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createLogger函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
constructor(loggerOpts: LoggerOpts ) {
super()
const {name, devMode} = loggerOpts
if (devMode) {
let streams = buildDevOpts(loggerOpts.level)
let opts: LoggerOptions = {name}
if (streams) {
opts.streams = streams
}
this.logger = createLogger(opts)
} else {
this.logger = createLogger({name})
}
}
示例2: start
export function start(logger?:Logger):Promise<any> {
logger = logger || createLogger({
name: "express-typescript-sequelize",
stream: process.stdout,
level: "info"
});
let storageManager = new SequelizeStorageManager({database: "example", username: process.env.EXAMPLE_USERNAME || "username", password: ""}, logger);
return storageManager.init()
.then(() => {
return configureExpress(logger, storageManager)
.then((app:express.Application) => {
return congifureRoutes(app, logger, storageManager)
.then(() => {
return app;
});
})
.then((app:express.Application) => {
return new Promise((resolve) => {
var server = app.listen(3000, () => {
resolve(server);
});
});
})
});
}
示例3: runAsyncTest
public static async runAsyncTest(): Promise<void> {
let logger: bunyan.Logger = bunyan.createLogger({
level: "trace",
name: "cloco-node-client (test)",
});
let options: IOptions = {
encryptor: new AesEncryptor("This_is_an_encryption_passphrase"),
log: logger,
ttl: 60,
};
// initialize the client and load in the configuration.
let client: ClocoClient = new ClocoClient(options);
await client.init();
logger.info("cloco client initialized");
// check the state of the current cache.
logger.info(Cache.current);
logger.info(client.get<any>("default"));
// write to the cache.
let updated: any = {foo: "bar", updated: new Date()};
await client.put<any>("default", updated);
await client.put<any>("a-third-cob", "some updated text " + new Date().toString());
await client.put<any>("another-cob", "some encrypted text " + new Date().toString());
// check the state of the current cache.
logger.info(Cache.current);
AsyncTest.timer = setTimeout(() => AsyncTest.keepAlive(), 1000);
}
示例4: log
export function log(): bunyan.Logger {
if ( !_log ) {
_log = bunyan.createLogger( { name: 'no app'} );
_log.level(bunyan.WARN);
}
return _log;
}
示例5:
logger.init = (config) => { /** init method to initiate the creation of logger */
logger.root = bunyan.createLogger(
{
name: 'root',
serializers: { /** serializer converts App Objects passed to it to readable json format eg :
logger.info(object, 'This is a log ref for object');
*/
err: bunyan.stdSerializers.err,
req: bunyan.stdSerializers.req,
res: bunyan.stdSerializers.res
},
streams: [
{
level: config.systemConfig.log.level,
stream: process.stdout //type is defaulted to 'stream'
},
{
level: config.systemConfig.log.level, // this is the level of error logs
path: config.systemConfig.log.path, //path of log file where logs are going to be written to
// type is defaulted to 'file'
type: 'rotating-file', //this is responsible for creating back copies of log files overwriting default
period: '1d', //this is the period of rotation for creating back copies
count: 3, //this is the number of back copies to be made
}
],
src: true
}
);
}
示例6: it
it("when logger passed in options this should be used to init the logger.", function(): void {
let options: any = {};
options.log = bunyan.createLogger({
name: "unit-test",
});
Logger.init(options);
expect(Logger.log).toEqual(options.log);
});
示例7: init
/**
* Initializes the static logger.
* @param {IOptions} options The initialization options.
*/
public static init(options: IOptions): void {
if (options.log) {
Logger.log = options.log;
} else {
Logger.log = bunyan.createLogger({
name: "cloco-node-client",
});
}
Logger.log.debug("Logging is initialized.");
}
示例8: bunyanLogger
export function bunyanLogger(): Bunyan {
// add the global bunyan logger to std out
const streams = [];
streams.push({
stream: process.stdout,
});
return Bunyan.createLogger({
streams,
name: 'EliakarisBlog',
});
}
示例9: constructor
constructor(cfg?: any) {
cfg = cfg || {};
console.log("Configuring logger with platform stream", cfg);
this.platformStream = new PlatformStream(cfg);
this.root = bunyan.createLogger({
name: 'system',
streams: [{
type: 'stream',
level: cfg.level || 'info',
stream: this.platformStream
}]
});
}
示例10: constructor
constructor() {
this.caches = {
DEP_CACHE,
COMPILER_CACHE,
DEPLOY_DIR
};
this.logger = createLogger(LOGGER);
this.GAPI_KEY = process.env.GAPI_KEY;
this.scriptCompilerArgs = {};
this.styleCompilerArgs = {};
this.htmlCompilerArgs = { filters: FILTERS };
// Set up templates
this.templates = {};
const tempReg = new RegExp("(.*)\.template\..*");
const temps = glob.sync("*.template.*", { cwd: join(__dirname, "templates")});
temps.forEach(t => {
const m = t.match(tempReg);
if (!m) return;
const [_, name] = m;
const p = join(__dirname, "templates", t);
try {
const templater = require(p).default;
this.templates[name] = new templater();
} catch (e) {
console.log(`There was an error loading ${p}. Until it is fixed, template ${name} will not be available for use.`);
console.log(e);
}
});
// Set up fetchers
this.fetchers = {};
const fetchReg = new RegExp("(.*)\.fetcher\..*");
const fetchs = glob.sync("*.fetcher.*", { cwd: join(__dirname, "fetchers")});
fetchs.forEach(f => {
const m = f.match(fetchReg);
if (!m) return;
const [_, name] = m;
const p = join(__dirname, "fetchers", f);
try {
const fetcher = require(p).default;
this.fetchers[name] = new fetcher(fetcherArgs[name]);
} catch (e) {
console.log(`There was an error loading ${p}. Until it is fixed, fetcher ${name} will not be available for use.`);
console.log(e);
}
});
}