Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j 2 configuration: appenderRef.xyz.ref?

Tags:

java

log4j

From https://logging.apache.org/log4j/2.x/manual/configuration.html:

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile

   ...

logger.rolling.name = org.apache.logging.log4j.core.appender.rolling
logger.rolling.level = debug
logger.rolling.additivity = false
logger.rolling.appenderRefs = rolling
logger.rolling.appenderRef.rolling.ref = RollingFile

What does the last line do? I get that logger.rolling.appenderRefs = rolling causes the rolling logger to point towards the rolling appender, but I don't understand the last line.

like image 580
Jason S Avatar asked Oct 18 '25 19:10

Jason S


1 Answers

This

logger.rolling.appenderRefs = rolling

first declares a set of appender references by name. Here, it declares one named rolling. This rolling is unrelated to the rolling in

appenders = console, rolling, list

This

logger.rolling.appenderRef.rolling.ref = RollingFile

uses the previously declared name to refer to the appender reference. The .ref then connects that appender reference with the appender named RollingFile.

like image 173
Savior Avatar answered Oct 20 '25 09:10

Savior