2 Minutes To Code (β Version)

Log4j - 2 minute tutorial

This is how log4j works

This is how it works. The main objects/configs in the log4j framework that we work with are loggers, appenders, layouts, patterns,and log-levels.

Object/Concept Description
Logger Loggers are objects with given names through which application makes logging calls. Every logger has one or more appender tied to it.
Appender An appender is the destination where logs are recorded, for eg. console, file, db etc.
Layout Alayout is tied to an appender and determines the format of logged messages for eg., plain text, xml format, html format etc.
Pattern A pattern is tied to a layout and determines the fields that are logged in message besides the given message string, for eg. timestamp, class name, method name, line number etc.
Log Level The only other thing that you need to know about log4j to get going is the concept of log-level. See, when you write logs in your app, you can specify the criticality or level of log, say for example ordinary log, important log or critical log . Now you can configure log4j to print logs whichare ordinary or a higher level. So, you can choose at run-time, the verbosity of logs.