I am running an application that logs things using Log4j2. I am configuring the logging programmically using the code below:
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
AppenderComponentBuilder console = builder.newAppender("stdout","Console");
builder.add(console);
FilterComponentBuilder flow = builder.newFilter("MarkerFilter",Filter.Result.ACCEPT,Filter.Result.DENY);
flow.addAttribute("marker","FLOW");
console.add(flow);
LayoutComponentBuilder layout = builder.newLayout("PatternLayout");
standard.addAttribute("pattern","%d [%-6p] %c{1} - %m%n");
console.add(standard);
RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.DEBUG);
rootLogger.add(builder.newAppenderRef("stdout"));
builder.add(rootLogger);
Configurator.initialize(builder.build());
Please note that I am attempting to set a pattern using the addAttribute() method of the LayoutComponentBuilder ("layout" in the code above).
In another class (called MainClass) I am using Lombok's @log4j2 annotation. In that file I am entering the following log entry:
log.info("Application has started!");
When running my application, I would expect the log output to be:
2016-06-20 19:23:48,202 [INFO ] net.factor3.apps.MainClass - Application has started!
Instead, I am seeing:
Application has started!
I do not understand why the pattern I am setting is not being displayed.
Have I found a bug in Log4j2's pattrn API? Or am I missing something that is causing the logger to "ignore" my pattern settings? Someone please advise.