17 May 2013 06:44
Programmatically setting log4j2 log level
Eric Scheie <efaces <at> gmail.com>
2013-05-17 04:44:40 GMT
2013-05-17 04:44:40 GMT
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.
ROOT_LOGGER_NAME)).setLevel(Level.XXXXX);
And when I call:
((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogManager.
ROOT_LOGGER_NAME)).getLevel()
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">
<appenders>
<Console name="Console" target="SYSTEM_OUT">
(Continue reading)
Remko
Sent from my iPhone
On 2013/04/30, at 14:40, Imesh Damith <imesh <at> rezgateway.com> wrote:
> Hi Remko,
>
> Sorry, I do not have access to your JIRA. (User name pwd).
>
> Here with I have attached relevant files. My whole program needs to configure but within these classes you
should be able to understand.
>
>
> client code (Logs_test.java class) send the debug log and TCPServer_test.java class receive it.
>
> But there is an error catching in line 111 ( class not found).
>
>
>
> Let me know if I miss any jar file. My pom.xml file also attached.
>
>
RSS Feed