2018-03-30 21:30:30 +02:00
|
|
|
import * as winston from 'winston';
|
2019-02-07 17:44:51 +02:00
|
|
|
import {Config} from '../common/config/private/Config';
|
2020-01-28 19:36:52 +02:00
|
|
|
import {ServerConfig} from '../common/config/private/PrivateConfig';
|
2017-06-03 22:35:47 +02:00
|
|
|
|
2020-09-06 12:17:05 +02:00
|
|
|
const forcedDebug = process.env.NODE_ENV === 'debug';
|
|
|
|
|
2020-09-06 13:14:28 +02:00
|
|
|
if (forcedDebug === true) {
|
|
|
|
console.log('NODE_ENV environmental variable is set to debug, forcing all logs to print');
|
|
|
|
}
|
2017-06-04 15:25:08 +02:00
|
|
|
export const winstonSettings = {
|
2017-06-10 22:32:56 +02:00
|
|
|
transports: [
|
2018-11-30 16:36:42 +02:00
|
|
|
new winston.transports.Console(<any>{
|
2020-09-06 12:22:54 +02:00
|
|
|
level: forcedDebug === true ? ServerConfig.LogLevel[ServerConfig.LogLevel.silly] : ServerConfig.LogLevel[Config.Server.Log.level],
|
2017-06-10 22:32:56 +02:00
|
|
|
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) => {
|
2017-06-10 22:32:56 +02:00
|
|
|
// 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()) + '] ' +
|
2017-06-10 22:32:56 +02:00
|
|
|
(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) : '');
|
2017-06-10 22:32:56 +02:00
|
|
|
},
|
|
|
|
debugStdout: true
|
|
|
|
})
|
|
|
|
],
|
|
|
|
exitOnError: false
|
2017-06-04 15:25:08 +02:00
|
|
|
};
|
|
|
|
|
2020-12-25 11:36:49 +02:00
|
|
|
export type logFN = (...args: (string | number)[]) => {};
|
2019-12-06 16:53:34 +02:00
|
|
|
|
|
|
|
export const Logger: {
|
|
|
|
error: logFN,
|
|
|
|
warn: logFN,
|
|
|
|
info: logFN,
|
|
|
|
verbose: logFN,
|
|
|
|
debug: logFN,
|
|
|
|
silly: logFN
|
|
|
|
} = new (<any>winston).Logger(winstonSettings);
|