0
votes

Hi I have recently migrated the logging from log4j to log4j2 in my spring project.

Everything is working fine as expected but I wish to know how I can set the properties <SizedBasedTriggeringPolicy size="10MB" /> and <DefaultRolloverPolicy max="80" /> in my log4j2 config file by directly picking up the value from the given system argument for Rolling File Appender.

In log4j I used to use <param name="MaxFileSize" value="10MB" /> and <param name="MaxBackupIndex" value="80" /> in my RollingFileAppender default configuration and could override the parameter value by passing myAppenderLoggerName.MaxBackupIndex = my-value and myAppenderLoggerName.MaxFileSize = my-value as system properties args.

I'm aware I can use $(sys:my-parameter-name:-default-value) in log4j2 for substitution but is there a direct approach through which I can override the parameter by referencing it's property name directly in log4j2 like it was there is log4j like say myAppender.paramterNameForRolloverSizeInLog4j2 = my-value ?

1

1 Answers

0
votes

No, Log4j2 doesn't automatically associate every attribute with a system property.

I'm not sure why you would want to either as that would be quite cumbersome. For example, to set the max file size you would need

-DmyAppender.policies.sizeBasedTriggeringPolicy.max=10MB

How is that better? But if you really want that you are free to do

<property name="myAppenderMax">${sys:myAppender.policies.sizeBasedTriggeringPolicy.max:=10MB}</property>

and then specify ${myAppenderMax} as the value in the appender configuration.