How to configure log4j to log different log levels to different files for the same logger

What you need to do is have a single <logger> definition with a defined level of INFO, but in your two appender definitions, you set their thresholds accordingly, e.g. <appender name=”ERROR_FILE”> <param name=”Threshold” value=”ERROR”/> </appender> <appender name=”GENERAL”> <param name=”Threshold” value=”INFO”/> </appender> You then add both appenders to your logger: <logger name=”com.acme”> <level value=”INFO”/> <appender-ref ref=”ERROR_FILE”/> … Read more

How to delete old logs with log4j2

Since 2.5, Log4j supports a custom Delete action that is executed on every rollover. You can control which files are deleted by any combination of: Name (matching a glob or a regex) Age (“delete if 14 days old or older”) Count (“keep only the most recent 3”) Size (“keep only the most recent files up … Read more

Migrating from log4j to log4j2 – properties file configuration

Here is what I constructed after going through the documentation and worked. rootLogger.level = INFO property.filename = trace.log appenders = R, console appender.console.type = Console appender.console.name = STDOUT appender.console.layout.type = PatternLayout appender.console.layout.pattern = %d %5p [%t] (%F:%L) – %m%n appender.R.type = RollingFile appender.R.name = File appender.R.fileName = ${filename} appender.R.filePattern = ${filename}.%d{yyyy-MM-dd} appender.R.layout.type = PatternLayout appender.R.layout.pattern … Read more

How to give environmental variable path for file appender in configuration file in log4j

When parsing its configuration file, the expression ${MY_HOME} will be expanded to the value of the system property named MY_HOME, not the system environment variable. There’s a difference between the two. To achieve this in a clean way, you’ll have to add something like this to the JVM invocation line: -DMY_HOME=$MY_HOME That would define the … Read more