logger functionality

This commit is contained in:
Oleksandr Honcharov 2024-06-11 20:28:57 +03:00
parent 1b2f0d02ef
commit 0a81acf49e
2 changed files with 39 additions and 5 deletions

View File

@ -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
View 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)
}
}