log4j Log configuration file log4j.properties

Source: Internet
Author: User
Tags log4j

# Specify level of log output, Destination: console, file
#  log output priority by root element: Debug < Info < Warn < error
Log4j.rootlogger=info,console, File
 
############# log output to console #############
# Log output to the console using the API class
log4j.appender.console= Org.apache.log4j.ConsoleAppender
# Specifies the format of the log output: Flexible format
log4j.appender.console.layout=org.apache.log4j.patternlayout
# Concrete format content%d: Date   %p: Time   %c: Priority   %M: Method  %m%n: Printed information  
log4j.appender.console.layout.conversionpattern=%d%p%c.%m ()-%m%n
 
 
############# log output to file #############
log4j.appender.file=org.apache.log4j.rollingfileappender
# File parameters: Specify the log file path
log4j.appender.file.file=. /logs/mylog.log
# File parameter: Specify maximum log file size
log4j.appender.file.maxfilesize=5kb
# file parameter: Specifies the maximum number
of log files generated log4j.appender.file.maxbackupindex=100
# log format
log4j.appender.file.layout= Org.apache.log4j.PatternLayout
log4j.appender.file.layout.conversionpattern=%d%c.%m ()-%m%n


code example

public class MyLog {
	 Logger log = Logger.getlogger (Test.class);
	@Test Public
	Void Demo () {
		try {
			log.info ("Logic code Start");
			int i = 1/0;
			Log.info ("Logical Code End");
		} catch (Exception e) {
			e.printstacktrace ();
			Log.error ("error message", E);}}}
Output display



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.