From 407f22692b8003e7ddf40c6863072142f858ef89 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Tue, 4 Jan 2022 14:20:09 +0100 Subject: [PATCH] Added level log4j2 configuration. --- .../statoolinfos/StatoolInfosLauncher.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/fr/devinsy/statoolinfos/StatoolInfosLauncher.java b/src/fr/devinsy/statoolinfos/StatoolInfosLauncher.java index d07b413..cc9fb29 100644 --- a/src/fr/devinsy/statoolinfos/StatoolInfosLauncher.java +++ b/src/fr/devinsy/statoolinfos/StatoolInfosLauncher.java @@ -71,13 +71,31 @@ public final class StatoolInfosLauncher } else { + // + Level logEnvLevel = Level.getLevel(System.getenv().get("LOG4J_LEVEL")); + Level logPropertyLevel = Level.getLevel(System.getProperty("log4j2.level")); + + Level level; + if (logPropertyLevel != null) + { + level = logPropertyLevel; + } + else if (logEnvLevel != null) + { + level = logEnvLevel; + } + else + { + level = Level.INFO; + } + // Build a custom default log configuration. ConfigurationBuilder builder = ConfigurationBuilderFactory.newConfigurationBuilder(); builder.setStatusLevel(Level.ERROR); builder.setConfigurationName("CustomDefaultLogger"); AppenderComponentBuilder appenderBuilder = builder.newAppender("Console", "CONSOLE").addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); appenderBuilder.add(builder.newLayout("PatternLayout").addAttribute("pattern", "%m%n")); - RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.INFO); + RootLoggerComponentBuilder rootLogger = builder.newRootLogger(level); rootLogger.add(builder.newAppenderRef("Console")); builder.add(appenderBuilder); builder.add(rootLogger);