Skip to content

Commit

Permalink
improved logformat
Browse files Browse the repository at this point in the history
  • Loading branch information
ijonas committed Oct 25, 2022
1 parent be683c6 commit ee2bb2d
Show file tree
Hide file tree
Showing 3 changed files with 459 additions and 5 deletions.
26 changes: 21 additions & 5 deletions lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
class Logger {
info(message: string | Object) {
console.log(message);
}
import winston from 'winston';

const logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'txnhooks' },
});

const logformat = winston.format.printf(({ level, message, label, timestamp }) => {
return `${timestamp} [${label}] ${level}: ${message}`;
});

if (process.env.NODE_ENV !== 'production') {
logger.add(new winston.transports.Console({
format: winston.format.combine(
winston.format.label({label: "txnhooks"}),
winston.format.timestamp(),
logformat
),
}));
}
export default new Logger();
export default logger;
Loading

0 comments on commit ee2bb2d

Please sign in to comment.