Skip to content

Commit

Permalink
Export current log level value
Browse files Browse the repository at this point in the history
  • Loading branch information
nktpro committed Feb 16, 2024
1 parent a241462 commit 7cf4bfc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
32 changes: 16 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ export enum LogLevel {
Debug = 4,
}

const logLevelMap: Record<string, LogLevel> = {
export const logLevelMap: Record<string, LogLevel> = {
none: LogLevel.None,
error: LogLevel.Error,
warn: LogLevel.Warn,
info: LogLevel.Info,
debug: LogLevel.Debug,
};

const levelName = (Deno.env.get("LOG_LEVEL") ?? "info").toLowerCase();
const levelValue = logLevelMap[levelName];
export const logLevelName = (Deno.env.get("LOG_LEVEL") ?? "info").toLowerCase();
export const logLevelValue = logLevelMap[logLevelName];

if (levelValue === undefined) {
throw new Error(`Invalid LOG_LEVEL value: ${levelName}. Valid values are: ${Object.keys(logLevelMap).join(", ")}`);
if (logLevelValue === undefined) {
throw new Error(`Invalid LOG_LEVEL value: ${logLevelName}. Valid values are: ${Object.keys(logLevelMap).join(", ")}`);
}

export class Logger {
Expand All @@ -43,7 +43,7 @@ export class Logger {
}
}

export const DefaultLogger = new Logger(console.error.bind(console), levelValue);
export const DefaultLogger = new Logger(console.error.bind(console), logLevelValue);
export const DefaultLoggerWithTimestamp = DefaultLogger.transform((log) => (...args: unknown[]) => {
return log(new Date().toISOString(), ...args);
});

0 comments on commit 7cf4bfc

Please sign in to comment.