Related uses of log

Source: Internet
Author: User

1, it is best to define the log variable with static final

Private static final Log log = Logfactory.getlog (Mytest.class);

There are three advantages to doing so:

    • can guarantee thread safety
    • Static or non-static code is available
    • Does not affect serialization of objects

2, the output of the log log in the Code "first project engineering, to have the relevant jar"

1) The contents of the Log4g.properties configuration file "need to configure some log output path, and canonical output file name format"

Log4j.rootlogger = debug,stdout,d,e### output information to control lift # # #log4j. appender.stdout = Org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.Target = System.outlog4j.appender.stdout.layout = Org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern = [%-5p]%d{yyyy-mm-dd Hh:mm:ss,sss} method:%l%n%m%n### output debug levels above the log to =e://logs/error.log # # #log4j. APPENDER.D = Org.apache.log4j.dailyrollingfileappenderlog4j.appender.d.file = E://logs/log.loglog4j.appender.d.append = Truelog4j.appender.d.threshold = DEBUG Log4j.appender.d.layout = Org.apache.log4j.patternlayoutlog4j.appender.d.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss} [%t:%r]-[%p]%m %n### output error level above the log to =e://logs/error.log # # #log4j. APPENDER.E = Org.apache.log4j.dailyrollingfileappenderlog4j.appender.e.file =e://logs/error.log log4j.appender.E.Append = Truelog4j.appender.e.threshold = ERROR Log4j.appender.e.layout = Org.apache.log4j.patternlayoutlog4j.appender.e.layout.conversionpattern =%-d{yyyy-mm-dd HH:mm:ss}  [%t:%r]-[%p]%m%n 

2) Specific implementation class "Log4gtest.java"

Package Com.log4g;import Org.apache.log4j.logger;public class Log4gtest {private static final Logger Logger = Logger.getl Ogger (log4gtest.class);      public static void Main (string[] args) {          //record debug level information          logger.debug ("This is debug Message.debug test");          Record info level information          logger.info ("This is info message.info test");          Record the error level information          logger.error ("This is the test for error Message.error");}  }

The result of the operation is:

Then find the relevant e-disk, you will find the relevant log file exists, that is, success!

   

Related uses of log

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.