This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Other Open Source Projects and the fly likes Log4J properties in Production Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Log4J properties in Production" Watch "Log4J properties in Production" New topic

Log4J properties in Production

Jayakumar A Gopalan

Joined: Jul 16, 2005
Posts: 1

I am planning to use Log4J in our applicationi. I tried searching the web regarding the following questions, but didnt get anything useful:

1) How do I specify different log4j properties for Production (I cant use System properties)
2) Is there any way dynamically I can update the logging level (without modifying the properties file or restarting the application/server)

Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
you can create a log4j properties file with the values that need to have it for production and then can deploy ur application.
As of setting different logging levels,your code can use any of the logging levels like Debug,Info,Warn,Error,Fatal.
But can reduce the logs on the production,by setting the desired log level in the log4j properties file.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41599
You can set the log level dynamically by calling Logger.getRoot().setLevel(...).

Ping & DNS - my free Android networking tools app
krishnakumar K R

Joined: Oct 27, 2005
Posts: 12

Is there any way to update this in the configuration file as well??

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41599
Sure. If your logger is named STD_LOG you write:

log4j.rootLogger=WARN, STD_LOG
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

You can also control the configuration via system properties. The explanation of how to do that is hidden in the API documentation for PropertyConfigurator:

All option values admit variable substitution. The syntax of variable substitution is similar to that of Unix shells. The string between an opening "${" and closing "}" is interpreted as a key. The value of the substituted variable can be defined as a system property or in the configuration file itself. The value of the key is first searched in the system properties, and if not found there, it is then searched in the configuration file being parsed. The corresponding value replaces the ${variableName} sequence. For example, if java.home system property is set to /home/xyz, then every occurrence of the sequence ${java.home} will be interpreted as /home/xyz.
Consider Paul's rocket mass heater.
subject: Log4J properties in Production