mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-20 03:11:41 +00:00
26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
TypeScript
// Env log level helpers normalize log level values from environment variables.
|
|
import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce";
|
|
import { ALLOWED_LOG_LEVELS, type LogLevel, tryParseLogLevel } from "./levels.js";
|
|
import { loggingState } from "./state.js";
|
|
|
|
/** Resolves OPENCLAW_LOG_LEVEL once per value, warning only when the invalid value changes. */
|
|
export function resolveEnvLogLevelOverride(): LogLevel | undefined {
|
|
const trimmed = normalizeOptionalString(process.env.OPENCLAW_LOG_LEVEL) ?? "";
|
|
if (!trimmed) {
|
|
loggingState.invalidEnvLogLevelValue = null;
|
|
return undefined;
|
|
}
|
|
const parsed = tryParseLogLevel(trimmed);
|
|
if (parsed) {
|
|
loggingState.invalidEnvLogLevelValue = null;
|
|
return parsed;
|
|
}
|
|
if (loggingState.invalidEnvLogLevelValue !== trimmed) {
|
|
loggingState.invalidEnvLogLevelValue = trimmed;
|
|
process.stderr.write(
|
|
`[openclaw] Ignoring invalid OPENCLAW_LOG_LEVEL="${trimmed}" (allowed: ${ALLOWED_LOG_LEVELS.join("|")}).\n`,
|
|
);
|
|
}
|
|
return undefined;
|
|
}
|