0

Please correct me if I'm wrong, but it seems the log4j2.xml must be in the classpath of the program, and everything in the classpath gets packaged up into a .jar file when you make a standalone runnable .jar file of the program.

If that's the case, then the XML file cannot be changed after the program has been exported to the .jar file. Thus, it doesn't seem that there is any way to change the logging level without re-exporting the program.

Please tell me I'm wrong about this and that there is a way that I can change the logging level while the program is running by using, say, a drop-down list in JFrame so that the user can select the logging level.

Sturm
  • 689
  • 2
  • 23
  • 52
  • possible duplicate of [How to turn off log4j warnings?](http://stackoverflow.com/questions/6849887/how-to-turn-off-log4j-warnings) – Stephen P May 23 '14 at 16:49
  • See my comment below to user3669653's answer. – Sturm May 23 '14 at 17:03
  • Actually, doing some more research, I've discovered that this question has already been [asked and answered](http://stackoverflow.com/questions/23434252/programmatically-change-log-level-in-log4j2?rq=1). Thus, this is now a duplicate. My apologies. – Sturm May 23 '14 at 17:49

2 Answers2

1

You can change the logger level by using the Java Management Extensions Bean (JMX Bean) included in the library:

  1. Enable the JMX port in your application start up:

    -Dcom.sun.management.jmxremote.port=[port_num]

  2. Use any of the available JMX clients (the JVM provides one in JAVA_HOME/bin/jconsole.exe) while executing your application.

  3. In JConsole look for the "org.apache.logging.log4j2.Loggers" bean

  4. Change the level of your logger

The thing that I like most of this is that you don´t have to modify your code or configuration for managing this. It´s all external and transparent.

More info: http://logging.apache.org/log4j/2.x/manual/jmx.html

Victor
  • 2,450
  • 2
  • 23
  • 54
0

I've used this in the past

LogManager.getRootLogger().setLevel(Level.DEBUG);

You can change to any of the log levels that way.

user3669653
  • 354
  • 1
  • 8
  • 15
  • 1
    Nope, that's for previous versions of log4j. I'm running log4j2 (rc1). There is no `setLevel` method for the logger object. At least, none that I can find. – Sturm May 23 '14 at 17:02