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)