black666
black666

Reputation: 3027

Different log levels for webapp in development / test / production stage

Our webapp has a lot of DEBUG and INFO log statments which is obviously great for development. Once we deploy the .war file to the test / production servers, the log4j.properties also gets deployed which results in a lot of DEBUG and INFO statements in the log files.

What would be the best practice if we want see the DEBUG log level only on development machines, INFO on the test servers and WARN on the production servers? Is there a global tomcat configuration where I can set a log level which overwrites the individual logging settings for each webapp? Or is maven and replacing the log4j.properites file on build time the way to go?

Upvotes: 0

Views: 1340

Answers (1)

revdrjrr
revdrjrr

Reputation: 1045

I prefer to have the app be 'aware' of which environment it's in. That could be a feature of the framework you're using, your app's build, or can be accomplished by passing an environment variable to it as a JVM arg and then when you're initializing your logger, you can have it inspect that argument. The specific implementation details depend on what, if any, framework your webapp uses, what type of logger you're using, etc. A benefit of using something like passing an argument to the JVM is that you can have more than just your logger key off what environment the app is in, and you don't have to worry about building (and testing) different packages for each environment.

Upvotes: 2

Related Questions