Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Log4j levels  RSS feed

Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the correct log4j level to use in a web application for the following circumstances.

1) In authentication user gives wrong password ( Can i use DEBUG for it?)
2) User profile is updated successfully ( INFO?)
3) Connection pool is depleted ( DEBUG?)
4) DB Failure ( FATAL?)
When should I use error level. If I catch any exception can I use it? Or only for critical exception should I use it?

In production if DEBUG is swithched off what is the use of using that level?

Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to decide theses things.

Because DEBUG is shut off during production, I use that the most.
Everything that goes on in my app gets logged to debug mode. Full stack traces get printed instead of just messages. All the arguments to core methods get printed.
This way, when something is going wrong, I can change the log levels for the classes, package, or entire app to DEBUG and tail the logs to see where it is failing, in detail.

Once I find the problem, I can turn the level back down to keep the logs from growing like crazy.

I don't make much use of INFO and WARN because I like the logs to be fairly quiet when there isn't a problem. A quick message when the app starts up and shuts down is about all I use INFO for.

If an action is supposed to send out an email, in addition to what it normally does but there is no email address on file or the SMTP server rejects the address on file, I'll use WARN for that because the actual operation worked; it just couldn't send the email.

Another good use of WARN would be for logging suspicious activity.
If you have filters or validation routines that strip out HTML characters or SQL commands from user input fields, you might want to log the user, IP, data/time, and the characters in question under WARN each time those things show up.

Your mileage may vary.

You can also set up multiple appenders to have different logs for different things. Your choice of levels for one file might be different than the levels on another.

It really is up to you.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!