1

I have updated the logging jars from log4j1 to log4j2.17. However I am not able to convert my log4j.properties file into log4j2..properties file. Below is my log4j.properties file

log4j.loggerFactory=com.test.control.log.MyLoggerFactory

log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.Threshold = ERROR
log4j.appender.STDOUT.layout = org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern = [%d] %-5p [%t] %C %M - %m%n

log4j.rootLogger=DEBUG,STDOUT
log4j.rootLogger=ERROR,CUSTOM
log4j.logger.com.test = CUSTOM
log4j.appender.MY_APP_APPENDER = org.apache.log4j.RollingFileAppender
log4j.appender.MY_APP_APPENDER.Threshold = CUSTOM#com.test.control.log.LogLevel
log4j.appender.MY_APP_APPENDER.layout = org.apache.log4j.PatternLayout
log4j.appender.MY_APP_APPENDER.layout.ConversionPattern = [%d] %-5p [%t] %C %m%n
log4j.appender.MY_APP_APPENDER.File = myApp.log
log4j.appender.MY_APP_APPENDER.append = true

I need to migrate from log4j to log4j2 and I need to change properties file as above. Maybe somebody can help me to understand how would be log4j2.properties look like.

Pradeep Kumar
  • 63
  • 1
  • 4
  • 3
    I suggest you read: https://stackoverflow.com/questions/35900555. One important take-away from that Q&A is that you need to read the documentation. Reading the documentation is the first step to understanding what your properties will need to look like. – Stephen C Jan 15 '22 at 07:05
  • You can also use the [`Log4j1ConfigurationConverter`](https://logging.apache.org/log4j/2.x/log4j-1.2-api/apidocs/org/apache/log4j/config/Log4j1ConfigurationConverter.html) included in `log4j-1.2-api`. BTW: there are errors in your configuration, like the double `log4j.rootLogger` key. – Piotr P. Karwasz Jan 15 '22 at 08:54
  • @PiotrP.Karwasz,thanks for pointing double log4j.rootLogger. – Pradeep Kumar Jan 15 '22 at 09:03
  • @PiotrP.Karwasz, i am working in legacy application there we migrating log4j1.x to log4j-2.17. In application we are using some custom log level(let say-custom). for this we want print all the higher level the like .. warn, error,and Fatal include custom. when i given the threshold value to Custom, logs is not printing. is there any configuration we missing? any help is appreciated. – Pradeep Kumar Jan 15 '22 at 09:14

0 Answers0