Skip to content

Commit

Permalink
chore: reuse created loggers (#5077)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidzr authored Sep 26, 2022
1 parent 010382b commit de4b7bc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions webui/react/src/shared/utils/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ const generateNamespace = (parts: string[], separator = NAMEPACE_SEPARATOR) => {
return parts.join(separator);
};

const loggers: Record<string, debug.Debugger> = {};

/** returns the underlying Debug logger. */
export const getLogger = (namespace: string, level: Level): ((...msg: unknown[]) => void) => {
const logger = debug(`${namespace}:${level}`);
return logger;
const key = `${namespace}:${level}`;
if (!loggers[key]) {
loggers[key] = debug(key);
}
return loggers[key];
};

export interface LoggerInterface {
Expand Down

0 comments on commit de4b7bc

Please sign in to comment.