About Log4j.properties Example: Dailyrollingfileappender

Source: Internet
Author: User

  1. Package com.v512.log4j;
  2. Import Org.apache.log4j.Logger;
  3. Public class Hellolog4j {
  4. //Construct a logger, which is the class in which the logger is located, indicating that you want to log in the class
  5. private static Logger Logger = Logger.getlogger (hellolog4j.   Class);
  6. /**  
  7. * @param args
  8. */
  9. public static void Main (string[] args) {
  10. GetMessage ();
  11. }
  12. private static void GetMessage () {
  13. //record various levels of information, where it is stored, and in which way it is configured in the Log4j.properties file.
  14. Logger.debug ("This is debug message.");
  15. Logger.info ("This is a info message.");
  16. Logger.warn ("This is a warn message.");
  17. Logger.error ("This is a error message.");
  18. }
  19. }

[Plain]View PlainCopy
    1. Log4j.rootlogger=info,file
    2. Log4j.appender.file=org.apache.log4j.dailyrollingfileappender
    3. Log4j.appender.file.file=message.log
    4. Log4j.appender.file.layout=org.apache.log4j.patternlayout
    5. LOG4J.APPENDER.FILE.LAYOUT.CONVERSIONPATTERN=%D{YYYYMMDD HH:mm:ss}%p%l [%t]%m%n

[Plain]View PlainCopy
    1. Message.log.2012-07-28
    2. Message.log.2012-07-27
    3. Message.log (today)
    4. 20120729 11:26:58 Info Com.v512.log4j.HelloLog4J.getMessage (hellolog4j.java:18) [main] This is a info message.
    5. 20120729 11:26:59 WARN com.v512.log4j.HelloLog4J.getMessage (hellolog4j.java:19) [main] This is a WARN message.
    6. 20120729 11:26:59 Error Com.v512.log4j.HelloLog4J.getMessage (HELLOLOG4J.JAVA:20) [main] This is a error message.
        Transfer from http://blog.csdn.net/seeds_home/article/details/7800908

About Log4j.properties Example: Dailyrollingfileappender

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.