summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/App.java
diff options
context:
space:
mode:
authorManuel Bentele2021-04-27 12:07:24 +0200
committerManuel Bentele2021-04-27 14:22:51 +0200
commitd66f3877f1d4781a4fa465a220232ff772cc6a62 (patch)
treeaa341d5bd8608e642f39950af210d2331bd23a50 /dozentenmodul/src/main/java/org/openslx/dozmod/App.java
parent[client,server] Refactors and abstracts version information in config logic a... (diff)
downloadtutor-module-d66f3877f1d4781a4fa465a220232ff772cc6a62.tar.gz
tutor-module-d66f3877f1d4781a4fa465a220232ff772cc6a62.tar.xz
tutor-module-d66f3877f1d4781a4fa465a220232ff772cc6a62.zip
[client] Set log4j debug level for file (DEBUG) and console (INFO)
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/App.java')
-rwxr-xr-xdozentenmodul/src/main/java/org/openslx/dozmod/App.java31
1 files changed, 23 insertions, 8 deletions
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()) {