Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
Bot crashes on start
Browse files Browse the repository at this point in the history
Fixes #130
  • Loading branch information
sebasptsch committed Nov 7, 2022
1 parent e3caad1 commit 7f7ed54
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/services/Logger.ts
Original file line number Diff line number Diff line change
@@ -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>('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
Expand All @@ -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 })
Expand Down

0 comments on commit 7f7ed54

Please sign in to comment.