Better logging defaults
This commit is contained in:
parent
f5442e7316
commit
a96af61f79
|
@ -21,7 +21,7 @@ import net.filebot.util.SystemProperty;
|
|||
public final class Logging {
|
||||
|
||||
private static final SystemProperty<Pattern> anonymizePattern = SystemProperty.of("net.filebot.logging.anonymize", Pattern::compile);
|
||||
private static final SystemProperty<Level> debugLevel = SystemProperty.of("net.filebot.logging.debug", Level::parse, Level.CONFIG);
|
||||
private static final SystemProperty<Level> 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());
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue