2019-02-07 17:44:51 +02:00
|
|
|
import {Config} from '../common/config/private/Config';
|
2021-04-18 15:48:35 +02:00
|
|
|
import {LogLevel} from '../common/config/private/PrivateConfig';
|
2017-06-03 22:35:47 +02:00
|
|
|
|
2021-05-16 11:11:53 +02:00
|
|
|
export type logFN = (...args: (string | number)[]) => void;
|
|
|
|
|
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');
|
|
|
|
}
|
2021-05-16 11:11:53 +02:00
|
|
|
|
|
|
|
export class Logger {
|
|
|
|
public static silly(...args: (string | number)[]): void {
|
|
|
|
if (!forcedDebug && Config.Server.Log.level < LogLevel.silly) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Logger.log(`[\x1b[35mSILLY\x1b[0m]`, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static debug(...args: (string | number)[]): void {
|
|
|
|
if (!forcedDebug && Config.Server.Log.level < LogLevel.debug) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Logger.log(`[\x1b[34mDEBUG\x1b[0m]`, ...args);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static verbose(...args: (string | number)[]): void {
|
|
|
|
if (!forcedDebug && Config.Server.Log.level < LogLevel.verbose) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Logger.log(`[\x1b[36mVERBS\x1b[0m]`, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static info(...args: (string | number)[]): void {
|
|
|
|
if (!forcedDebug && Config.Server.Log.level < LogLevel.info) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Logger.log(`[\x1b[32mINFO_\x1b[0m]`, ...args);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static warn(...args: (string | number)[]): void {
|
|
|
|
if (!forcedDebug && Config.Server.Log.level < LogLevel.warn) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Logger.log(`[\x1b[33mWARN_\x1b[0m]`, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static error(...args: (string | number)[]): void {
|
|
|
|
|
|
|
|
Logger.log(`[\x1b[31mERROR\x1b[0m]`, ...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static log(tag: string, ...args: (string | number)[]): void {
|
|
|
|
const date = (new Date()).toLocaleString();
|
|
|
|
let LOG_TAG = '';
|
|
|
|
if (args.length > 0 && typeof args[0] === 'string' && args[0].startsWith('[') && args[0].endsWith(']')) {
|
|
|
|
LOG_TAG = args[0];
|
|
|
|
args.shift();
|
|
|
|
}
|
|
|
|
console.log(date + tag + LOG_TAG, ...args);
|
|
|
|
}
|
|
|
|
}
|