Logging frameworks have two major benefits over System.out., i.e. categories and levels. Both allow you to selectively filter logging statements permanently or only for diagnostics time. In this post, we will learn about levels.
The amount and type of information shown in the system and event logs is controlled by the log4j “level” setting in configuration file. Remember, each message on the log is prefixed by the level of the message.
Log4j has following levels of logging.
WARN – It suggest that the application might be continued, but you should take extra caution. The application can tolerate warning messages, but they should always be justified and examined so that they did not prove hidden crackers in application waiting to fire.
INFO – Important business process has finished and good news is “as expected”. In real time, system administrators will watch the info logs to ensure what’s happening on system right now, and if there is any problem in normal flow.
DEBUG – You can use them a lot for debugging the application at development time. Each and every log message will come to log files once this level is set. It basically belongs to developers.
ERROR – It shouts at you that something had gone terribly wrong, and you must investigate immediately. It simply means that your application has met really undesired state. For example database unavailability or unexpected formatted input etc.
FATAL – You will not feel their presence very much in normal day, but once they appear, it signals very bad news, even the application death.
ALL – This level is used to turn on all levels of logging. Once this is configured and the levels are not considered at all. All appenders will start pouring the log events in log files.
OFF – Simple enough. NO LOGGING !!
TRACE – This has been recently introduced in version 1.2 and adds more information to debug level logs.
- When a logger appender is created with certain level, it outputs all those log events equal to its level and also all greater levels than it.
- Log4j’s root logger by default has DEBUG level.
- You can have your own custom levels also. We will learn about them sometime in future.
Happy Learning !!