wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Log4J properties in Production" Watch "Log4J properties in Production" New topic
Author

Log4J properties in Production

Jayakumar A Gopalan
Greenhorn

Joined: Jul 16, 2005
Posts: 1
Hi,

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)

Thanks,
Jay
Rajendar Goud
Ranch Hand

Joined: Mar 06, 2002
Posts: 220
Hi,
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.


Raj
Ulf Dittmer
Marshal

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


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

Joined: Oct 27, 2005
Posts: 12
Hi,

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

Regards,
Krish
Ulf Dittmer
Marshal

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

log4j.rootLogger=WARN, STD_LOG
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Log4J properties in Production
 
Similar Threads
How not to hard-code file location in java?
FileAppender path -log4j
Hibernate and java.util.Logging
Diabling logging in log4j
log4j XML reading problem