mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2024-12-22 13:22:58 -05:00
Optimise logger
This commit is contained in:
parent
500485c2e3
commit
f118de2038
1 changed files with 8 additions and 9 deletions
|
@ -12,14 +12,9 @@ const logLevels = {
|
|||
trace: 5,
|
||||
};
|
||||
|
||||
let currentUUID: string;
|
||||
const addReqId = format((info) => {
|
||||
info.reqId = currentUUID
|
||||
return info
|
||||
})
|
||||
|
||||
export const logger = createLogger({
|
||||
format: format.combine(addReqId(), format.timestamp(), format.json()),
|
||||
format: format.combine(format.timestamp(), format.json()),
|
||||
transports: [new transports.Console({}), new transports.File({ filename: './serverLog.log' })],
|
||||
levels: logLevels
|
||||
});
|
||||
|
@ -29,12 +24,16 @@ export const errorHandler = (err: Error, req: Request, res: Response, next: Next
|
|||
return next(err)
|
||||
}
|
||||
|
||||
currentUUID = res.locals.uuid
|
||||
res.status(500).send({ status: 'error', message: err.message, code: res.locals.uuid })
|
||||
logger.warn(err.message)
|
||||
logger.warn({
|
||||
message: err.message,
|
||||
endpoint: req.originalUrl,
|
||||
reqId: res.locals.uuid,
|
||||
origin: req.headers.origin,
|
||||
})
|
||||
}
|
||||
|
||||
export const uuid = (req: Request, res: Response, next: NextFunction) => {
|
||||
res.locals.uuid = randomUUID()
|
||||
next(res)
|
||||
next()
|
||||
}
|
Loading…
Reference in a new issue