mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 13:21:55 +00:00
refactor(logger): console level matches file level, remove getConsoleLogLevel
Simplify logger by removing getConsoleLogLevel() and LOG_LEVEL_VALUES. When ASK262_LOG_CONSOLE=true, console output uses the same level as file logging (ASK262_LOG_LEVEL).
This commit is contained in:
+1
-28
@@ -77,17 +77,6 @@ export enum LogOperation {
|
|||||||
RETRYING_RATE_LIMIT = "retrying_rate_limit",
|
RETRYING_RATE_LIMIT = "retrying_rate_limit",
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Numeric log level values (Pino convention).
|
|
||||||
*/
|
|
||||||
const LOG_LEVEL_VALUES: Record<LogLevel, number> = {
|
|
||||||
trace: 10,
|
|
||||||
debug: 20,
|
|
||||||
info: 30,
|
|
||||||
warn: 40,
|
|
||||||
error: 50,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Valid log level strings.
|
* Valid log level strings.
|
||||||
*/
|
*/
|
||||||
@@ -128,21 +117,6 @@ function getFileLogLevel(): LogLevel {
|
|||||||
return "debug";
|
return "debug";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the console log level.
|
|
||||||
* Console shows max('info', file level) - never shows debug.
|
|
||||||
*
|
|
||||||
* @returns The calculated console log level
|
|
||||||
*/
|
|
||||||
function getConsoleLogLevel(): LogLevel {
|
|
||||||
const fileLevel = getFileLogLevel();
|
|
||||||
const fileLevelValue = LOG_LEVEL_VALUES[fileLevel];
|
|
||||||
const infoLevelValue = LOG_LEVEL_VALUES.info;
|
|
||||||
|
|
||||||
// Console level is max of (info, file level)
|
|
||||||
return fileLevelValue > infoLevelValue ? fileLevel : "info";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the log directory from environment.
|
* Get the log directory from environment.
|
||||||
*
|
*
|
||||||
@@ -209,14 +183,13 @@ async function createRootLogger(): Promise<pino.Logger> {
|
|||||||
|
|
||||||
// Console transport: opt-in only (ASK262_LOG_CONSOLE=true)
|
// Console transport: opt-in only (ASK262_LOG_CONSOLE=true)
|
||||||
if (process.env.ASK262_LOG_CONSOLE === "true") {
|
if (process.env.ASK262_LOG_CONSOLE === "true") {
|
||||||
const consoleLevel = getConsoleLogLevel();
|
|
||||||
const consoleStream = pretty({
|
const consoleStream = pretty({
|
||||||
colorize: true,
|
colorize: true,
|
||||||
translateTime: "SYS:standard",
|
translateTime: "SYS:standard",
|
||||||
ignore: "pid,hostname",
|
ignore: "pid,hostname",
|
||||||
destination: process.stderr,
|
destination: process.stderr,
|
||||||
});
|
});
|
||||||
streams.push({ stream: consoleStream, level: consoleLevel });
|
streams.push({ stream: consoleStream, level: fileLevel });
|
||||||
}
|
}
|
||||||
|
|
||||||
return pino(
|
return pino(
|
||||||
|
|||||||
Reference in New Issue
Block a user