Skip to content

Commit

Permalink
Add trace log level (#4539)
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion authored Sep 13, 2022
1 parent da54be8 commit 2dd1323
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
14 changes: 3 additions & 11 deletions packages/utils/src/logger/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export enum LogLevel {
info = "info",
verbose = "verbose",
debug = "debug",
silly = "silly",
trace = "trace",
}

export const logLevelNum: {[K in LogLevel]: number} = {
Expand All @@ -15,21 +15,13 @@ export const logLevelNum: {[K in LogLevel]: number} = {
[LogLevel.info]: 2,
[LogLevel.verbose]: 3,
[LogLevel.debug]: 4,
[LogLevel.silly]: 5,
/** Request in https://github.com/ChainSafe/lodestar/issues/4536 by eth-docker */
[LogLevel.trace]: 5,
};

// eslint-disable-next-line @typescript-eslint/naming-convention
export const LogLevels = Object.values(LogLevel);

export const customColors = {
error: "red",
warn: "yellow",
info: "white",
verbose: "green",
debug: "pink",
silly: "purple",
};

export const defaultLogLevel = LogLevel.info;

export type LogFormat = "human" | "json";
Expand Down
7 changes: 4 additions & 3 deletions packages/utils/src/logger/winston.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import winston from "winston";
import type {Logger} from "winston";
import {ILogger, ILoggerOptions, LoggerChildOpts, LogLevel} from "./interface.js";
import {ILogger, ILoggerOptions, LoggerChildOpts, LogLevel, logLevelNum} from "./interface.js";
import {getFormat} from "./format.js";
import {LogData} from "./json.js";

Expand Down Expand Up @@ -50,6 +50,7 @@ export class WinstonLogger implements ILogger {
format: getFormat(options),
transports,
exitOnError: false,
levels: logLevelNum,
})
);
}
Expand All @@ -74,8 +75,8 @@ export class WinstonLogger implements ILogger {
this.createLogEntry(LogLevel.debug, message, context, error);
}

silly(message: string, context?: LogData, error?: Error): void {
this.createLogEntry(LogLevel.silly, message, context, error);
trace(message: string, context?: LogData, error?: Error): void {
this.createLogEntry(LogLevel.trace, message, context, error);
}

child(options: LoggerChildOpts): WinstonLogger {
Expand Down

0 comments on commit 2dd1323

Please sign in to comment.