LOG4J Program encountered error printing log to file

Source: Internet
Author: User

Log4j.properties:

# define the DEBUG priority, R for the purpose of the log output

Log4j.rootlogger= DEBUG, R

# Set the log output type to file type

Log4j.appender.r= Org.apache.log4j.FileAppender

# Set the location of the log files

Log4j.appender.r.file=. /visitemanage/logs/logrecord.log

# each time a new log message is written at the end of the file

log4j.appender.r.append= true

# Log Output Information format type

log4j.appender.r.layout= Org.apache.log4j.PatternLayout

# The log output Information format is newline, date, priority, [Full-class name], log information, line break

Log4j.appender.r.layout.conversionpattern=%n%d%p [%l]%m%n

Test code:

Package com.zhongren.Test;
Import Org.apache.log4j.Logger;

public class Test {
public static void Main (string[] args) {
Logger Logger = Logger.getlogger (Test.class.getName ());//Get logger, this logger will be responsible for controlling log information
try {
int i=10/0;
} catch (Exception e) {
Logger.info (E.getmessage ());//output log information using the Debug, info method of the Logger object
}
}
}

Test results:

Log4j program encountered error printing log to file

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.