mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 07:29:08 +00:00
refactor: add severe log level
This commit is contained in:
committed by
Carlos Valente
parent
715600a514
commit
d41cd78f2e
@@ -270,13 +270,13 @@ process.on('exit', (code) => console.log(`Ontime shutdown with code: ${code}`));
|
|||||||
|
|
||||||
process.on('unhandledRejection', async (error) => {
|
process.on('unhandledRejection', async (error) => {
|
||||||
generateCrashReport(error);
|
generateCrashReport(error);
|
||||||
logger.error(LogOrigin.Server, `Uncaught exception | ${error}`);
|
logger.crash(LogOrigin.Server, `Uncaught exception | ${error}`);
|
||||||
await shutdown(1);
|
await shutdown(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('uncaughtException', async (error) => {
|
process.on('uncaughtException', async (error) => {
|
||||||
generateCrashReport(error);
|
generateCrashReport(error);
|
||||||
logger.error(LogOrigin.Server, `Uncaught exception | ${error}`);
|
logger.crash(LogOrigin.Server, `Uncaught exception | ${error}`);
|
||||||
await shutdown(1);
|
await shutdown(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ class Logger {
|
|||||||
* @param log
|
* @param log
|
||||||
*/
|
*/
|
||||||
private _push(log: Log) {
|
private _push(log: Log) {
|
||||||
if (!isProduction || log.level === LogLevel.Error) {
|
if (!isProduction || log.level === LogLevel.Severe) {
|
||||||
if (log.level === LogLevel.Error) {
|
if (log.level === LogLevel.Severe) {
|
||||||
consoleRed(`[${log.level}] \t ${log.origin} \t ${log.text}`);
|
consoleRed(`[${log.level}] \t ${log.origin} \t ${log.text}`);
|
||||||
} else {
|
} else {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
@@ -98,6 +98,15 @@ class Logger {
|
|||||||
this.emit(LogLevel.Error, origin, text);
|
this.emit(LogLevel.Error, origin, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility to emit logging message of type SEVERE
|
||||||
|
* @param origin
|
||||||
|
* @param text
|
||||||
|
*/
|
||||||
|
crash(origin: string, text: string) {
|
||||||
|
this.emit(LogLevel.Severe, origin, text);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shutdown logger
|
* Shutdown logger
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export enum LogLevel {
|
|||||||
Info = 'INFO',
|
Info = 'INFO',
|
||||||
Warn = 'WARN',
|
Warn = 'WARN',
|
||||||
Error = 'ERROR',
|
Error = 'ERROR',
|
||||||
|
Severe = 'SEVERE',
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Log = {
|
export type Log = {
|
||||||
|
|||||||
Reference in New Issue
Block a user