{"record":{"id":"f0a93ffc0a7dde45","repo":"pinojs/pino","slug":"unknown-level-level-f0a93f","errorCode":null,"errorMessage":"unknown level ${level}","messagePattern":"unknown level (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/levels.js","lineNumber":83,"sourceCode":"    case 'fatal':\n    case 'error':\n    case 'warn':\n    case 'info':\n    case 'debug':\n    case 'trace':\n      return true\n    default:\n      return false\n  }\n}\n\nfunction setLevel (level) {\n  const { labels, values } = this.levels\n  if (typeof level === 'number') {\n    if (labels[level] === undefined) throw Error('unknown level value' + level)\n    level = labels[level]\n  }\n  if (values[level] === undefined) throw Error('unknown level ' + level)\n  const preLevelVal = this[levelValSym]\n  const levelVal = this[levelValSym] = values[level]\n  const useOnlyCustomLevelsVal = this[useOnlyCustomLevelsSym]\n  const levelComparison = this[levelCompSym]\n  const hook = this[hooksSym].logMethod\n\n  for (const key in values) {\n    if (levelComparison(values[key], levelVal) === false) {\n      this[key] = noop\n      continue\n    }\n    this[key] = isStandardLevel(key, useOnlyCustomLevelsVal) ? levelMethods[key](hook) : genLog(values[key], hook)\n  }\n\n  this.emit(\n    'level-change',\n    level,\n    levelVal,","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/pinojs/pino/blob/5aa62305c57709ebd6f6b7c328e8830eeb29b297/lib/levels.js#L65-L101","documentation":"setLevel throws this when the given level name is not registered in the logger's levels map (or when a numeric level value has no matching label). Pino resolves levels strictly against its internal labels/values lookup, so any unknown string or out-of-range number is rejected immediately rather than silently ignored.","triggerScenarios":"logger.setLevel('verbose') where 'verbose' was never defined via customLevels; setLevel(99) where no label maps to that numeric value; setLevel on a logger whose customLevels option excluded the name being set.","commonSituations":"Typos in level names, passing levels from another logging library (winston 'verbose', log4j 'trace' as string), configuring custom levels but then setting a default library level by name, or reading a level from config/env with a stale value.","solutions":["Use a level name that exists in this logger's levels (call logger.levels to see valid labels/values).","If using a custom level, pass it in the customLevels option at logger creation before calling setLevel.","If passing a number, ensure it matches a defined level value (e.g. 30 for 'info' in default levels).","Fix config/env values that supply the level string, trimming whitespace and casing (level names are case-sensitive)."],"exampleFix":"// before\nlogger.setLevel('verbose')\n// after\nconst pino = require('pino')\nconst logger = pino({ customLevels: { verbose: 25 } })\nlogger.setLevel('verbose')","handlingStrategy":"validation","validationCode":"function isValidLevel(logger, level) {\n  if (typeof level === 'number') return level in logger.levels.labels\n  return typeof level === 'string' && level in logger.levels.values\n}\nif (!isValidLevel(logger, cfg.level)) throw new Error(`unsupported level: ${cfg.level}`)","typeGuard":"function isKnownLevel(logger, level) {\n  return typeof level === 'number'\n    ? level in logger.levels.labels\n    : typeof level === 'string' && level in logger.levels.values\n}","tryCatchPattern":"try {\n  logger.setLevel(cfg.level)\n} catch (e) {\n  if (String(e.message).startsWith('unknown level')) {\n    logger.warn(`invalid level ${cfg.level}, falling back to 'info'`)\n    logger.setLevel('info')\n  } else throw e\n}","preventionTips":["Derive level choices from logger.levels.labels instead of hardcoding strings.","Whitelist accepted level names at the config boundary.","Remember level names are case-sensitive strings; trim env-sourced values.","Define custom levels once at logger creation before any setLevel call."],"tags":["configuration","logging","invalid-argument"],"backgroundTag":"unknown-log-level","analyzedSha":"5aa62305c57709ebd6f6b7c328e8830eeb29b297","analyzedAt":"2026-09-02T22:05:21.418Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}