Java Mailing List Archive

Home » Log4J Users List »

Programmatically setting log4j2 log level

Eric Scheie


Replies: Find Java Web Hosting

Author LoginPost Reply
I'm developing a web application and would like to be able to dynamically
change log levels from within my application instead of editing the log4j2
configuration file.  I'm using log4j 2.0 beta5.

I'm currently setting the log level after a form submit using:

((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogManager.

And when I call:

((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogManager.

I get the level that I previously set as expected but I don't see the level
reflected in the logs. For example, when changing the level to DEBUG on
the root logger I do not see debug messages written to the console. If I
change the level of the root logger in my log4j2.xml configuration file I
do see the debug messages written to the console.

Here is my log4j2.xml file.

<?xml version="1.0" encoding="UTF-8"?>

<configuration status="DEBUG" monitorInterval="10">


    <Console name="Console" target="SYSTEM_OUT">

       <PatternLayout pattern="%d %-5p [%t] %X %C{2}.%M(%L) - %m%n"/>




    <root level="INFO">

       <appender-ref ref="Console"/>




Any ideas I how I can change the root logger level after startup
programmtically? I've been searching the web but the only things that come
up are related to log4j 1.2, I haven't found anything applicable to log4j


©2008 - Jax Systems, LLC, U.S.A.