diff --git a/source/net/sourceforge/filebot/Main.java b/source/net/sourceforge/filebot/Main.java index d6cb0177..409e2b51 100644 --- a/source/net/sourceforge/filebot/Main.java +++ b/source/net/sourceforge/filebot/Main.java @@ -94,9 +94,16 @@ public class Main { // tee stdout and stderr to log file if set if (args.logFile != null) { - File logFile = args.getLogFile(); - FileChannel logChannel = new FileOutputStream(logFile, true).getChannel(); + File logFile = new File(args.logFile); + if (!logFile.isAbsolute()) { + logFile = new File(new File(getApplicationFolder(), "logs"), logFile.getPath()).getAbsoluteFile(); // by default resolve relative paths against {applicationFolder}/logs/{logFile} + } + if (!logFile.exists() && !logFile.getParentFile().mkdirs() && !logFile.createNewFile()) { + throw new IOException("Failed to create log file: " + logFile); + } + // open file channel and lock + FileChannel logChannel = new FileOutputStream(logFile, true).getChannel(); if (args.logLock) { System.out.println("Locking " + logFile); logChannel.lock(); diff --git a/source/net/sourceforge/filebot/cli/ArgumentBean.java b/source/net/sourceforge/filebot/cli/ArgumentBean.java index e363d55e..668dbcf7 100644 --- a/source/net/sourceforge/filebot/cli/ArgumentBean.java +++ b/source/net/sourceforge/filebot/cli/ArgumentBean.java @@ -6,7 +6,6 @@ import static java.util.Collections.*; import static net.sourceforge.tuned.FileUtilities.*; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -188,13 +187,4 @@ public class ArgumentBean { return Level.parse(log.toUpperCase()); } - - public File getLogFile() throws IOException { - File f = new File(logFile).getAbsoluteFile(); - if (!f.exists() && !f.getParentFile().mkdirs() && !f.createNewFile()) { - throw new IOException("Failed to create log file: " + f); - } - return f; - } - }