Apache common logs and log4j logs
1. Three purposes of the log
A. Monitoring the variables in your code the synchronization of the data is recorded in the file for other system analysis.
B. Tracking code run track, to do after the basis of audit
C. Acting as a debugger in the development environment, output to a file or console
2. Apache provides a common log interface that enables the implementation of the following log implementations for Third-party software common logs:
A. log4j Logger
B. jdk1.4logging
C. simplelog
D. Nooplog
3. Two generic interfaces: Log and Logfactory
In the Eclipse Package Explorer management view, the classes in the Common-logging.jar bundle under the Struts framework:
Two packages: org.apache.commons.logging
Org.apache.commons.logging.impl
Org.apache.commons.logging Log.class Interface
Loglofingurationexception.class
Logfeetoy.class interface
Logsource.class
Package.html
Org.apache.commons.logging.impl Jdk14logger.class
log4j Categorylog.class
Log4factory.class
Log4jogger.class
Logfactoryimpl.class
Logfitlogger.class
Nooplog.class
Simplelog.class
6 levels of common log packs:
Logfactory two static methods
public static Log GetLog (string name) throws by name
Logconfigurationexception;
Public station Log GetLog (class dass) throws by class name
Logconfigurationexceptions
Multiple outputs of log4j: 1. Controller
2. Documents.
3.GUI
4.stocket Interface Server
5.NT Event Recorder
6.Unix Sysleg Daemon Etc Association
Just modify the configuration file.
Set conmmon-logging. Properties
(Special note: An error occurred while upgrading)
Resolved from below
Org.apache.common.logging.log=org.apche.commons.logging.impllog4jlogger
Three important components of log4j:
1. Priority of log information (ERROR.WARN.INFO.DEBUG)
2. The output destination of the log information
3. Output format of log information
LOG4J supports two types of configuration files: xml
Java Property file (key = value)
Log4j.properties Configuration
Htmilayout HTML table
Patternlayout the flexibility to specify layout patterns
Simplelayout contains log information levels and information strings
Ttcclayout contains log generation time, threads, categories, and so on
Similar to printf print format in C language
Print parameters:%m The message specified by the output code
%p Output Priority Debug INFO WARN ERROR FATAL
%r output time in milliseconds to output the log information from the application
The class that the%c output belongs to
%t output The name of the thread that generated the log time
%n output a carriage return line break Windows platform/r/n "UNIX platform"/n/"
%d output point of time, such as%D{YYYMMMDDHH:MM.SS; SSS}
%l output Log information location, class, occurrence of the thread, code location
The call Log log=logfartoty.getlog ("MyTest") in the program;
Log.info ("My Test");
return null
Download log4j 1.2.14 Dist/lib/logging-log4j.jar