log4j:
- Using the log4j as a standard approach to logging .
- Logging defined as "A record,as of the performance of a machine or the progress of an undertaking.
Topics in log4j:
- The value of logging
- Approaches to logging-tracing
- Java Specification Request 47
- Log4J Background
- Log4J Configuration
- Using Log47
The value of logging:
Do programmers use debuggers or Loggers?- Logging is often faster than using a debugger.
- Logging can be used to diagnose problems in the field.
- Debugging is difficult in a distributed computing environment.
Logging Activities:
- Tracing
- Debugging
- Error Handling
- Logging
Types of information logged:
- Program flow
- Detailed information about what occurs in a method at a granular level
- Information about a specific error that occurred in the system
- Document historical business events that have occurred
Approaches to logging:
System.out.println
- poor performance
- All or none
- example below
class foo{
public staticfinal boolean debug=true;
public void test(){
if(debug)
System.out.println("i exist only in a test environment");
}
}
Custom log api
- More code to maintain
- Classic build vs buy (or use) decision
Java Specification Request 47:
- Enable/disable logging at run time.
- control logging at a fairly fine granularity.
-Disable logging for specific functionality.
- Bridge services that connect the logging APIs to existing logging services(Operating System Logs,Third party logs).
Basic usage example:
class Foo{
category log=null;
public Foo(){
log=Category.getinstance(getclass());
log.info("Constructing foo");
}
public String doStuff(Long x){
log.debug("debug stuff");
}
}
class Foo{
category log=null;
public Foo(){
log=Category.getinstance(getclass());
log.info("Constructing foo");
}
public String doStuff(Long x){
log.debug("debug stuff");
}
}
No comments:
Post a Comment
If you Like my blog Spread it and help friends for whom this blog is useful for their career.