{"record":{"id":"53336214f60570d6","repo":"stanfordnlp/CoreNLP","slug":"cannot-initialize-logger-533362","errorCode":null,"errorMessage":"Cannot initialize logger!","messagePattern":"Cannot initialize logger!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/dcoref/SieveCoreferenceSystem.java","lineNumber":336,"sourceCode":"  public static String initializeAndRunCoref(Properties props) throws Exception {\n    String timeStamp = Calendar.getInstance().getTime().toString().replaceAll(\"\\\\s\", \"-\").replaceAll(\":\", \"-\");\n\n    //\n    // initialize logger\n    //\n    String logFileName = props.getProperty(Constants.LOG_PROP, \"log.txt\");\n    if (logFileName.endsWith(\".txt\")) {\n      logFileName = logFileName.substring(0, logFileName.length()-4) +\"_\"+ timeStamp+\".txt\";\n    } else {\n      logFileName = logFileName + \"_\"+ timeStamp+\".txt\";\n    }\n    try {\n      FileHandler fh = new FileHandler(logFileName, false);\n      logger.addHandler(fh);\n      logger.setLevel(Level.FINE);\n      fh.setFormatter(new NewlineLogFormatter());\n    } catch (SecurityException | IOException e) {\n      throw new RuntimeException(\"Cannot initialize logger!\", e);\n    }\n\n    logger.fine(timeStamp);\n    logger.fine(props.toString());\n    Constants.printConstants(logger);\n\n    // initialize coref system\n    SieveCoreferenceSystem corefSystem = new SieveCoreferenceSystem(props);\n\n    // MentionExtractor extracts MUC, ACE, or CoNLL documents\n    MentionExtractor mentionExtractor;\n    if (props.containsKey(Constants.MUC_PROP)){\n      mentionExtractor = new MUCMentionExtractor(corefSystem.dictionaries, props,\n                                                 corefSystem.semantics, corefSystem.singletonPredictor);\n    } else if(props.containsKey(Constants.ACE2004_PROP) || props.containsKey(Constants.ACE2005_PROP)) {\n      mentionExtractor = new ACEMentionExtractor(corefSystem.dictionaries, props,\n                                                 corefSystem.semantics, corefSystem.singletonPredictor);\n    } else if (props.containsKey(Constants.CONLL2011_PROP)) {","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/dcoref/SieveCoreferenceSystem.java#L318-L354","documentation":"initializeAndRunCoref sets up a java.util.logging FileHandler writing to logFileName. Creating that handler can fail with SecurityException (security manager denies logging/file access) or IOException (bad path, unwritable directory), and the code wraps this in a RuntimeException 'Cannot initialize logger!' so startup aborts before any coreference processing.","triggerScenarios":"Running main with a log file path that points to a non-existent directory, an unwritable location, or when a SecurityManager blocks FileHandler creation; also if the log file is locked by another process on some platforms.","commonSituations":"Passing a -Ddcoref.log or properties log path with a directory that doesn't exist; running in a sandboxed/read-only deployment where the process cannot create files; relative log paths resolved against an unexpected working directory in a server or container.","solutions":["Ensure the directory of the configured log file exists and the process has write permission there","Use an absolute log file path, or point the log to a writable temp directory","Remove or elevate the SecurityManager restriction, or grant logging permission (e.g. FilePermission and LoggingPermission)","Catch the RuntimeException around initializeAndRunCoref and fall back to console logging (java.util.logging ConsoleHandler) instead of a file"],"exampleFix":"// before\ncoref.props: dcoref.log = logs/coref.log   // 'logs' does not exist\n// after\n// create the directory first, or use an absolute path\nnew File(\"logs\").mkdirs();\nprops.setProperty(\"dcoref.log\", \"/var/log/coref/coref.log\");","handlingStrategy":"try-catch","validationCode":"String logFile = props.getProperty(\"dcoref.log\", \"coref.log\");\nFile f = new File(logFile);\nFile parent = f.getAbsoluteFile().getParentFile();\nif (parent != null && !parent.isDirectory() && !parent.mkdirs())\n  throw new IOException(\"Cannot create log dir: \" + parent);\nif (!f.getAbsolutePath().isEmpty() && f.exists() && !f.canWrite())\n  throw new IOException(\"Log file not writable: \" + f);","typeGuard":null,"tryCatchPattern":"try {\n  SieveCoreferenceSystem.runCoref(props);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Cannot initialize logger\")) {\n    logger.addHandler(new ConsoleHandler()); // fallback to console logging\n    logger.warning(\"File logging unavailable: \" + e.getCause());\n  } else throw e;\n}","preventionTips":["Use absolute paths for the log file in server/container deployments","Ensure the working process has write permissions to the log directory","Create log directories during deployment, not at first run","Avoid running under a SecurityManager without granting logging/File permissions"],"tags":["corenlp","logging","file-io","startup"],"backgroundTag":"file-write-failed","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}