Log4j configuration file details

Source: Internet
Author: User

Basic information:
-------------
Log4j-1.2.9.jar
 

Configuration process:
------------
1) Load log4j-1.2.9.jar
2) Configure log4j. properties in the root path. refer to the following log4j configuration code.
3) Add the following logging code to the Java file, JSP, or servlet for logging.

Others:
-----------
1. log4j. jar: http://www.apache.org/dist/jakarta/log4j/jakarta-log4j-1.2.8.zip
2. log4e. jar: http://log4e.jayefem.de/index.php/Download
Note: log4e is the log4j plug-in of eclipse. After adding the plug-in to the folder, restart eclipse and right-click the program to view the log4e option.

 


Log4j. Properties
======================
======================
Log4j. rootlogger = debug, A1, R
# Rollingfileappender
Log4j. appender. A1 = org. Apache. log4j. rollingfileappender
Log4j. appender. a1.file = C: SYS. Log
Log4j. appender. a1.maxfilesize = 100kb
Log4j. appender. a1.maxbackupindex = 1
Log4j. appender. a1.layout = org. Apache. log4j. patternlayout
Log4j. appender. a1.layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N
# Backup
Log4j. appender. r = org. Apache. log4j. rollingfileappender
Log4j. appender. R. File = log4j. Log
Log4j. appender. R. maxfilesize = 100kb
Log4j. appender. R. maxbackupindex = 1
Log4j. appender. R. layout = org. Apache. log4j. ttcclayout


# Leleappender
Log4j. appender. b1 = org. Apache. log4j. leleappender
Log4j. appender. b1.layout = org. Apache. log4j. patternlayout
Log4j. appender. b1.layout. conversionpattern = %-4r %-5 p [% T] % 37C % 3x-% m % N
Log4j. appender. b1.layout. conversionpattern = % 5 p [% T] (% F: % L)-% m % N


Mylogtest. Java
======================
======================
Import java. util. locale;
Import java. util. resourcebundle;
Import org. Apache. log4j .*;

Public class mylogtest {
Static logger = logger. getlogger (mylogtest. Class. getname ());
 
Public static void main (string [] ARGs ){
Logger. setresourcebundle (resourcebundle. getbundle ("log4j", locale. simplified_chinese); mylogtest.logger.info ("test info starts ");
Mylogtest.logger.info ("test information ended ");
Try {
Integer. parseint ("");
} Catch (exception e ){
Logger. Error (E );
}
}
}

 

 

 

MATERIALS:
========================================================== ========================================================== ==================
========================================================== ========================================================== ====================

Example of the log4j. properties File

1. ========================================================== ======================================
This file is the focus of this article, that is, the log4j configuration file.

# Set root logger level to debug and its only appender to A1
# Log4j has five levels of logger
# Fatal 0
# Error 3
# Warn 4
# INFO 6
# Debug 7
# Configure the root logger with the Syntax:
# Log4j. rootlogger = [level], appendername, appendername ,...
Log4j. rootlogger = info, A1, R
# This sentence indicates that all logs are output.
# If it is log4j. rootlogger = warn, it means only warn, error, fatal
# Output. debug and info will be blocked.
# A1 is set to be a consoleappender.
# The appender in log4j has several layers, such as the console, files, Gui components, and even an interface server, NT event recorder, and Unix Syslog daemon.
# Leleappender output to the console
Log4j. appender. A1 = org. Apache. log4j. leleappender
# Output layout used by a1. log4j provides four layout S: org. Apache. log4j. htmllayout (layout in HTML form)
# Org. Apache. log4j. patternlayout (you can flexibly specify the layout mode ),
# Org. Apache. log4j. simplelayout (including the log information level and information string ),
# Org. Apache. log4j. ttcclayout (including the log generation time, thread, category, and other information)

Log4j. appender. a1.layout = org. Apache. log4j. patternlayout
# Flexibly define the output format. For details, see log4j javadoc org. Apache. log4j. patternlayout.
# D time ....
Log4j. appender. a1.layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N
# R extension output to file rollingfileappender, which can provide a log backup function.
Log4j. appender. r = org. Apache. log4j. rollingfileappender
# Log File Name
Log4j. appender. R. File = log4j. Log
# Log File Size
Log4j. appender. R. maxfilesize = 100kb
# Saving a backup file
Log4j. appender. R. maxbackupindex = 1

Log4j. appender. R. layout = org. Apache. log4j. ttcclayout
# Log4j. appender. R. layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS} [% C]-[% P] % m % N


2. ========================================================== ========================================================== ============
Next, I will provide a configuration process for using log4j in weblogic. First, I will provide the complete information of this configuration file.

# Log4j. rootlogger = info, A1, r // specifies the log output level as info. A1 and R indicate the log output location respectively.
Log4j. Category. hybl_wshabcm = debug, A1, r // specifies the package information of the log output and the output location.
Log4j. appender. A1 = org. Apache. log4j. leleappender // The first location of log output is specified here. A1 is the consoleappender of the console.
/*
* Log4j provides the following types of appender:
* Org. Apache. log4j. leleappender (console ),
* Org. Apache. log4j. fileappender (file ),
* Org. Apache. log4j. dailyrollingfileappender (a log file is generated every day ),
* Org. Apache. log4j. rollingfileappender (a new file is generated when the file size reaches the specified size ),
* Org. Apache. log4j. writerappender (send log information to any specified place in stream format)
*
*/
Log4j. appender. a1.layout = org. Apache. log4j. patternlayout // specify the layout mode of A1.

/*
* Log4j provides the following layout types:
×Org. Apache. log4j. htmllayout (in HTML table format ),
* Org. Apache. log4j. patternlayout (you can flexibly specify the layout mode ),
* Org. Apache. log4j. simplelayout (containing the log information level and information string ),
* Org. Apache. log4j. ttcclayout (including the log generation time, thread, category, and other information)
*/
Log4j. appender. a1.layout. conversionpattern = %-d {yyyy-mm-dd hh: mm: SS, SSS} [% C]-[% P] % m % N // specify the log output format


Log4j. appender. r = org. Apache. log4j. rollingfileappender // specify the log output as a file
Log4j. appender. R. File = C:/sys.html // File Location
Log4j. appender. R. maxfilesize = 500kb // Maximum File Size
Log4j. appender. R. maxbackupindex = 1 // Number of backups
Log4j. appender. R. layout = org. Apache. log4j. htmllayout // the file format is HTML.
# Log4j. appender. R. layout = org. Apache. log4j. patternlayout
Log4j. appender. r. layout. conversionpattern = % d {yyyy-mm-dd hh: mm: SS, SSS} [% T] [% C] [% P]-% m % N

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.