> ## Content Index
> Fetch the complete content index at: https://honstain.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Scalatra Logging
- URL: https://honstain.com/scalatra-logging/
- Published: 2019-02-08T16:17:19.000Z
- Updated: 2026-06-21T00:33:43.000Z
- Author: Anthony Honstain
- Tags: Scala, Scalatra, #Import 2024-01-27 15:52

## Overview

If you want to add logging to your Scalatra service and get some basic log strings coming to STDOUT, following the Scalatra documentation for logging is the best reference [http://scalatra.org/guides/2.6/monitoring/logging.html](http://scalatra.org/guides/2.6/monitoring/logging.html?ref=honstain.com)

The rest of this post is just the details of me adding additional logging to the example Scalata service from this series of blog posts.

## Details

The logging framework recommended by Scalatra is Logback, so if you follow the [official getting started guide](http://scalatra.org/getting-started/project-structure.html?ref=honstain.com) (or went through one of the [previous posts on creating a Scalatra service](https://honstain.com/scalatra-giter8/)), you would likely have the following dependency for [Logback](https://logback.qos.ch/?ref=honstain.com) in your project.

```
"ch.qos.logback" % "logback-classic" % "1.2.3" % "runtime",
```

The Scalatra site also has an simple example that shows how to get basic support running [http://scalatra.org/guides/2.6/monitoring/logging.html](http://scalatra.org/guides/2.6/monitoring/logging.html?ref=honstain.com). This will let you generate the following kind of log data to your STDOUT:

```
07:58:38.004 [qtp1915910607-17] DEBUG o.b.honstain.app.ToyInventory - Creating inventory sku:ZL104
07:58:38.005 [qtp1915910607-17] DEBUG o.b.honstain.app.ToyInventory - Creating inventory Inventory(ZL104,3,Pine Block of Wood)

```

If you would also like to generate a log file with JSON (if you are interested in constructing some structured log data) the following project was helpful for me [https://github.com/logstash/logstash-logback-encoder](https://github.com/logstash/logstash-logback-encoder?ref=honstain.com)

```xml
<configuration>

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>log/log-ToyInventoryApp.log</file>
    <encoder class="net.logstash.logback.encoder.LogstashEncoder">
      <customFields>{"application":"log-ToyInventoryApp"}</customFields>
    </encoder>
  </appender>

  <root level="debug">
    <appender-ref ref="FILE" />
  </root>
</configuration>

```

The previous log message would then appear as the following in your log file:

```json
{"@timestamp":"2019-02-08T07:58:38.004-08:00","@version":"1","message":"Creating inventory sku:ZL104","logger_name":"org.bitbucket.honstain.app.ToyInventory","thread_name":"qtp1915910607-17","level":"DEBUG","level_value":10000,"application":"log-ToyInventoryApp"}
{"@timestamp":"2019-02-08T07:58:38.005-08:00","@version":"1","message":"Creating inventory Inventory(ZL104,3,Pine Block of Wood)","logger_name":"org.bitbucket.honstain.app.ToyInventory","thread_name":"qtp1915910607-17","level":"DEBUG","level_value":10000,"application":"log-ToyInventoryApp"}

```

For additional reference you can look to the commit I made to this example Scalatra project [https://bitbucket.org/honstain/scalatra-example-blog/commits/99fa1f17980bee4c3d29374bb1bcc8e5d0887802](https://bitbucket.org/honstain/scalatra-example-blog/commits/99fa1f17980bee4c3d29374bb1bcc8e5d0887802?ref=honstain.com)

The documentation for logback is a good reference if you are unfamiliar with this type of logging framework [https://logback.qos.ch/manual/architecture.html](https://logback.qos.ch/manual/architecture.html?ref=honstain.com)

In summary, this is a reasonable start but we still have some way to go before we could optimally interface with an ELK or Splunk.