0

This may be a stupid question, but since it came to my mind, I am asking to see if this makes any sense.

  • I have a project that runs on customer's machine.
  • It is started via command-line and creates log inside a logs folder. The logging levels are set inside log4j.xml. The current statements I see are INFO, DEBUG and ERROR.

Requirement
- I am working on a feature where I am introducing TRACE option.
- I do not want to log these statements by default (just log at the level of DEBUG).
- But in case of any issues, I want to enable the TRACE level (via some environment variable, system property) that my running application can pick and start logging the TRACE statements as well

How can I achieve this?

daydreamer
  • 87,243
  • 191
  • 450
  • 722
  • Take a look at a previous [question](http://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/config/LoggerConfig.html) already answered. – feanor07 Aug 13 '16 at 23:41
  • *"via some environment variable"*? You can't change environment variable *while application is running*, so that won't work. And although you can change a system property while application is running, it's be better to just update the logging configuration directly. – Andreas Aug 13 '16 at 23:59
  • If your configuration is defined in `log4j.xml`, why did you tag `logback` and `slf4j`? They have nothing to do with Log4j configuration. – Andreas Aug 14 '16 at 00:01

1 Answers1

0

If it's a web project, a very convenient way is to place this JSP in your WebContent folder.

It will print all the available loggers and you can change the log level simply by clicking.

https://gist.github.com/iamkristian/943918