log4j migration to log4j2

Not Exactly related to the Question, But the below are my learning in log4j2 migration. hope it helps someone.

Since the log4j vulnerability which was discovered in late 2021,
many organizations have upgraded to log4j2 to overcome it. and many developers needed to understand what exactly is log4j and what is the vulnerability.
I recommend you to read about that, as it was a major vulnerability in software industry.
I also migrated 2 applications to log4j2 and faced many issues in the migration.
hence writing this here. i will write a detailed article on this later but for the time being, if anyone else is migrating to log4j2 from log4j i prefer
reading my below learnings.

  1. This is a major change in the application, so be careful while doing it. it involves a change in almost all the files present.
  2. If you are making a change to a legacy application, you might need to change many other supported jars, hence understand that it’s gonna take time.
  3. If there is a log4j.properties file, convert it to log4j.xml ,it might feel hard to convert but trust me you wont find much docs on properties file.
  4. A REPLACE ALL method wont always work, double check your work.
  5. There will be transitive dependencies, try to understand that and exclude them in pom.
  6. If you are changing versions of spring or any other framework, understand that there were many changes done in the new versions, refer docs.

documentation for migrating from Log4j to Log4j2:
https://logging.apache.org/log4j/2.x/manual/migration.html#Log4j2ConfigurationFormat

Some sites that helped me:
https://stackify.com/log4j2-java/
https://www.digitalocean.com/community/tutorials/log4j2-example-tutorial-configuration-levels-appenders
https://howtodoinjava.com/log4j2/log4j2-consoleappender-example/
https://access.redhat.com/solutions/4347841

Leave a Comment