From 7f7ed545495d5beb71c29ab54d6003f1a752a914 Mon Sep 17 00:00:00 2001 From: Sebastian Pietschner Date: Mon, 7 Nov 2022 18:51:47 +0000 Subject: [PATCH] Bot crashes on start Fixes #130 --- src/services/Logger.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/services/Logger.ts b/src/services/Logger.ts index ade66a3..a9e169c 100644 --- a/src/services/Logger.ts +++ b/src/services/Logger.ts @@ -1,11 +1,13 @@ import { Signales } from '@dynamicabot/signales'; import { Service, Token } from 'typedi'; import fs from 'node:fs'; +import fsP from 'node:fs/promises'; export const LoggerToken = new Token('Logger'); // generate file name depending on the date (e.g. 2021-09-01-1.log, 2021-09-01-2.log, etc.) with a suffix parameter -const createLogfileWriter = (suffix: string = 'log') => { +const createLogfileWriter = async (suffix: string = 'log') => { + await fsP.mkdir('logs', { recursive: true }); const date = new Date(); const filename = `logs/${date.getFullYear()}-${ date.getMonth() + 1 @@ -15,9 +17,9 @@ const createLogfileWriter = (suffix: string = 'log') => { return writer; }; -const logFile = createLogfileWriter(); +const logFile = await createLogfileWriter(); -const errorFile = createLogfileWriter('error'); +const errorFile = await createLogfileWriter('error'); /** Signale Logger instance */ @Service({ id: Logger })