{"record":{"id":"1d18cd7565c2ed6f","repo":"docmirror/dev-sidecar","slug":"error-1d18cd","errorCode":null,"errorMessage":"未指定日志类型，无法配置并获取日志对象！！！","messagePattern":"未指定日志类型，无法配置并获取日志对象！！！","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/utils/util.logger.js","lineNumber":76,"sourceCode":"    config.categories[category] = { appenders: logToConsole ? [category, 'std'] : [category], level }\n  }\n\n  log4js.configure(config)\n\n  // 拿第一个日志类型来logger并设置到log变量中\n  log = log4js.getLogger(categories[0])\n  logOrConsole.setLogger(log)\n\n  log.info(`设置日志配置完成，进程ID: ${process.pid}，categories：[${categories}]，config:`, JSON.stringify(config))\n}\n\nmodule.exports = {\n  getLogger (category) {\n    if (!category) {\n      if (log) {\n        log.error('未指定日志类型，无法配置并获取日志对象！！！')\n      }\n      throw new Error('未指定日志类型，无法配置并获取日志对象！！！')\n    }\n\n    if (category === 'core' || category === 'gui') {\n      // core 和 gui 的日志配置，因为它们在同一进程中，所以一起配置，且只能配置一次\n      if (log == null) {\n        log4jsConfigure(['core', 'gui'])\n      }\n\n      return log4js.getLogger(category)\n    } else {\n      if (log == null) {\n        log4jsConfigure([category])\n      } else if (category !== log.category) {\n        log.error(`当前进程已经设置过日志配置，无法再设置 \"${category}\" 的配置，先临时返回 \"${log.category}\" 的 log 进行日志记录。如果与其他类型的日志在同一进程中写入，请参照 core 和 gui 一起配置`)\n      }\n\n      return log\n    }","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/docmirror/dev-sidecar/blob/7710cd56cce760c708f30b01d2d4056eb8c402d5/packages/core/src/utils/util.logger.js#L58-L94","documentation":"getLogger(category) configures and returns a log4js logger per category ('core', 'gui', 'server', etc.). A category name is mandatory — it selects the log file and appenders. When called with a falsy category (undefined, null, ''), the function logs and throws this error since it cannot configure a logger without knowing which one is requested.","triggerScenarios":"Calling util.logger.getLogger() with no argument; passing an empty string or null category, typically from a variable that was not initialized (e.g. `getLogger(category)` where category comes from config or constructor that omitted it).","commonSituations":"Refactoring code and forgetting to pass the module name; constructing a class with an optional name field left undefined; copying a getLogger call and deleting the literal; config-driven category lookup returning empty.","solutions":["Pass an explicit category string: getLogger('core'), getLogger('server'), etc.","Check the variable supplying the category — initialize or default it (e.g. `category || 'server'`)","If the category comes from config/options, validate it is a non-empty string before calling getLogger","Grep your call sites for getLogger( with missing/empty arguments"],"exampleFix":"// before\nconst log = getLogger(options.category) // undefined when options.category missing\n// after\nconst log = getLogger(options.category || 'server')","handlingStrategy":"validation","validationCode":"function getLoggerSafe(category) {\n  if (typeof category !== 'string' || category.trim() === '') {\n    category = 'server' // or throw your own descriptive error\n  }\n  return getLogger(category)\n}","typeGuard":"function isValidCategory(c) { return typeof c === 'string' && c.trim() !== '' }","tryCatchPattern":"try {\n  const log = getLogger(category)\n} catch (e) {\n  if (String(e.message).includes('未指定日志类型')) {\n    console.error('Logger category missing; defaulting to console')\n    return console\n  }\n  throw e\n}","preventionTips":["Always pass a literal category name to getLogger","Default optional category variables ('' || 'server')","Validate options/config objects that supply category names","List valid categories (core/gui/server/...) in your module docs"],"tags":["logging","missing-argument","configuration"],"backgroundTag":"missing-logger-category","analyzedSha":"7710cd56cce760c708f30b01d2d4056eb8c402d5","analyzedAt":"2026-08-31T22:07:07.234Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}