• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Log4J properties in Production

 
Jayakumar A Gopalan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set the log level dynamically by calling Logger.getRoot().setLevel(...).
 
krishnakumar K R
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

Regards,
Krish
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure. If your logger is named STD_LOG you write:

log4j.rootLogger=WARN, STD_LOG
 
Paul Clapham
Sheriff
Posts: 21154
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic