automatically create necessary folders as required by configured log paths

Massimo Melina committed May 15, 2022 at 01:01 UTC 5d1e57f97ec8810bbc07256fe506d6132ba4b0c1
1 file changed +5 -2
server/src/log.ts
+5 -2
@@ -5,10 +5,11 @@ import { Writable } from 'stream'
5 import { defineConfig } from './config'
6 import { createWriteStream, existsSync, renameSync, WriteStream } from 'fs'
7 import * as util from 'util'
8 -import { stat } from 'fs/promises'
8 +import { mkdir, stat } from 'fs/promises'
9 import { DAY } from './const'
10 import events from './events'
11 import _ from 'lodash'
12 +import { dirname } from 'path'
13
14 class Logger {
15 stream?: Writable
@@ -28,7 +29,9 @@ class Logger {
29 const stats = await stat(path)
30 this.last = stats.mtime || stats.ctime
31 }
31 - catch {}
32 + catch {
33 + await mkdir(dirname(path), { recursive: true })
34 + }
35 this.reopen()
36 }
37