Showing posts with label Log4j logger. Show all posts
Showing posts with label Log4j logger. Show all posts

Friday, January 7, 2011

Log4j Implmentation with an example.

Article discusses the following
-------------------------------------------------


What is Log4j.
Example Implementation 
About Log level , appender, Layout in Log4j

Log4j is an OpenSource logging API developed under the Jakarta Apache project.Log4j allows developers to insert log statements in their code and configure them externally.

Logically, log4j can be viewed as being comprised of three main components: logger, appender, and layout namely. The functionalities of each of these components are accessible through Java classes of the same name. Users can extend these basic classes to create their own loggers, appenders, and layouts. 

You can download the current version of log4j from the project home page.
http://logging.apache.org/log4j/

Log4j can be configured with two ways : log4j.properties(tradtional way)  , Log4j.xml( More and more applications are adopting to this now).

Log4j.properties example
-------------------------
--------

  • Create a Java project.
  • Add the log4j.jar to the build path of the project.
  • Create a file named log4j.properties in the src folder with the following content.
          ### direct log messages to stdout ###
          log4j.appender.stdout=org.apache.log4j.ConsoleAppender
         log4j.appender.stdout.Target=System.out
        log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
        log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
        log4j.rootLogger=debug, stdout

------  click below to read More ( no need to click in case of a full page view) ---

subversion video