From 7ded2598b570ba90999aa49ccdcf43a74a21b0b6 Mon Sep 17 00:00:00 2001 From: Dennis Heinrich Date: Tue, 26 Nov 2024 10:35:56 +0100 Subject: [PATCH] Logging with timestamp, obtaining more details for #6 --- source/Main.ts | 6 ++++++ source/Services/DiscordEmbed.ts | 2 ++ source/Services/Logging.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/source/Main.ts b/source/Main.ts index 2d86736..fb91b94 100644 --- a/source/Main.ts +++ b/source/Main.ts @@ -3,9 +3,15 @@ import Configuration from "./Services/Configuration"; import Logging from "./Services/Logging"; import DiscordService from "./Services/DiscordEmbed"; +// Create a new logger instance and configuration instance const appLogger = Logging.getLogger(); const appConfig: Configuration = new Configuration(); +// Log the application start and version +const packageJson = require('../package.json'); +appLogger.info(`Starting | App: ${packageJson.name} | Version: ${packageJson.version}`); +appLogger.info(`----------------------------------------------------`); + /** * Check if the configuration is valid and exit the application if it is not */ diff --git a/source/Services/DiscordEmbed.ts b/source/Services/DiscordEmbed.ts index 593ed50..7309715 100644 --- a/source/Services/DiscordEmbed.ts +++ b/source/Services/DiscordEmbed.ts @@ -56,12 +56,14 @@ export default class DiscordEmbed { this.generateEmbedFromStatusFeed(this.serverStatsFeed).then(embedMessage => { if (this.firstMessageId !== null) { (channel as TextChannel).messages.fetch(this.firstMessageId).then(message => { + this.appLogger.info(`Message found, editing message with new embed`); message.edit({embeds: [embedMessage]}); }).catch(() => { this.appLogger.warn('Message not found, sending new message'); sendInitialMessage(embedMessage); }); } else { + this.appLogger.info(`No message found, sending new message`); sendInitialMessage(embedMessage); } }); diff --git a/source/Services/Logging.ts b/source/Services/Logging.ts index 4263dd6..30596fd 100644 --- a/source/Services/Logging.ts +++ b/source/Services/Logging.ts @@ -5,8 +5,12 @@ export default class Logging { return winston.createLogger({ level: 'info', format: winston.format.combine( + winston.format.timestamp({ + format: 'YYYY-MM-DD HH:mm:ss' + }), winston.format.colorize(), winston.format.simple(), + winston.format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`) ), transports: [ new winston.transports.Console(),