Ninja uses the Logback via slf4j as logging library.
Usually you want to use different logging settings when running in test, dev or on production.
There are three main ways how you can configure Logback.
By default Logback will look for a file called logback.xml in the root of your application. If it finds one it will intialize the logging system accordingly. This approach is okay for simple setups.
Logback evaluates a Java system property named logback.configurationFile. This approach is handy if you are using Ninja’s standalone mode:
java -Dlogback.configurationFile=/srv/conf/logback.xml -jar ninja-application.jar
This allows you to use one logging configuration for all your instances. More about that approach here: http://logback.qos.ch/manual/configuration.html
If you cannot or do not want to use external Java system properties you can use application.conf and the key logback.configurationFile to specify the location of the logging file. Ninja will pick up the file and configure Logback accordingly.
# An example for application.conf based configuration of logback %prod.logback.configurationFile=logback_prod.xml # will be used in production %dev.logback.configurationFile=logback_dev.xml # will be used in dev mode
Ninja will look for specified files in three places in the following order:
Ninja provides you with a simple foundation to use Logback. And this is perfect, because logback has everything you need to configure logging - even for the largest systems you can image.
The best way to configure Logback is to follow the excellent guide at: http://logback.qos.ch/manual/configuration.html
But just in case you were wondering how such a logback.xml file can look like:
<configuration> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>myApp.log</file> <encoder> <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern> </encoder> </appender> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%msg%n</pattern> </encoder> </appender> <root level="debug"> <appender-ref ref="FILE" /> <appender-ref ref="STDOUT" /> </root> </configuration>
By the way - you can also write logback configuration files in Groovy.