本文整理汇总了TypeScript中winston.Logger.add方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Logger.add方法的具体用法?TypeScript Logger.add怎么用?TypeScript Logger.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类winston.Logger
的用法示例。
在下文中一共展示了Logger.add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: moment
logger.unmute = () => {
if (muted) {
muted = false
logger.add(winston.transports.Console, {
level: 'trace',
levels: customLevels.levels,
handleExceptions: false,
colorize: true,
timestamp: function() {
return moment().format();
}
})
}
}
示例2: getLogger
export function getLogger (file: string): LoggerInstance {
let filepath = join(__dirname, `../../log/${file}`)
let logger = new Logger({
exitOnError: false,
transports: [
new transports.Console({
colorize: true,
handleExceptions: true,
json: false,
level: 'error'
})
]
})
// second logger for all logs on files daily rotated
logger.add(require('winston-daily-rotate-file'), {
colorize: false,
filename: filepath,
handleExceptions: true,
json: false,
level: 'silly',
maxFiles: 10,
maxsize: 100000000,
prepend: true,
prettyPrint: true,
timestamp: function (): string { return (new Date()).toTimeString() }
})
// stream to pipe with morgan
logger['morganStream'] = {
write: (message): void => {
logger.info(message)
}
}
return logger
}
示例3: require
filename: logDir+'log.txt',
colorize: false,
timestamp: true,
maxsize: 1024*1024*5 //5MB
})
]
});
require('winston-mongodb').MongoDB;
import parameters = require('../../core/parameters');
var disabled = parameters.getParameter('logger-db-disable', false);
if (!disabled) {
var conf = parameters.getDBParameter('logger-db', 'mongodb://localhost/portallogs');
logger.add(winston.transports.MongoDB, {
db: conf
});
}
// Uncomment this if you want to enable logzio logs!
// var logzioWinstonTransport = require('winston-logzio');
// var loggerOptions = {
// token: 'Your-token-here'
// };
// logger.add(logzioWinstonTransport, loggerOptions);
/**
示例4: new
import * as express from 'express';
import * as expressWinston from 'express-winston';
import * as winston from 'winston';
import config from './Config';
import IAppLogger from './IAppLogger';
const logger = new (winston.Logger)({
level: config.get('LOG_LEVEL')
});
if (config.get('NODE_ENV') !== 'test') {
logger.add(winston.transports.Console);
}
export interface ILoggerMiddleware {
logger: express.RequestHandler;
errorLogger: express.ErrorRequestHandler;
}
const loggerSingleton: IAppLogger = logger;
const LoggerMiddleware: ILoggerMiddleware = {
logger: expressWinston.logger({
winstonInstance: logger
}),
errorLogger: expressWinston.errorLogger({
winstonInstance: logger
})
};
export default loggerSingleton;
示例5: Copyright
*/
/* TypeScript headers */
/// <reference path="../typings/node/node.d.ts" />
var GPLv3Message =
"TPC.js Copyright (C) 2014 Gurjeet Singh, http://gurjeet.singh.im"
+ "\n" + "This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you"
+ "\n" + "are welcome to redistribute it under terms of GNU General Public License version 3.";
var blessed = require('blessed');
var winston = require('winston');
var g_logger = new (winston.Logger)({ exitOnError: false })
g_logger.handleExceptions(new winston.transports.File({ filename: '/tmp/tpcc_exceptions.log' })) /* XXX This doesn't seem to do anything when an exception occurs! */
g_logger.add(winston.transports.File, { filename: uvp_log_file });
g_logger.log('info', 'Beginning TPC-C run.');
/* Create a screen */
/*
* XXX: For some inexplicable reason, if this variable is named 'screen', it
* causes `tsc` to emit an error, and no amount of diagnosis resolved the error.
*
* TODO: Create a definition file for blessed and contribute it to
* DefinitelyTyped repo.
*/
var mainScreen: any = blessed.screen();
/*
* Create a box in top-left corner of the screen, sized just enough to hold a
示例6: function
import * as winston from 'winston';
import * as config from 'config';
export const logger = new winston.Logger();
const env = config.util.getEnv('NODE_ENV');
// Development Logger
if(env === 'development') {
logger.add(winston.transports.Console, {
type: 'verbose',
colorize: true,
prettyPrint: true,
handleExceptions: true,
humanReadableUnhandledException: true
});
}
process.on('unhandledRejection', function (reason, p) {
logger.warn('Possibly Unhandled Rejection at: Promise ', p, ' reason: ', reason);
});
示例7: void
import * as winston from 'winston';
import 'winston-fast-rabbitmq';
const logger = new winston.Logger();
const options: winston.WinstonFastRabbitMqTransportOptions = {
appId: '',
durable: false,
exceptionsLevel: 'error',
exchangeName: 'winston-log',
exchangeType: 'topic',
handleError: (err: any) => void(0),
handleExceptions: true,
host: 'localhost',
humanReadableUnhandledException: true,
level: 'debug',
password: 'guest',
port: 5672,
protocol: 'amqp',
raw: false,
routingKey: 'log.*',
silent: true,
username: 'guest',
virtualHost: '%2f',
};
logger.add(winston.transports.WinstonFastRabbitMq, options);