Link Search Menu Expand Document

NOTE: We no longer use SparkJava in CS56/156, but this information has been retained for reference.

Log4J is short for Apache Logging For Java

If you get this message when starting up a Sparkjava web application, the reason is that are missing the dependency on Log4J:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See for further details.

To fix this, include this in your pom.xml:


That is only the start. You’ll then get this error message instead:

log4j:WARN No appenders could be found for logger (spark.route.Routes).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See for more info.

To fix this, create a file called in the file src/main/resources. The contents should be as shown below.)


# Root logger option
log4j.rootLogger=DEBUG, stdout

# Redirect log messages to console
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Once you do this, you’ll start seeing a lot more information in the output stream of your Sparkjava webapps. For example:

2018-09-04 17:08:19 DEBUG Routes:187 - Adds route: post, /posts, spark.RouteImpl$1@4a7a2694
2018-09-04 17:08:19 DEBUG Routes:187 - Adds route: get, /posts, spark.RouteImpl$1@59a47725
2018-09-04 17:08:19 DEBUG log:176 - Logging to org.slf4j.impl.Log4jLoggerAdapter(org.eclipse.jetty.util.log) via org.eclipse.jetty.util.log.Slf4jLog
2018-09-04 17:08:19 INFO  log:186 - Logging initialized @1734ms

Too little log output can be frustrating, since you don’t know what’s going on. But too much can be overwhelming, so it’s possible to tailor the level of output using the settings in the file.

For more information, see: