capotej/finatra — pull request #58 by pcalcado (2013-09-14 03:16:39+00:00)
Title: Logging to stdout and fixed log level

**tl;dr Logging to a file doesn't work, removed the feature and made logging to stdout follow the configured node and level**

At SoundCloud we are using Finatra as the HTTP router/handler for our new services architecture ([some more detail here](http://www.slideshare.net/pcalcado/from-a-monolithic-ruby-on-rails-app-to-the-jvm)). All of our services are developed following the [12 factor app model](http://12factor.net/), and there are a couple of things in Finatra which we had to patch to make it work under this framework.

One of such things is logging.

We first identified a problem with Finatra not following its configuration when deciding which file to log to. Other problem is that we must log to STDOUT, not a file. In fact, our filesystem is read-only, and the mere fact that Finatra attempts to create/touch a `finatra.log` file breaks it badly.

This is what we do:

```scala
class PatchedFinatraServer extends FinatraServer {
override def initLogger() = {
val log: Logger = LoggerFactory(
node = "com.twitter",
level = Some(Level.DEBUG),
handlers = List(() => new ConsoleHandler)).apply()
}
}
```

While fixing the issue (see commits 1e894fc3693be2cc95599ba5582770136c4e8ce2, 7044861d3a512e7ae8c0fb9fe2c034c6d2587166, 86810f735399c4c2c2864008adf621c55932152d and cc05445cf2c1dfb1f0dd8900135c8eec73d252e8) I've found out that apparently the "log to file" feature never (for some value of never) worked. Here is a test run using the generator script:

```
ziege: ~/code/foss/scala/finatra/banana
$ grep finatra -A 1 pom.xml
finatra
1.3.7

ziege: ~/code/foss/scala/finatra/banana
$ grep logger.error -A 2 -B 1 src/main/scala/banana/App.scala
get("/") { request =>
logger.error("this should end up in the file?")
render.plain("hello world").toFuture
}

ziege: ~/code/foss/scala/finatra/banana
$ mvn scala:run
[INFO] Scanning for projects...
[...]
[INFO] launcher 'main' selected => banana.App
Sep 13, 2013 10:42:45 PM com.twitter.logging.Logger log
INFO: Starting LatchedStatsListener
Sep 13, 2013 10:42:45 PM com.twitter.logging.Logger log
INFO: Starting JsonStatsLogger
Sep 13, 2013 10:42:45 PM com.twitter.logging.Logger log
INFO: Starting TimeSeriesCollector
Sep 13, 2013 10:42:45 PM com.twitter.logging.Logger log
INFO: Admin HTTP interface started on port 9990.
Sep 13, 2013 10:42:45 PM com.twitter.logging.Logger log
INFO: process 46573 started on 7070
finatra process 46573 started on port: 7070
config args:
-Dname=finatra\
-Dlog_path=logs/finatra.log\
-Dstats_enabled=true\
-Dmax_request_megabytes=5\
-Dstats_port=9990\
-Dtemplate_path=/\
-Dlog_node=finatra\
-Dport=7070\
-Dlocal_docroot=src/main/resources\
-Dpid_enabled=false\
-Dpid_path=finatra.pid\
-Denv=development\
Sep 13, 2013 10:42:49 PM com.twitter.logging.Logger log
INFO: GET /
Sep 13, 2013 10:42:49 PM com.twitter.logging.Logger log
ERROR: this should end up in the file?
^C%
ziege: ~/code/foss/scala/finatra/banana
$ cat log/finatra.log

ziege: ~/code/foss/scala/finatra/banana
$
```

So, instead of trying to fix it I just removed the feature as no one is able to use it anyway. I kept the old commits just for history's sake, please feel free to squash them.