Playframework a step-by-step log (i)

Source: Internet
Author: User

Log module is an essential part of a system, it can help us to write programs to view error messages, facilitate debugging and maintenance, on the business side, it can also record some of the system's key operations to facilitate system information monitoring and tracking.

Play logs are based on logback and are particularly handy to use, which has to be admired by the designer.

Next, let's start with a simple, rough trial:

1, first create a play project, the name is: Hello_log; If your IntelliJ idea is using 14, you will find "error" after creation, it doesn't matter that you re-import it after you close the project. This is also the IDE's plug-in issue for play.

2, after, we open app/controllers in the application, add the following information (red circled out of the section):

This code does not need to explain too much, is to create a logger, and then need to print the log where the log. Note that here I use Trace, DEBUG, INFO, WARN, error five levels, Logback now only these five usage levels (off) is less than the log4j used previously often a "FATAL", and these five levels are incremented by rank.

3. Then, we open play configuration file conf/application.conf, follow the changes:

OK, end, let's run!

Imagine that the result should be to print all the logs before the Welcome interface comes out, and possibly also to enter the printed content like a log file.

Result

Console

Log file (logs/application):

perfect! Exactly the same as the expected result!

What do you think? Isn't it super simple? Next, you may wonder: How is play implemented? Where is the Logback profile written? What do the Logger.root, Logger.application, and Logger.play in the configuration file stand for? Could you customize a log appender and output style? Listen to tell, please.

Playframework a step-by-step log (i)

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.