feat: Add new logging utility class
The commit introduces a LogsUtils class under src/utils. This class includes various logging methods such as info, warn, error, softError, trace, fatal, and debug. Also, it uses conditional statements to handle different context and debug scenarios.
This commit is contained in:
39
src/utils/logs.util.ts
Normal file
39
src/utils/logs.util.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import * as process from "node:process";
|
||||
import {ILogObj, Logger} from "tslog";
|
||||
|
||||
export class LogsUtils {
|
||||
private Logger: Logger<ILogObj>;
|
||||
constructor(contextName: string) {
|
||||
this.Logger = new Logger({name: contextName})
|
||||
}
|
||||
|
||||
info(value: any, value2?: any) {
|
||||
this.Logger.info(`\n\n(i) |> ${value}\n${value2 ? '|> ' + value2 + '\n' : ''}`)
|
||||
}
|
||||
|
||||
warn(value: any, value2?: any) {
|
||||
this.Logger.warn(`\n\n(?) |> ${value}\n${value2 ? '|> ' + value2 + '\n' : ''}`)
|
||||
}
|
||||
|
||||
error(value: any, value2?: any) {
|
||||
this.Logger.error(`\n\n(!) |> ${value}\n${value2 ? '|> ' + value2 + '\n' : ''}`)
|
||||
if (process.env["CONTEXT"] === 'prod') process.exit(-1)
|
||||
}
|
||||
|
||||
softError(value: any, value2?: any) {
|
||||
this.Logger.error(`\n\n(!) |> ${value}\n${value2 ? '|> ' + value2 + '\n' : ''}`)
|
||||
}
|
||||
|
||||
trace(value: any, value2?: any) {
|
||||
if (process.env["DEBUG"] === 'true') this.Logger.trace(`\n\n(*) |> ${value}\n${value2 ? '|> ' + value2 + '\n' : ''}`)
|
||||
}
|
||||
|
||||
fatal(value: any, value2?: any) {
|
||||
this.Logger.fatal(`\n\n(X) |> ${value}\n${value2 ? '|> ' + value2 + '\n' : ''}`)
|
||||
if (process.env["CONTEXT"] === 'prod') process.exit(-1)
|
||||
}
|
||||
|
||||
debug(value: any, value2?: any) {
|
||||
if (process.env["DEBUG"] === 'true') this.Logger.debug(`\n\n(~) |> ${value}\n${value2 ? '|> ' + value2 + '\n' : ''}`)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user