Skip to content
Permalink
Browse files

Fixed logs folder checking and creation

Previously, if YaCy log folder was for example at
`/home/user/yacy/DATA/LOG`, because of improper truncation of log path,
an unnecessary directory creation was atempted at `/home/us`.
  • Loading branch information...
luccioman committed Aug 31, 2018
1 parent 3f9abec commit 9b1c87033b7a4aa12ea607081c836c6e614a492c
Showing with 18 additions and 6 deletions.
  1. +18 −6 source/net/yacy/cora/util/ConcurrentLog.java
@@ -390,12 +390,24 @@ public final static void configureLogging(final File dataPath, final File appPat

// creating the logging directory
String logPattern = logManager.getProperty("java.util.logging.FileHandler.pattern");
int stripPos = logPattern.lastIndexOf(File.separatorChar);
if (!new File(logPattern).isAbsolute()) logPattern = new File(dataPath, logPattern).getAbsolutePath();
if (stripPos < 0) stripPos = logPattern.lastIndexOf(File.separatorChar);
File log = new File(logPattern.substring(0, stripPos));
if (!log.isAbsolute()) log = new File(dataPath, log.getPath());
if (!log.canRead()) log.mkdir();
File logFile = new File(logPattern);
if (!logFile.isAbsolute()) {
logFile = new File(dataPath, logPattern);
logPattern = logFile.getAbsolutePath();
}
File logDirectory = logFile.getParentFile();
if(logDirectory != null) {
if (!logDirectory.isAbsolute()) {
logDirectory = new File(dataPath, logDirectory.getPath());
}
if (!logDirectory.exists()) {
if(!logDirectory.mkdir()) {
System.err.println("STARTUP: Could not create the logs directory at " + logDirectory.getAbsolutePath());
}
} else if(!logDirectory.isDirectory()) {
System.err.println("STARTUP: Log file parent path at " + logDirectory.getAbsolutePath() + "is not a directory");
}
}

// generating the root logger
final Logger logger = Logger.getLogger("");

0 comments on commit 9b1c870

Please sign in to comment.
You can’t perform that action at this time.