The following blog is a simple insight into a very helpful and widely used framework for logging purpose.
Bingo !!! You are right – Log4j
Log4j is designed to be highly configurable using simple configuration files at runtime. Using its main components viz. Loggers,appenders and layouts it provides a very extensive logging process in quiet many aspects like levels of priorities,logging destinations (console,database, file…) etc.
What are the responsibilities of these core objects?
Well the names of the objects actually give you a very intuitive definition itself –
- Loggers are responsible for capturing logging information.
- Appenders are responsible for publishing logging information to specific destinations.
- Layouts are responsible to format the information or data being logged.
Well these so called “CORE” objects are mandatory.
There are a set of non-mandatory/optional objects as well –
The supporting objects, which support the core objects in performing additional tasks (Still important though) viz. Level,Filter,Objectrenderer and Logmanager.
Anyone who has ever used this framework immediately identifies the term – LEVEL ( And now you understand the importance of a Support object 🙂 )
- The Level object defines the granularity and priority of any logging information. There are seven levels of logging defined within the api – OFF, DEBUG, INFO, ERROR, WARN, FATAL, and ALL(with priority in the specified order).
- The Filter object is used to analyze logging information and make further decisions on whether that information should be logged or not. The filter object along with Appender helps in filtering logging information before it can be published to the desired destination. An Appender object can have several Filter objects associated with them. Needless to say that all the Filter objects associated with that Appender need to approve the logging data to finally allow the data to reach its destination (Ya… We are talking about your log files/db/console/UNIX Syslog).
- The ObjectRenderer object (as the name suggests) is specialized in providing a String representation of different objects passed to the logging framework.
- The LogManager object manages the logging framework. It is responsible for reading the initial configuration parameters from a configuration file or a configuration class.
I will add more on the settings in my upcoming blogs. Happy Coding !!!!