Skip to content

Commit

Permalink
Add custom LogService with Winston for error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
YashGupt29 committed Nov 18, 2024
1 parent b6b0573 commit f3fa8e8
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 11 deletions.
38 changes: 38 additions & 0 deletions logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { createLogger, format, transports } = require('winston');
const winstonTimestampColorize = require('winston-timestamp-colorize');

const customFormat = format.combine(
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
winstonTimestampColorize(),
format.colorize({all:true}),
format.printf(({ level, timestamp, message, stack, tool_name, url }) => {

let logMessage = `${level} at ${timestamp}`;
logMessage += `\n${message}`;
if (tool_name) {
logMessage += `\n Tool: ${tool_name}`;
}
if (url) {
logMessage += `\n URL: ${url}`;
}
if (stack) {
logMessage += `\n Stack: ${stack}`;
}
return logMessage;
}),

);

const logger = createLogger({
level: 'info',
format: customFormat,
transports: [
new transports.Console({
format: format.combine(customFormat)
}),
new transports.File({ filename: 'logs/error.log', level: 'error' }),
new transports.File({ filename: 'logs/combined.log' }),
],
});

module.exports = logger;
Loading

0 comments on commit f3fa8e8

Please sign in to comment.