From a96af61f79240eb20d0426b2c43b2bc2d6600991 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 15 Mar 2016 14:57:21 +0000 Subject: [PATCH] Better logging defaults --- source/net/filebot/Logging.java | 2 +- source/net/filebot/Main.java | 53 +++++++++++++++------------------ 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/source/net/filebot/Logging.java b/source/net/filebot/Logging.java index d7ead35e..afbcd983 100644 --- a/source/net/filebot/Logging.java +++ b/source/net/filebot/Logging.java @@ -21,7 +21,7 @@ import net.filebot.util.SystemProperty; public final class Logging { private static final SystemProperty anonymizePattern = SystemProperty.of("net.filebot.logging.anonymize", Pattern::compile); - private static final SystemProperty debugLevel = SystemProperty.of("net.filebot.logging.debug", Level::parse, Level.CONFIG); + private static final SystemProperty debugLevel = SystemProperty.of("net.filebot.logging.debug", Level::parse, Level.WARNING); public static final Logger log = createConsoleLogger("net.filebot.console", Level.ALL); public static final Logger debug = createConsoleLogger("net.filebot.debug", debugLevel.get()); diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index 68630575..87ca4333 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -421,38 +421,9 @@ public class Main { } public static void initializeLogging(ArgumentBean args) throws IOException { - // tee stdout and stderr to log file if set - if (args.logFile != null) { - File logFile = new File(args.logFile); - if (!logFile.isAbsolute()) { - logFile = new File(ApplicationFolder.AppData.resolve("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 = FileChannel.open(logFile.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND); - if (args.logLock) { - if (args.getLogLevel() == Level.ALL) { - debug.config("Locking " + logFile); - } - logChannel.lock(); - } - - OutputStream out = Channels.newOutputStream(logChannel); - System.setOut(new TeePrintStream(out, true, "UTF-8", System.out)); - System.setErr(new TeePrintStream(out, true, "UTF-8", System.err)); - } - if (args.runCLI()) { // CLI logging settings log.setLevel(args.getLogLevel()); - - // set debug log level standard log level if lower - if (debug.getLevel().intValue() < log.getLevel().intValue()) { - debug.setLevel(log.getLevel()); - } } else { // GUI logging settings log.setLevel(Level.INFO); @@ -467,6 +438,30 @@ public class Main { debug.log(Level.WARNING, "Failed to initialize error log", e); } } + + // tee stdout and stderr to log file if set + if (args.logFile != null) { + File logFile = new File(args.logFile); + if (!logFile.isAbsolute()) { + logFile = new File(ApplicationFolder.AppData.resolve("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 = FileChannel.open(logFile.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.APPEND); + if (args.logLock) { + if (args.getLogLevel() == Level.ALL) { + log.config("Locking " + logFile); + } + logChannel.lock(); + } + + OutputStream out = Channels.newOutputStream(logChannel); + System.setOut(new TeePrintStream(out, true, "UTF-8", System.out)); + System.setErr(new TeePrintStream(out, true, "UTF-8", System.err)); + } } }