本文整理汇总了TypeScript中winston.Logger类的典型用法代码示例。如果您正苦于以下问题:TypeScript Logger类的具体用法?TypeScript Logger怎么用?TypeScript Logger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Logger类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: log
export function log(msg: any) {
const infoLog = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
colorize: true,
level: 'info'
})
]
});
infoLog.info(msg);
};
示例2: errorLog
export function errorLog(msg: any) {
const errorLog = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
colorize: true,
level: 'error'
})
]
});
errorLog.error(msg);
}
示例3: new
const init = () => {
let quipLevels = {
levels: {
error: 0,
warn: 1,
info: 2,
verbose: 3,
debug: 4,
silly: 5
},
colors: {
error: 'red',
warn: 'yellow',
info: 'green',
verbose: 'blue',
debug: 'purple',
silly: 'pink'
}
};
let quipTransports = [
new (winston.transports.Console) ({
colorize: true,
level: (process.env.NODE_ENV == 'development') ? 'debug' : 'info',
handleExceptions: true,
json: false
}),
new (winston.transports.File) ({
colorize: false,
filename: 'log/quip.log',
handleExceptions: true,
json: true,
level: 'warn',
maxsize: 5242880,
maxFiles: 5
})
];
logger = new (winston.Logger) ({
levels: quipLevels.levels,
transports: quipTransports
});
logger.debug("Initiated logging.");
};
示例4: setVerbosity
setVerbosity (v: LoggerOptions["level"]) {
this.logger.configure({
level: v,
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format.colorize({ all: true }),
logFmt
)
})
}
示例5: stopped
server.close((e: any) => {
if (e) {
logger.error(e);
process.exit(1);
}
logger.warn(`Server stopped (${signal}).`);
process.exit();
});
示例6: getAllOfRunNumber
/**
* Functions for retrieving data from DB
*/
// get all items in the run number given a hash
// if following is true, get only future predictions from the timestamp
async function getAllOfRunNumber(hash, following) {
// calculate a range of values. run numbers are per day,
// so this gets us a list of all other predictions given the run number and a timestamp
let unixTime = Number(hash.prdt) * 1000
let min = new Date(unixTime)
min.setHours(0, 0, 0)
let max = new Date(unixTime) // have to set this again here to get us another object to operate on
max.setHours(0, 0, 0)
max.setDate(max.getDate() + 1)
// only get the following predictions
if (following) {
min = new Date(unixTime)
}
var params = {
TableName : 'cta-trains',
KeyConditionExpression: 'rn = :rn and prdt BETWEEN :min AND :max',
ExpressionAttributeValues: {
':min': min.getTime() / 1000,
':max': max.getTime() / 1000,
':rn': Number(hash.rn)
}
};
try {
let query = await dynamo.queryAsync(params)
return query.Items
} catch (error) {
logger.warning(error)
}
};
示例7:
process.on('exit', () => {
logger.info('Hello stopping');
if(server !== undefined) {
server.close();
}
});
示例8: saveErrorLogFile
export function saveErrorLogFile(err, req, res, next) {
if(!fs.existsSync('logs')){
fs.mkdirSync('logs');
}
if(!fs.existsSync('logs/error')){
fs.mkdirSync('logs/error');
}
if(err.status >= 400) {
let meta: any = {
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress,
req: {},
res: {}
};
meta.req.url = req.originalUrl ||Â req.url;
meta.req.method = req.method;
meta.req.httpVersion = req.httpVersion;
meta.req.query = req.query || '';
meta.req.params = req.params || '';
meta.req.body = req.body || '';
meta.req['accept-language'] = req.headers['accept-language'];
meta.req['accept-language'] = req.headers['user-agent'];
meta.responseTime = res.responseTime;
meta.res.statusCode = res.statusCode;
meta.error = err;
errorFileLog.log('error', '', meta);
}
next(err);
}
示例9: info
export function info(args:Array) {
var text = '';
for (var i = 0; i < args.length; i++) {
var obj = args[i];
text += colors.magenta(obj);
}
logger2.info(text);
}