Logging with timestamp, obtaining more details for #6

This commit is contained in:
Dennis Heinrich 2024-11-26 10:35:56 +01:00
parent 50d463ac3b
commit 7ded2598b5
3 changed files with 12 additions and 0 deletions

View file

@ -3,9 +3,15 @@ import Configuration from "./Services/Configuration";
import Logging from "./Services/Logging"; import Logging from "./Services/Logging";
import DiscordService from "./Services/DiscordEmbed"; import DiscordService from "./Services/DiscordEmbed";
// Create a new logger instance and configuration instance
const appLogger = Logging.getLogger(); const appLogger = Logging.getLogger();
const appConfig: Configuration = new Configuration(); 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 * Check if the configuration is valid and exit the application if it is not
*/ */

View file

@ -56,12 +56,14 @@ export default class DiscordEmbed {
this.generateEmbedFromStatusFeed(this.serverStatsFeed).then(embedMessage => { this.generateEmbedFromStatusFeed(this.serverStatsFeed).then(embedMessage => {
if (this.firstMessageId !== null) { if (this.firstMessageId !== null) {
(channel as TextChannel).messages.fetch(this.firstMessageId).then(message => { (channel as TextChannel).messages.fetch(this.firstMessageId).then(message => {
this.appLogger.info(`Message found, editing message with new embed`);
message.edit({embeds: [embedMessage]}); message.edit({embeds: [embedMessage]});
}).catch(() => { }).catch(() => {
this.appLogger.warn('Message not found, sending new message'); this.appLogger.warn('Message not found, sending new message');
sendInitialMessage(embedMessage); sendInitialMessage(embedMessage);
}); });
} else { } else {
this.appLogger.info(`No message found, sending new message`);
sendInitialMessage(embedMessage); sendInitialMessage(embedMessage);
} }
}); });

View file

@ -5,8 +5,12 @@ export default class Logging {
return winston.createLogger({ return winston.createLogger({
level: 'info', level: 'info',
format: winston.format.combine( format: winston.format.combine(
winston.format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
winston.format.colorize(), winston.format.colorize(),
winston.format.simple(), winston.format.simple(),
winston.format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`)
), ),
transports: [ transports: [
new winston.transports.Console(), new winston.transports.Console(),