stanfordnlp/CoreNLP · error · RuntimeException
Cannot initialize logger!
Error message
Cannot initialize logger!
What it means
CorefSystem.initLogger throws RuntimeException("Cannot initialize logger!") when java.util.logging FileHandler cannot attach a handler to logFileName — a SecurityException (security manager denies file logging) or IOException (path unwritable/invalid).
Solutions
- Set the coref log file property to an absolute path in a writable directory and create parent dirs first
- Check file write permissions on the log directory (chmod / run as appropriate user)
- If a SecurityManager is active, grant FileHandler permissions or use console logging instead
- Wrap or reconfigure java.util.logging to log to stdout in restricted environments
Example fix
// before
props.setProperty("coref.logFile", "logs/coref.log"); // logs/ doesn't exist
// after
File logDir = new File("/tmp/coref-logs");
logDir.mkdirs();
props.setProperty("coref.logFile", new File(logDir, "coref.log").getAbsolutePath()); Defensive patterns
Strategy: validation
Validate before calling
File logFile = new File(logFileName);
File parent = logFile.getAbsoluteFile().getParentFile();
if (parent != null && !parent.isDirectory() && !parent.mkdirs()) {
throw new IllegalStateException("Cannot create log dir: " + parent);
}
if (!logFile.getParentFile().canWrite()) {
throw new IllegalStateException("Log dir not writable: " + parent);
} Try / catch
try {
system.runOnConll(props);
} catch (RuntimeException e) {
if ("Cannot initialize logger!".equals(e.getMessage())) {
logger.log(Level.SEVERE, "Logger init failed; check log path/permissions", e.getCause());
} else throw e;
} Prevention
- Configure the coref log file to an absolute path in a writable directory
- Create parent directories before running
- Check for SecurityManager restrictions in the deployment environment
- Fall back to console logging in containers/sandboxes
When it happens
Trigger: initLogger called (from runOnConll) with a logFileName in a nonexistent directory, a read-only location, or blocked by a SecurityException from a security manager.
Common situations: Log path points to a non-writable directory under the working dir; running in a sandboxed/containerized environment with restricted file access; logFileName containing invalid path characters or a locked file.
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
- Error creating data exporter
- RuntimeIOException wrapping IOException
- Serializing classifier to
- Could not create directory <tgtDir.getAbsolutePath()>
- cp: could not list files in source
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/4fdd48bf074a2294.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/coref/CorefSystem.java:85
CorefUtils.removeSingletonClusters(document);
}
CorefUtils.checkForInterrupt();
Map<Integer, CorefChain> result = Generics.newHashMap();
for (CorefCluster c : document.corefClusters.values()) {
result.put(c.clusterID, new CorefChain(c, document.positions));
}
ann.set(CorefCoreAnnotations.CorefChainAnnotation.class, result);
}
public void initLogger(Logger logger, String logFileName) {
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);
}
}
public void runOnConll(Properties props) throws Exception {
File f = new File(CorefProperties.conllOutputPath(props));
if (! f.exists()) {
f.mkdirs();
}
String timestamp = Calendar.getInstance().getTime().toString().replaceAll("\\s", "-").replaceAll(":", "-");
String baseName = CorefProperties.conllOutputPath(props) + timestamp;
String goldOutput = baseName + ".gold.txt";
String beforeCorefOutput = baseName + ".predicted.txt";
String afterCorefOutput = baseName + ".coref.predicted.txt";
PrintWriter writerGold = new PrintWriter(new FileOutputStream(goldOutput));
PrintWriter writerBeforeCoref = new PrintWriter(new FileOutputStream(beforeCorefOutput));
PrintWriter writerAfterCoref = new PrintWriter(new FileOutputStream(afterCorefOutput));
Logger logger = Logger.getLogger(CorefSystem.class.getName());View on GitHub (pinned to 1b7edd19c4)