fix: (regression 0.45.0) admin/logs is not updated in realtime
Massimo Melina committed
Jun 28, 2023 at 23:41 UTC
b7bb77a1c4ae79dc1040e315e3c307225f264333
1 file changed
+2
src/log.ts
+2
@@ -11,6 +11,7 @@ import _ from 'lodash'
11
import { createFileWithPath, prepareFolder } from './util-files'
12
import { getCurrentUsername } from './perm'
13
import { makeNetMatcher, tryJson } from './misc'
14
+import events from './events'
15
16
class Logger {
17
stream?: Writable
@@ -100,6 +101,7 @@ export const logMw: Koa.Middleware = async (ctx, next) => {
101
const date = a[2]+'/'+a[1]+'/'+a[3]+':'+a[4]+' '+a[5]?.slice(3)
102
const user = getCurrentUsername(ctx)
103
const length = ctx.state.length ?? ctx.length
104
+ events.emit(logger.name, Object.assign(_.pick(ctx, ['ip', 'method','status']), { length, user, ts: now, uri: ctx.originalUrl }))
105
debounce(() => // once in a while we check if the file is still good (not deleted, etc), or we'll reopen it
106
stat(logger.path).catch(() => logger.reopen())) // async = smoother but we may lose some entries
107
stream!.write(util.format( format,