stanfordnlp/CoreNLP · error · RuntimeException
Cannot initialize logger!
Error message
Cannot initialize logger!
What it means
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.
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
Example fix
// before
coref.props: dcoref.log = logs/coref.log // 'logs' does not exist
// after
// create the directory first, or use an absolute path
new File("logs").mkdirs();
props.setProperty("dcoref.log", "/var/log/coref/coref.log"); Defensive patterns
Strategy: try-catch
Validate before calling
String logFile = props.getProperty("dcoref.log", "coref.log");
File f = new File(logFile);
File parent = f.getAbsoluteFile().getParentFile();
if (parent != null && !parent.isDirectory() && !parent.mkdirs())
throw new IOException("Cannot create log dir: " + parent);
if (!f.getAbsolutePath().isEmpty() && f.exists() && !f.canWrite())
throw new IOException("Log file not writable: " + f); Try / catch
try {
SieveCoreferenceSystem.runCoref(props);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().contains("Cannot initialize logger")) {
logger.addHandler(new ConsoleHandler()); // fallback to console logging
logger.warning("File logging unavailable: " + e.getCause());
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Unknown value for log.method
- Cannot initialize logger!
- Shouldn't happen:
- Error reading saved links
- RuntimeIOException wrapping IOException
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/53336214f60570d6.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/dcoref/SieveCoreferenceSystem.java:336
public static String initializeAndRunCoref(Properties props) throws Exception {
String timeStamp = Calendar.getInstance().getTime().toString().replaceAll("\\s", "-").replaceAll(":", "-");
//
// initialize logger
//
String logFileName = props.getProperty(Constants.LOG_PROP, "log.txt");
if (logFileName.endsWith(".txt")) {
logFileName = logFileName.substring(0, logFileName.length()-4) +"_"+ timeStamp+".txt";
} else {
logFileName = logFileName + "_"+ timeStamp+".txt";
}
try {
FileHandler fh = new FileHandler(logFileName, false);
logger.addHandler(fh);
logger.setLevel(Level.FINE);
fh.setFormatter(new NewlineLogFormatter());
} catch (SecurityException | IOException e) {
throw new RuntimeException("Cannot initialize logger!", e);
}
logger.fine(timeStamp);
logger.fine(props.toString());
Constants.printConstants(logger);
// initialize coref system
SieveCoreferenceSystem corefSystem = new SieveCoreferenceSystem(props);
// MentionExtractor extracts MUC, ACE, or CoNLL documents
MentionExtractor mentionExtractor;
if (props.containsKey(Constants.MUC_PROP)){
mentionExtractor = new MUCMentionExtractor(corefSystem.dictionaries, props,
corefSystem.semantics, corefSystem.singletonPredictor);
} else if(props.containsKey(Constants.ACE2004_PROP) || props.containsKey(Constants.ACE2005_PROP)) {
mentionExtractor = new ACEMentionExtractor(corefSystem.dictionaries, props,
corefSystem.semantics, corefSystem.singletonPredictor);
} else if (props.containsKey(Constants.CONLL2011_PROP)) {View on GitHub (pinned to 1b7edd19c4)