mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 05:01:23 +00:00
Feat/logger support log level validation0222 (#23436)
* 1、环境变量**:新增 `OPENCLAW_LOG_LEVEL`,可取值 `silent|fatal|error|warn|info|debug|trace`。设置后同时覆盖**文件日志**与**控制台**的级别,优先级高于配置文件。 2、启动参数**:在 `openclaw gateway run` 上新增 `--log-level <level>`,对该次进程同时生效于文件与控制台;未传时仍使用环境变量或配置文件。 * fix(logging): make log-level override global and precedence-safe --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -10,9 +10,16 @@ export const ALLOWED_LOG_LEVELS = [
|
||||
|
||||
export type LogLevel = (typeof ALLOWED_LOG_LEVELS)[number];
|
||||
|
||||
export function tryParseLogLevel(level?: string): LogLevel | undefined {
|
||||
if (typeof level !== "string") {
|
||||
return undefined;
|
||||
}
|
||||
const candidate = level.trim();
|
||||
return ALLOWED_LOG_LEVELS.includes(candidate as LogLevel) ? (candidate as LogLevel) : undefined;
|
||||
}
|
||||
|
||||
export function normalizeLogLevel(level?: string, fallback: LogLevel = "info") {
|
||||
const candidate = (level ?? fallback).trim();
|
||||
return ALLOWED_LOG_LEVELS.includes(candidate as LogLevel) ? (candidate as LogLevel) : fallback;
|
||||
return tryParseLogLevel(level) ?? fallback;
|
||||
}
|
||||
|
||||
export function levelToMinLevel(level: LogLevel): number {
|
||||
|
||||
Reference in New Issue
Block a user