From d66f3877f1d4781a4fa465a220232ff772cc6a62 Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 27 Apr 2021 12:07:24 +0200 Subject: [client] Set log4j debug level for file (DEBUG) and console (INFO) --- .../src/main/java/org/openslx/dozmod/App.java | 31 ++++++++++++++++------ .../gui/changemonitor/DialogChangeMonitor.java | 2 +- .../dozmod/gui/window/ImageDetailsWindow.java | 4 +-- dozentenmodul/src/main/properties/log4j.properties | 17 ++++++++---- 4 files changed, 38 insertions(+), 16 deletions(-) (limited to 'dozentenmodul/src') diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java index a062c1d6..7e13be8d 100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java @@ -24,6 +24,8 @@ import javax.swing.UIManager; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.BasicConfigurator; import org.apache.log4j.FileAppender; +import org.apache.log4j.Level; +import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; import org.apache.log4j.spi.LoggingEvent; @@ -56,7 +58,7 @@ public class App { private static String masterServerHost = null; - private static void setupLogger() { + private static String setupFileLogger() { // path to the log file final String logFilePath = Config.getPath() + File.separator + Branding.getConfigDirectory() + ".log"; @@ -79,13 +81,12 @@ public class App { // add file appender to global logger FileAppender fa = null; try { - fa = new FileAppender(new PatternLayout("%d [%F:%M] %m%n"), logFilePath); + fa = new FileAppender(new PatternLayout("[%t] %-5p %F - %m%n"), logFilePath); fa.setEncoding("UTF-8"); - // All classes should log to file, configure global file appender. + fa.setThreshold(Level.DEBUG); } catch (IOException e) { LOGGER.error("Failed to set logfile path to '" + logFilePath + "': ", e); - BasicConfigurator.configure(); - return; + return null; } final FileAppender ffa = fa; @@ -123,7 +124,14 @@ public class App { } }; + // register file logger (appender) BasicConfigurator.configure(ap); + + return logFilePath; + } + + public static void logHeader(String logFilePath) + { LOGGER.info("Starting logging to: " + logFilePath); LOGGER.info(Branding.getApplicationName() + " Version: " + ClientVersion.getLocalRevision()); LOGGER.info(" " + FormatHelper.longDate(ClientVersion.getLocalRevTimestamp())); @@ -135,8 +143,14 @@ public class App { LOGGER.info("java.vm.version: " + System.getProperty("java.vm.version")); LOGGER.info("java.runtime.version: " + System.getProperty("java.runtime.version")); } - - public static void main(final String[] args) throws InvocationTargetException, InterruptedException { + + public static void main(final String[] args) throws InvocationTargetException, InterruptedException + { + // setup basic logging appender to log output on console if no external appender (log4j.properties) is configured + if (LogManager.getRootLogger().getAllAppenders() == null) { + BasicConfigurator.configure(); + } + if (args.length >= 2) { if (args[0].equals("--json")) { writeJsonUpdateFile(args[1]); @@ -161,7 +175,8 @@ public class App { return; } - setupLogger(); + final String logFilePath = setupFileLogger(); + logHeader(logFilePath); // Setting the locale if (!setPreferredLanguage()) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/changemonitor/DialogChangeMonitor.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/changemonitor/DialogChangeMonitor.java index 4651bdad..6e2df962 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/changemonitor/DialogChangeMonitor.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/changemonitor/DialogChangeMonitor.java @@ -154,7 +154,7 @@ public class DialogChangeMonitor { * @param cw The ControlWrapper where the changed state changed. */ void contentChanged(AbstractControlWrapper cw) { - LOGGER.info(cw.getClass().getSimpleName() + " is changed: " + cw.isCurrentlyChanged); + LOGGER.debug(cw.getClass().getSimpleName() + " is changed: " + cw.isCurrentlyChanged); final boolean oldEver = this.wasEverModified; final boolean oldCurrent = this.isCurrentlyModified; this.wasEverModified = false; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java index bad9cea0..a847082f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java @@ -141,12 +141,12 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout @Override public void validityChanged(String errorMessage) { lblError.setText(errorMessage); btnSaveChanges.setEnabled(changeMonitor.isValid() && changeMonitor.wasEverModified()); - LOGGER.info("Valid: " + changeMonitor.isValid()); + LOGGER.debug("Valid: " + changeMonitor.isValid()); } @Override public void modificationChanged() { btnSaveChanges.setEnabled(changeMonitor.isValid() && changeMonitor.wasEverModified()); - LOGGER.info("Changed: " + changeMonitor.isCurrentlyModified()); + LOGGER.debug("Changed: " + changeMonitor.isCurrentlyModified()); } }); // Hook when user presses X (top right) diff --git a/dozentenmodul/src/main/properties/log4j.properties b/dozentenmodul/src/main/properties/log4j.properties index 21c0faed..8fa5e798 100644 --- a/dozentenmodul/src/main/properties/log4j.properties +++ b/dozentenmodul/src/main/properties/log4j.properties @@ -1,6 +1,13 @@ -log4j.rootLogger=DEBUG, A1 +# root level logging configuration +log4j.rootLogger=ALL, console -log4j.appender.A1=org.apache.log4j.ConsoleAppender -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=[%t] %-5p %F - %m%n -log4j.logger.org.apache.directory=ERROR +# NOTE: The file logging appender is added and configured by the Java +# implementation, since the logging file path and logic can only +# be realized by the implementation (using system properties). + +# configuration for console output +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=[%t] %-5p %F - %m%n +log4j.appender.console.encoding=UTF-8 +log4j.appender.console.Threshold=INFO -- cgit v1.2.3-55-g7522