1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-27 02:09:16 +02:00
pigallery2/src/backend/Logger.ts

43 lines
1.4 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';
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 = {
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],
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
};
export 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);