fix: log must report timestamp of request not of response
Massimo Melina committed
Mar 10, 2023 at 12:00 UTC
1d370cbaaf776d6be1422d4dc964833ec0d05606
1 file changed
+2
-2
src/log.ts
+2
-2
@@ -1,7 +1,7 @@
1
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
2
3
import Koa from 'koa'
4
-import { Writable } from 'stream'
4
+import { once, Writable } from 'stream'
5
import { defineConfig } from './config'
6
import { createWriteStream, renameSync } from 'fs'
7
import * as util from 'util'
@@ -64,13 +64,13 @@ const logRotation = defineConfig('log_rotation', 'weekly')
64
export function log(): Koa.Middleware {
65
const debounce = _.debounce(cb => cb(), 1000)
66
return async (ctx, next) => { // wrapping in a function will make it use current 'mw' value
67
+ const now = new Date()
68
await next()
69
const isError = ctx.status >= 400
70
const logger = isError && accessErrorLog || accessLogger
71
const rotate = logRotation.get()?.[0]
72
let { stream, last, path } = logger
73
if (!stream) return
73
- const now = new Date()
74
const a = now.toString().split(' ')
75
logger.last = now
76
if (rotate && last) { // rotation enabled and a file exists?