You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Robert Nicholson <ro...@gmail.com> on 2022/03/03 18:06:00 UTC

Not generating appenderRef in config?

When I validate my config by using configurationBuilder.writeXmlConfiguration(System.out)

I notice most is there but the Loggers don’t have the AppenderRef entries.

Why is that?

When debugging I can see that when I call something like

rootLogger.add(configurationBuilder.newAppenderRef(“appenderName”));

in the debugger under Logger I can see it has a Component with the AppenderRef and the attributes of this ref match the name of the Appender
that appears as an Appender in Appenders off the ConfigurationBuilder.

ie. the Loggers components has both the attribute “ref” -> “appenderName” and the component is a AppenderRef pluginType

Why then does it choose to not include any AppenderRef for the logger in the Xml it’s showing me?

This is what my code looks like

RootLoggerComponentBuilder rootLogger = configurationBuilder.newRootLogger(Level.INFO);
configurationBuilder.add(rootLogger);
configurationBuilder.add(getAppender());
rootLogger.add(configurationBuilder.newAppenderRef(“filelog”));

after this it will show a root logger in the XML with no AppenderRef

Similar for all other subsequent loggers.


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: Not generating appenderRef in config?

Posted by Robert Nicholson <ro...@gmail.com>.
It is looking like my issue was that because I’m adding the rootLogger to the configuration builder prior to adding the newAppenderRef so you cannot think of these as just object references. But rather steps with side affects that have to be performed in the correct order otherwise I guess you hit a terminal state where operations after that have no affect.

> On Mar 3, 2022, at 12:06 PM, Robert Nicholson <ro...@gmail.com> wrote:
> 
> When I validate my config by using configurationBuilder.writeXmlConfiguration(System.out)
> 
> I notice most is there but the Loggers don’t have the AppenderRef entries.
> 
> Why is that?
> 
> When debugging I can see that when I call something like
> 
> rootLogger.add(configurationBuilder.newAppenderRef(“appenderName”));
> 
> in the debugger under Logger I can see it has a Component with the AppenderRef and the attributes of this ref match the name of the Appender
> that appears as an Appender in Appenders off the ConfigurationBuilder.
> 
> ie. the Loggers components has both the attribute “ref” -> “appenderName” and the component is a AppenderRef pluginType
> 
> Why then does it choose to not include any AppenderRef for the logger in the Xml it’s showing me?
> 
> This is what my code looks like
> 
> RootLoggerComponentBuilder rootLogger = configurationBuilder.newRootLogger(Level.INFO);
> configurationBuilder.add(rootLogger);
> configurationBuilder.add(getAppender());
> rootLogger.add(configurationBuilder.newAppenderRef(“filelog”));
> 
> after this it will show a root logger in the XML with no AppenderRef
> 
> Similar for all other subsequent loggers.
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org