Added level log4j2 configuration.

This commit is contained in:
Christian P. MOMON 2022-01-04 14:20:09 +01:00
parent 65354e89cc
commit 407f22692b

View file

@ -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<BuiltConfiguration> 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);