log4j log Output mode profile Log4j.properties usage Personal Insights

Source: Internet
Author: User
Tags time interval log4j

Log level Size: DEBUG < INFO < WARN < ERROR < FATAL

1, the use of Log4j.rootlogger

#log4j. Rootlogger is configured with an output #log4j that is greater than or equal to the current level of log information. Rootlogger Usage: (note appendername can be one or more) #log4j. Rootlogger = Log level,                            Appendername1,appendername2,.... #log4j. appender.appendername1 defines the output of the log in two ways: one is command line output or console output, and the other is file mode save # 1) The console output should be configured as Org.apache.log4j.PatternLayout # 2) text save should be configured as Org.apache.log4j.DailyR Ollingfileappender # 3) You can also customize the Appender class #log4j. Appender.appenderName1.layout.ConversionPattern The format of the log content is defined #log4j. appender.appenderName1.file defines the file name #log4j for the log file. Appender.appenderName1.DatePattern
Defines the time interval for log file rebuilds and, if set to days, regenerates a new log file daily. # The old log file is saved with a new file name = Log4j.appender.appenderName1.file + log4j.appender.append 
Ername1.datepattern Log4j.rootlogger = Info,stdout,file Log4j.appender.stdout=org.apache.log4j.consoleappender Log4j.appender.stdout.layout=org.apache.log4j.patternlayout log4j.appender.stdout.layout.conversionpattern=[%p] [%d{yyyy-mm-dd HH:mm:ss}] [%c{1}:%l] -%m%n Log4j.appender.file = Org.apache.log4j.DailyRollingFileAppender log4j.appender.file.file=d\:\\log\\info (+). Log log4j.appender.file.datepattern= '. '
YYYY-MM-DD Log4j.appender.file.layout=org.apache.log4j.patternlayout
 LOG4J.APPENDER.FILE.LAYOUT.CONVERSIONPATTERN=[%P][%D{YYYY-MM-DD Hh:mm:ss}][%c{1}:%l]-%m%n


The above code, the information, WARN, ERROR, FATAL these four levels of log messages in the console print out, and as a file saved to D:\log\info (+). Log

2. Log4j.logger usage is as follows

# 1) log4j.logger. Package name = Log level, appendername1,appendername2,.... # defines the log output of all classes in the name of the package # 2) Log4j.logger. class full name with package name = Log level, appendername1,appendername2,.... # defines the log output of the specified class # 3) log4j.log Ger. Log Object logger named name = Log level, appendername1,appendername2,.... # defines the output of a log for a named name, such as: # log4j . Logger. Log1 refers to the log output that defines the log object that is obtained through Logger.getlogger ("Log1") #以log4j. Logger. Package name for example Log4j.logger.edu.service.impl = Error,service _stdout,service_logfile Log4j.appender.service_stdout=org.apache.log4j.consoleappender Log4j.appender.service_ Stdout.layout=org.apache.log4j.patternlayout log4j.appender.service_stdout.layout.conversionpattern=[%p][%d{
YYYY-MM-DD hh:mm:ss}][%c{1}:%l]-%m%n log4j.appender.service_logfile = Org.apache.log4j.DailyRollingFileAppender Log4j.appender.service_logfile.file=d:\\log\\service.log Log4j.appender.service_logfile. Datepattern= '. ' YYYY-MM-DD Log4j.appender.service_logfile.layout=org.apache.log4j.patteRnlayout log4j.appender.service_logfile.layout.conversionpattern=[%p][%d{yyyy-mm-dd HH:mm:ss}][%C{1}:%L]-%m%n
 

Package Edu.service.impl;

Import Java.io.File;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
Import Java.io.InputStream;
Import Java.util.Iterator;
Import java.util.List;

Import Org.apache.commons.lang.RandomStringUtils;
Import Org.apache.log4j.Logger;
Import Org.apache.poi.hssf.usermodel.HSSFRow;
Import Org.apache.poi.hssf.usermodel.HSSFSheet;
Import Org.apache.poi.hssf.usermodel.HSSFWorkbook;

Import Utils. StringUtils;

Import Edu.dao.UserDao;
Import Edu.po.User;
Import Edu.service.UserService;
Import Edu.vo.UserVO;

public class Userserviceimpl implements UserService {
	
	private Logger Logger = Logger.getlogger ( Userserviceimpl.class);

.....

Through the configuration of the above code, the private Logger Logger = Logger.getlogger (Userserviceimpl.class); The error, fatal information for this log object is output and saved to the D:\log\service.log file in the console.


 

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.