Added: error log in Log module

This commit is contained in:
Filip Rojek 2024-05-02 00:10:39 +02:00
parent ae5ceb643f
commit 1f121a8565

View File

@ -3,33 +3,36 @@ import fs from 'fs'
import path from 'path' import path from 'path'
export default class Log { export default class Log {
public static info(code: number, message: string, data?: any): void {
if (!data) {
data = ''
}
console.log(colors.bgGreen.black(` ${code} `) + colors.green.bgBlack(` ${message} `) + data)
}
public static info(code: number, message: string, data?:any): void { public static error(code: number, message: string, data?: any): object {
if(!data) { if (!data) {
data = "" data = ''
} }
console.log(colors.bgGreen.black(` ${code} `) + colors.green.bgBlack(` ${message} `) + data)
}
public static error(code: number, message: string, data?:any): void {
if(!data) {
data = ""
}
console.log(colors.bgRed.black(` ${code} `) + colors.red.bgBlack(` ${message} `) + data) console.log(colors.bgRed.black(` ${code} `) + colors.red.bgBlack(` ${message} `) + data)
//this.writeLog('error', code, message, data) //this.writeLog('error', code, message, data)
} return {
private static writeLog(level: string, code: number, message: string, data?:any): void { code: code,
if(data) { message: message,
data = JSON.stringify(data) data: data
} }
}
private static writeLog(level: string, code: number, message: string, data?: any): void {
if (data) {
data = JSON.stringify(data)
}
try { try {
throw Error("nevim") throw Error('nevim')
} catch (error) { } catch (error) {
this.error(500, 'Error while writing to log file', error) this.error(500, 'Error while writing to log file', error)
return return
} }
} }
} }