The Log4E logging plug-in - PowerPoint PPT Presentation

About This Presentation
Title:

The Log4E logging plug-in

Description:

Providing an audit trail for a program. Recording soft-errors (lost connections, etc.) for ... A logging framework lets you use different logging levels ... – PowerPoint PPT presentation

Number of Views:73
Avg rating:3.0/5.0
Slides: 11
Provided by: gall80
Learn more at: http://www.gallardo.org
Category:
Tags: log4e | awww | logging | plug

less

Transcript and Presenter's Notes

Title: The Log4E logging plug-in


1
The Log4E logging plug-in
  • David Gallardo

2
What is logging good for?
  • Tracing program execution during development
  • Debugging
  • Providing an audit trail for a program
  • Recording soft-errors (lost connections, etc.)
    for monitoring performance and troubleshooting
  • A logging framework lets you use different
    logging levels
  • You can turn different types of messages on and
    off
  • You can send different types of messages to
    different destinations

3
Adding logging code
  • Replaces System.out.println() calls throughout
  • Dont need to be removed
  • Like adding System.out.println() calls, its
    somewhat tedious to add logging code
  • Utility of logging code is improved if its
    consistentlogs can be searched with scripts, for
    example

4
The Log4E plug-in
  • Provides wizards that automate the addition of
    logging code
  • Add import and declaration for logger
  • Insert logging at start and end of methods
  • Insert logging of variables and method parameters

5
What Log4E doesnt do
  • Log4E does not provide a logging framework
  • Doesnt configure your framework
  • Doesnt make a fresh pot of coffee

6
Choosing a logging framework
  • Log4E supports three logging frameworks
  • Log4J
  • Java 1.4 Logging
  • Jakarta Commons Logging
  • Log4J is the original logging framework that Java
    1.4 logging is modeled after
  • Jakarta Commons Logging is actually a wrapper for
    logging frameworks
  • Well use Log4J in this example because its
    mature, well-documented and supported, and easier
    to configure

7
Installing Log4J
  • Download a zip or compressed tarfile from
    Apache.org website
  • Uncompress to a local directory
  • In your Eclipse projects properties
  • Locate Java Build Path
  • On Libraries page, click on Add External Jars
  • Browse for your Log4J directory, and locate the
    log4J Jar file in the /dist/lib directory
  • Press Open, followed by OK

8
Create a Log4J configuration file
  • The easiest way to configure Log4J is to add a
    log4j.properties file to your source directory.
  • There are many options available which we wont
    cover here, but essentially you need to define
  • A logger
  • An appender
  • A pattern layout
  • The following example uses the default root
    logger, appends to the console and prints the
    date, time, message priority, thread and message

9
A sample log4j.properties file
  • Logger
  • log4j.rootLoggerDEBUG, ConApp
  • Appender
  • log4j.appender.ConApporg.apache.log4j.ConsoleAppe
    nder
  • PatternLayout
  • log4j.appender.ConApp.layoutorg.apache.log4j.Patt
    ernLayout
  • log4j.appender.ConApp.layout.ConversionPatternd
    t -5p c - mn

10
Demo
  • Create a simple Java application
  • Ensure log4j is on class path
  • Use Log4E to add several types of logging
    messages
  • Run program
Write a Comment
User Comments (0)
About PowerShow.com