mirror of
https://github.com/filiprojek/nork.git
synced 2024-11-02 18:12:28 +01:00
Added: error log in Log module
This commit is contained in:
parent
ae5ceb643f
commit
1f121a8565
@ -3,33 +3,36 @@ import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
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 {
|
||||
if(!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 = ""
|
||||
}
|
||||
public static error(code: number, message: string, data?: any): object {
|
||||
if (!data) {
|
||||
data = ''
|
||||
}
|
||||
|
||||
console.log(colors.bgRed.black(` ${code} `) + colors.red.bgBlack(` ${message} `) + data)
|
||||
//this.writeLog('error', code, message, data)
|
||||
}
|
||||
private static writeLog(level: string, code: number, message: string, data?:any): void {
|
||||
if(data) {
|
||||
data = JSON.stringify(data)
|
||||
}
|
||||
//this.writeLog('error', code, message, data)
|
||||
return {
|
||||
code: code,
|
||||
message: message,
|
||||
data: data
|
||||
}
|
||||
}
|
||||
private static writeLog(level: string, code: number, message: string, data?: any): void {
|
||||
if (data) {
|
||||
data = JSON.stringify(data)
|
||||
}
|
||||
|
||||
try {
|
||||
throw Error("nevim")
|
||||
} catch (error) {
|
||||
this.error(500, 'Error while writing to log file', error)
|
||||
return
|
||||
}
|
||||
}
|
||||
try {
|
||||
throw Error('nevim')
|
||||
} catch (error) {
|
||||
this.error(500, 'Error while writing to log file', error)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user