Logging functionality is a must for any application. It provides a clear view on what application is doing, greatly simplifies the debugging process, and records any mishaps when the application is running in the production environment.
By default, Play Framework includes logging functionality for the application and the framework. We will add a minor customization to reduce the Play and third-party logs to a minimum, while having a clear print out of the application logic.
Using IntelliJ, expand conf directory and open logback.xml file.
To simplify the log file access, change the file appender directory to logs/application.log.
Add a new logger entry above the play and application loggers. Name the new logger and set the level to DEBUG. Change play logger level to WARN and application logger level to INFO.
For your reference, several logging levels are available:
As you develop the application, experiment with different levels for the play, application, and custom loggers to see how much information you would like to see. At LineDrop, we mostly keep the codebase logging set to DEBUG, occasionally changing it to TRACE to observe low level operations.
Uncomment ASYNCFILE entry in the root node to enable writing of the logs to a file.
To easily access the customer logger, add the Log object to your project.
Browse related articles