{"record":{"id":"203468406b8d965a","repo":"coleam00/Archon","slug":"logger-invalid-log-level-process-env-log-leve","errorCode":null,"errorMessage":"[logger] Invalid LOG_LEVEL '${process.env.LOG_LEVEL}'. Valid levels: ${[...VALID_LEVELS].join(', ')}. Falling back to 'info'.","messagePattern":"\\[logger\\] Invalid LOG_LEVEL '(.+?)'\\. Valid levels: (.+?)\\. Falling back to 'info'\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/paths/src/logger.ts","lineNumber":43,"sourceCode":"\nimport pino from 'pino';\nimport type { Logger } from 'pino';\nimport pretty from 'pino-pretty';\n\nexport type { Logger } from 'pino';\n\n// 'silent' is Pino's built-in level that disables all output. The CLI uses it\n// in --json mode to keep stdout to exactly the JSON payload.\nconst VALID_LEVELS = new Set(['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent']);\n\nfunction getInitialLevel(): string {\n  const envLevel = process.env.LOG_LEVEL?.toLowerCase();\n  if (envLevel) {\n    if (VALID_LEVELS.has(envLevel)) {\n      return envLevel;\n    }\n    // Warn via console since the logger itself isn't configured yet\n    console.warn(\n      `[logger] Invalid LOG_LEVEL '${process.env.LOG_LEVEL}'. ` +\n        `Valid levels: ${[...VALID_LEVELS].join(', ')}. Falling back to 'info'.`\n    );\n  }\n  return 'info';\n}\n\n/**\n * Build the root Pino logger.\n *\n * Uses `pino-pretty` as a **destination stream** (not a worker-thread transport)\n * when stdout is a TTY and NODE_ENV !== 'production'. Running pino-pretty as a\n * destination stream keeps the formatter on the main thread, which avoids the\n * `require.resolve('pino-pretty')` lookup that crashes inside Bun's `/$bunfs/`\n * virtual filesystem in compiled binaries (see GitHub issue #960 / #979).\n *\n * The same code path runs in dev and compiled binaries — no environment\n * detection required.","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/paths/src/logger.ts#L25-L61","documentation":"The logger reads LOG_LEVEL at initialization (getInitialLevel). If the env var is set but not one of the valid level names, it warns via console (the logger isn't configured yet) and falls back to 'info' instead of crashing.","triggerScenarios":"Setting LOG_LEVEL to an unrecognized value such as 'verbose', 'warn ', 'DEBUG' typos like 'logg', or a numeric level ('3').","commonSituations":"Copying LOG_LEVEL from another library that accepts different names; typos or stray whitespace/case issues; CI env files exporting an invalid default.","solutions":["Set LOG_LEVEL to a valid level: debug, info, warn, error (check VALID_LEVELS in packages/paths/src/logger.ts).","Remove the LOG_LEVEL env var to use the 'info' default.","Fix casing/whitespace: the check lowercases the value, so 'DEBUG' works but 'debug ' (trailing space) does not."],"exampleFix":"// before\nLOG_LEVEL=verbose\n// console: [logger] Invalid LOG_LEVEL 'verbose'. Valid levels: ... Falling back to 'info'.\n// after\nLOG_LEVEL=debug","handlingStrategy":"validation","validationCode":"const VALID = new Set(['debug','info','warn','error']);\nconst lvl = process.env.LOG_LEVEL?.toLowerCase().trim();\nif (lvl && !VALID.has(lvl)) console.warn(`LOG_LEVEL '${process.env.LOG_LEVEL}' invalid; using 'info'`);","typeGuard":"function isValidLogLevel(v: string | undefined): v is 'debug'|'info'|'warn'|'error' {\n  return !!v && ['debug','info','warn','error'].includes(v.toLowerCase().trim());\n}","tryCatchPattern":null,"preventionTips":["Restrict LOG_LEVEL values in .env files and CI to the documented set.","Normalize (lowercase/trim) env values before export.","Add a startup smoke check that asserts the configured level is accepted."],"tags":["logging","environment-variable","configuration"],"backgroundTag":"invalid-log-level","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}