{"record":{"id":"59cb550bf56c4734","repo":"statsd/statsd","slug":"undefined-log-level-level","errorCode":null,"errorMessage":"Undefined log level: ${level}","messagePattern":"Undefined log level: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/logger.js","lineNumber":35,"sourceCode":"};\n\nLogger.prototype = {\n  log: function (msg, type) {\n    if (this.backend == 'stdout') {\n      if (!type) {\n        type = 'DEBUG';\n      }\n      this.util.log(type + \": \" + msg);\n    } else {\n      let level;\n      if (!type) {\n        level = this.level;\n      } else {\n        level = \"LOG_\" + type.toUpperCase();\n      }\n\n      if (!this.util[level]) {\n        throw \"Undefined log level: \" + level;\n      }\n\n      this.util.log(this.util[level], msg);\n    }\n  }\n};\n\nexports.Logger = Logger;\n","sourceCodeStart":17,"sourceCodeEnd":44,"githubUrl":"https://github.com/statsd/statsd/blob/f7157b880631152569b04d626f631b60eec366f8/lib/logger.js#L17-L44","documentation":"When logging to the syslog backend, Logger.log() maps the requested type to a syslog priority constant by building the string 'LOG_' + type.toUpperCase() (or falls back to the configured default level). If modern-syslog does not export a constant with that name (e.g. LOG_FOO is undefined), the throw fires before calling this.util.log.","triggerScenarios":"Calling logger.log('message', 'foo') with a syslog backend where 'foo' does not map to a modern-syslog constant (valid types derive from LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR, LOG_CRIT, LOG_ALERT, LOG_EMERG); or configuring `level: \"LOG_VERBOSE\"`/any non-standard default level in the config so that the no-type call path resolves to an undefined constant.","commonSituations":"Typo'd or custom level strings in the config `level` option; calling log() with a type string like 'warn' instead of 'warning' or 'error' instead of 'err'; switching from a logger that accepted arbitrary level names to the syslog backend; using log types that worked under stdout (where any type string is accepted verbatim) then enabling syslog.","solutions":["Use a valid syslog type when calling log(): 'debug', 'info', 'notice', 'warning', 'err', 'crit', 'alert', or 'emerg'.","Set config `level` to a defined modern-syslog constant name such as 'LOG_INFO' or 'LOG_DEBUG'.","Validate type/level strings before calling log(), e.g. with an allowlist check.","If stdout semantics are needed (any label accepted), keep backend as 'stdout' rather than syslog."],"exampleFix":"// before\nlogger.log(\"cache expired\", \"warn\");\n\n// after\nlogger.log(\"cache expired\", \"warning\"); // maps to LOG_WARNING","handlingStrategy":"validation","validationCode":"const SYSLOG_LEVELS = ['debug','info','notice','warning','err','crit','alert','emerg'];\nfunction assertLogLevel(type) {\n  if (type && !SYSLOG_LEVELS.includes(String(type).toLowerCase())) {\n    throw new Error(`Invalid log level '${type}' for syslog backend`);\n  }\n}","typeGuard":"function isSyslogLevel(t) {\n  return typeof t === 'string' &&\n    ['LOG_DEBUG','LOG_INFO','LOG_NOTICE','LOG_WARNING','LOG_ERR','LOG_CRIT','LOG_ALERT','LOG_EMERG']\n      .includes('LOG_' + t.toUpperCase());\n}","tryCatchPattern":"try {\n  logger.log(msg, type);\n} catch (e) {\n  if (String(e).startsWith('Undefined log level')) {\n    console.error(`Bad log level '${type}', retrying at LOG_INFO`);\n    logger.log(msg, 'info');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Centralize logging through a wrapper that normalizes type names ('warn' -> 'warning', 'error' -> 'err') before calling logger.log().","Set config `level` only to documented modern-syslog constant names like LOG_INFO or LOG_DEBUG.","Check level strings are uppercase constants when switching backends from stdout to syslog.","Wrap logger.log calls so a bad level degrades to LOG_INFO instead of crashing the stats server."],"tags":["logging","syslog","configuration","statsd"],"backgroundTag":"invalid-log-level","analyzedSha":"f7157b880631152569b04d626f631b60eec366f8","analyzedAt":"2026-09-02T22:17:24.160Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}