h1. Logging configuration

The Play logger is built on "Log4j":http://logging.apache.org/log4j/1.2/index.html. Since most Java libraries use Log4j or a wrapper able to use Log4j as a backend, you can easily configure logging that is well-suited to your application.


h2. <a name="logging">Logging from your application</a>

Play provides a default logger with the class @play.Logger@. This class uses Log4j to write messages and exceptions to a logger named @play@.

Logging from your application is easy:

bc. Logger.info("A log message");
Logger.error(ex, "Oops");

The @play.Logger@ class’ methods support easy formatting through the standard Java formatter syntax:

bc. Logger.debug("The param was %s", param);
Logger.info("I want to log %s and %s and %s", a, b, c);

You can still use Log4j directly to create alternative loggers for specific needs:

bc. org.apache.log4j.Logger.getLogger("another.logger");


h2. <a name="levels">Configure log levels</a>

You can set the Play logger’s log level by configuring "application.log":configuration#application.log. You can change this value without restarting the server. Note that this level only applies to messages generated by the application.

If you need to fully configure Log4j, create a @log4j.properties@ file in the @conf/@ directory. Since this directory is the first element of the classpath, this file will be the default used by all libraries.

The default Log4j configuration is the following:

bc. log4j.rootLogger=ERROR, Console
 
log4j.logger.play=INFO
 
# Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p ~ %m%n

Copy this file and update it for your specifics needs!


h3. <a name="production">Production configuration</a>

See: "configure logging for production":production#logging for another example.

p(note). **Continuing the discussion**
 
Next, we continue configuration with %(next)"Configuration in several environments":ids%.
