2018-03-31 03:30:30 +08:00
|
|
|
import * as winston from 'winston';
|
2019-02-07 23:44:51 +08:00
|
|
|
import {Config} from '../common/config/private/Config';
|
|
|
|
import {LogLevel} from '../common/config/private/IPrivateConfig';
|
2017-06-04 04:35:47 +08:00
|
|
|
|
2017-06-04 21:25:08 +08:00
|
|
|
export const winstonSettings = {
|
2017-06-11 04:32:56 +08:00
|
|
|
transports: [
|
2018-11-30 22:36:42 +08:00
|
|
|
new winston.transports.Console(<any>{
|
2019-02-07 23:44:51 +08:00
|
|
|
level: LogLevel[Config.Server.log.level],
|
2017-06-11 04:32:56 +08:00
|
|
|
handleExceptions: true,
|
|
|
|
json: false,
|
|
|
|
colorize: true,
|
|
|
|
timestamp: function () {
|
|
|
|
return (new Date()).toLocaleString();
|
|
|
|
},
|
2018-03-31 03:30:30 +08:00
|
|
|
label: 'innerLabel',
|
2018-11-30 22:36:42 +08:00
|
|
|
formatter: (options: any) => {
|
2017-06-11 04:32:56 +08:00
|
|
|
// Return string will be passed to logger.
|
2018-11-30 22:36:42 +08:00
|
|
|
return options.timestamp() + '[' + (<any>winston)['config']['colorize'](options.level, options.level.toUpperCase()) + '] ' +
|
2017-06-11 04:32:56 +08:00
|
|
|
(undefined !== options.message ? options.message : '') +
|
2018-03-31 03:30:30 +08:00
|
|
|
(options.meta && Object.keys(options.meta).length ? '\n\t' + JSON.stringify(options.meta) : '');
|
2017-06-11 04:32:56 +08:00
|
|
|
},
|
|
|
|
debugStdout: true
|
|
|
|
})
|
|
|
|
],
|
|
|
|
exitOnError: false
|
2017-06-04 21:25:08 +08:00
|
|
|
};
|
|
|
|
|
2018-11-30 22:36:42 +08:00
|
|
|
export const Logger = new (<any>winston).Logger(winstonSettings);
|