logger functionality
This commit is contained in:
parent
1b2f0d02ef
commit
0a81acf49e
@ -17,10 +17,8 @@
|
||||
"prettier": "^3.3.1",
|
||||
"rage-rpc": "^0.4.0",
|
||||
"tsup": "^8.1.0",
|
||||
"typescript": "^5.4.5"
|
||||
"typescript": "^5.4.5",
|
||||
"winston": "^3.13.0"
|
||||
},
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
|
||||
}
|
||||
"type": "module"
|
||||
}
|
||||
|
36
server/src/logger.ts
Normal file
36
server/src/logger.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import winston, { format } from 'winston'
|
||||
const { timestamp, printf, colorize } = format
|
||||
|
||||
export default class Logger {
|
||||
private format = printf(({ message, level, timestamp }) => {
|
||||
return `[${new Date(timestamp).toLocaleTimeString()}] [${level}]: ${message}`
|
||||
})
|
||||
|
||||
private systemLogger = winston.createLogger({
|
||||
transports: [new winston.transports.Console()],
|
||||
format: format.combine(
|
||||
colorize({
|
||||
level: true,
|
||||
colors: {
|
||||
error: 'red',
|
||||
warn: 'yellow',
|
||||
info: 'white',
|
||||
},
|
||||
}),
|
||||
timestamp(),
|
||||
this.format,
|
||||
),
|
||||
})
|
||||
|
||||
public info(message: unknown) {
|
||||
this.systemLogger.info(message)
|
||||
}
|
||||
|
||||
public warn(message: unknown) {
|
||||
this.systemLogger.warn(message)
|
||||
}
|
||||
|
||||
public error(message: unknown) {
|
||||
this.systemLogger.error(message)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user