1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-01-14 04:35:56 +02:00
pigallery2/src/backend/Logger.ts

38 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-03-30 21:30:30 +02:00
import * as winston from 'winston';
import {Config} from '../common/config/private/Config';
2020-01-28 19:36:52 +02:00
import {ServerConfig} from '../common/config/private/PrivateConfig';
2017-06-04 15:25:08 +02:00
export const winstonSettings = {
transports: [
2018-11-30 16:36:42 +02:00
new winston.transports.Console(<any>{
level: ServerConfig.LogLevel[Config.Server.Log.level],
handleExceptions: true,
json: false,
colorize: true,
timestamp: function () {
return (new Date()).toLocaleString();
},
2018-03-30 21:30:30 +02:00
label: 'innerLabel',
2018-11-30 16:36:42 +02:00
formatter: (options: any) => {
// Return string will be passed to logger.
2018-11-30 16:36:42 +02:00
return options.timestamp() + '[' + (<any>winston)['config']['colorize'](options.level, options.level.toUpperCase()) + '] ' +
(undefined !== options.message ? options.message : '') +
2018-03-30 21:30:30 +02:00
(options.meta && Object.keys(options.meta).length ? '\n\t' + JSON.stringify(options.meta) : '');
},
debugStdout: true
})
],
exitOnError: false
2017-06-04 15:25:08 +02:00
};
type logFN = (...args: (string | number)[]) => {};
export const Logger: {
error: logFN,
warn: logFN,
info: logFN,
verbose: logFN,
debug: logFN,
silly: logFN
} = new (<any>winston).Logger(winstonSettings);