log
This commit is contained in:
parent
4b34fc20b8
commit
1c9cb7ea78
11 changed files with 741 additions and 122 deletions
|
|
@ -39,7 +39,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
|||
res.on("finish", () => {
|
||||
if (!req.url.startsWith("/api/")) return;
|
||||
|
||||
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "info"] || 1;
|
||||
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;
|
||||
|
||||
if (level === 1 && res.statusCode < 500) return;
|
||||
if (level === 2 && res.statusCode < 400) return;
|
||||
|
|
@ -47,6 +47,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
|||
|
||||
const obj = {
|
||||
logType: res.statusCode >= 500 ? "error" : res.statusCode >= 400 ? "warning" : "info",
|
||||
ip: req.ip,
|
||||
systemName: "development",
|
||||
startTimeStamp: timestamp,
|
||||
endTimeStamp: new Date().toISOString(),
|
||||
|
|
@ -55,7 +56,7 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
|
|||
method: req.method,
|
||||
endpoint: req.url,
|
||||
responseCode: String(res.statusCode === 304 ? 200 : res.statusCode),
|
||||
responseDescription: data?.code,
|
||||
responseDescription: data?.message,
|
||||
input: (level === 4 && JSON.stringify(req.body, null, 2)) || undefined,
|
||||
output: (level === 4 && JSON.stringify(data, null, 2)) || undefined,
|
||||
...req.app.locals.logData,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue