0

We have migrated a few days back from log4j 1.x to log4j 2.x. But I am unable to migrate log4j.properties to log4j2.properties.

Earlier we had the file named log4j.properties in classpath with the below contents:

log4j.rootLogger = INFO, out, FILE

log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n

log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=logPath/logName.log
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.FILE.MaxFileSize=200MB
log4j.appender.FILE.MaxBackupIndex=20
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n

It used to work perfectly fine. Now I have deleted the file and created a file named log4j2.properties with the below content:

rootLogger = INFO, out, FILE

appender.out.type=Console
appender.out.layout.type=PatternLayout
appender.out.layout.pattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n

appender.FILE.type=RollingFile
appender.FILE.name=RollingFile
appender.FILE.append=true
appender.FILE.fileName=logPath/logName.log
appender.FILE.filePattern='.'yyyy-MM-dd
appender.FILE.policies.type = Policies
appender.FILE.policies.time.type = TimeBasedTriggeringPolicy
appender.FILE.policies.time.interval = 1
appender.FILE.policies.time.modulate = true
appender.FILE.policies.size.type = SizeBasedTriggeringPolicy
appender.FILE.policies.size.size=100MB
appender.FILE.strategy.type = DefaultRolloverStrategy
appender.FILE.strategy.max = 1
appender.FILE.layout.type=PatternLayout
appender.FILE.layout.pattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n

I am trying to achieve the same functionality but it is not logging anything to the log file. Can you please suggest what I am doing wrong? The project is a Spring Boot Project.

James Z
  • 12,209
  • 10
  • 24
  • 44
Anirban
  • 925
  • 4
  • 24
  • 54
  • Have you seen https://stackoverflow.com/questions/35900555/migrating-from-log4j-to-log4j2-properties-file-configuration and https://logging.apache.org/log4j/2.x/manual/migration.html? – Asif A Fasih Jul 27 '22 at 03:06
  • I had seen the manual in apache website but not the stackoverflow answer. Thanks this will help and will get back if I have any more questions – Anirban Jul 27 '22 at 17:50
  • Does this answer your question? [Migrating from log4j to log4j2 - properties file configuration](https://stackoverflow.com/questions/35900555/migrating-from-log4j-to-log4j2-properties-file-configuration) – Asif A Fasih Jul 30 '22 at 02:34

0 Answers0