Java Log log4j

Source: Internet
Author: User

1. Download jar:Log4j-1.2.15.jar

2. Configuration file:log4j.properties

# priorities Are:debug, INFO, WARN, ERROR, or fatal.log4j.rootcategory=INFO,CONSOLE,FILELogs.dir=${catalina.base}/logs/springdemo/logs.filename=logsfilebuffersize=20480#log to Filelog4j.appender.FILE=org.apache.log4j.dailyrollingfileappenderlog4j.appender.FILE. file=d:/${Number}/10.logslog4j.appender.FILE. Encoding=utf-8log4j.appender.FILE. Append=truelog4j.appender.FILE. Locationinfo=truelog4j.appender.FILE. Datepattern= '. ' Yyyy-mm-dd '. Log ' Log4j.appender.FILE. Layout=org.apache.log4j.patternlayoutlog4j.appender.FILE. layout. CONVERSIONPATTERN=[%D]:%m%x%nlog4j.appender.FILE. buffersize=${filebuffersize}# CONSOLE is set to be a consoleappender using a PatternLayout.log4j.appender.CONSOLE=org.apache.log4j.consoleappenderlog4j.appender.CONSOLE. Threshold=debuglog4j.appender.CONSOLE. Layout=org.apache.log4j.patternlayoutlog4j.appender.CONSOLE. layout. conversionpattern=-%m%n

3.java class:

 Packagecom.log.test;ImportJava.text.SimpleDateFormat;Importjava.util.Date;ImportOrg.apache.log4j.Logger;ImportOrg.apache.log4j.PropertyConfigurator; Public classDemotest {StaticLogger Logger = Logger.getlogger (demotest.class. GetName ());  Public Static voidMain (string[] args)throwsException {//format Time Month DaySimpleDateFormat data =NewSimpleDateFormat ("YYYYMMdd"); String format = Data.format (NewDate ()); //Dynamic Configuration PathSystem.setproperty (" Number", format); //Create a folder by date //Load configuration filePropertyconfigurator.configure ("config/log4j.properties"); //path of the configuration file //Output Log InformationLogger.debug ("Hellosdsdwoasdassdasdasdfdsfrld"); }}

Java Log log4j

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.