0

Mine is a spring boot application and I am using log4j2 for logging. log4j-spring.xml is the config file.

I need to change log level for an appender programatically. Am able to do it in code using Configurator.setLevel(). The question is how to persist the change in log4j-spring.xml itself? Do I have to parse XML file to make this change or is there a better way?

Seema Kadavan
  • 2,538
  • 1
  • 16
  • 31
  • Maybe this helps you: https://stackoverflow.com/questions/28216310/reload-log4j2-configuration-on-demand ? – Markus Jun 06 '18 at 17:28
  • I don't think dynamically changing the actual xml file is possible out of the box. Unless you decide to take it into your own hands. But its always possible to programmatically change the logging configuration. There are also rest apis "/loggers/..." that comes with actuator dependency (starting from spring 1.5.1) which can be used to change logging configuration on demand. Another thing to note is, a manual change in the xml itself will be monitored and a reconfiguration of the logging context would be triggered. – ameenhere Jun 07 '18 at 08:27

0 Answers0