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

Bot crashes on start #131

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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