1

We have multiple spring mvc applications(war) deployed to weblogic 12c. Each was has dependency to one or two application lib(jar) packaged with it. What we want to do is, create application(war) specific log file and configure it to rotate based on some size and archive it old logs file to some folder.

How it can be achieved in log4j2?

user509755
  • 2,941
  • 10
  • 48
  • 82

1 Answers1

0

Create separate log4j2.xml configuration files for each web application, each with different target log files. Put the log4j2.xml configuration file in the WAR classpath: under WEB-INF/classes.

Start your log4j2.xml configuration with <Configuration status="trace" so that log4j2 internal status logs are printed to the console to help troubleshoot any issues.

For more details see https://logging.apache.org/log4j/2.x/manual/webapp.html and https://logging.apache.org/log4j/2.x/manual/logsep.html

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
  • Thank you Renko. I have been following this design. Now my another requirement is that, have only once log4j2 config and that should be out side the war, so we can change log level on demand. We have about 10-12 war files and managing those 10-12 separately would be a big maintenace issue. I think I want to use Context Selectors, but could not find proper tutorial about it. Also not sure how it would work with weblogic 12c server – user509755 Jun 28 '16 at 11:45
  • Do you need to increase the log level for all web applications simultaneously? – Remko Popma Jun 28 '16 at 11:51
  • Not all together, but we have set of web app for which we might need to increase it to debug level since they are related and would like to follow requests from one to another. – user509755 Jun 28 '16 at 11:55
  • My advice would be to have separate log4j2.xml configuration files per web app. However, the config file doesn't _have_ to be bundled inside the WAR. You can specify the configuration file location in the web.xml, so you can put all log config files in a single directory for easy maintenance. See https://logging.apache.org/log4j/2.x/manual/webapp.html – Remko Popma Jun 28 '16 at 12:00
  • Sure. Thank you for your advice. I would try to recommend this approach to my srs. I appreciate your help – user509755 Jun 28 '16 at 12:01