ocharles/logging-effect

Lots of blank lines being printed

Closed this issue · 2 comments

jml commented

When I run the test suite for my server that has logging with logging-effect, I get many, many blank lines printed. Likewise, when I fire up the server, I get an unexpected blank line when I load a

$ stack exec awesome-service -- --port 8080
[2016-10-16T16:03:55.841369000000] [Informational] Listening on :8080

^C

The blank line appears when I hit a web page.

Relevant code is at https://github.com/jml/servant-template/blob/master/%7B%7B%20cookiecutter.project_name%20%7D%7D/%7B%7B%20cookiecutter.project_name%20%7D%7D-server/src/%7B%7B%20cookiecutter.module_name%20%7D%7D/Server/Logging.hs#L62-L70

I don't have a minimal repro of this, but you can get running code fairly quickly with:

$ pip install --user cookiecutter
$ cookiecutter --no-input gh:jml/servant-template
$ cd awesome-service
$ stack test awesome-service-server

It's possible that this isn't an issue with logging-effect, but rather with the wai access logs. I only recall this occurring once I switched to withFDHandler though.

Ok, I believe the problem is here, in my code:

  withBatchedHandler options
                     (PP.displayIO fd . PP.renderPretty ribbonFrac width . (<> PP.linebreak) . PP.vsep)

What this is saying is that for any batch of messages ([msg]), concatenate all messages with vsep, which inserts line breaks between all messages, and then append a line break at the end. However, this means that if you have no messages at all, we will still output a line break - that's no good! I'll have a think about the best thing to do here, which might just be special-casing the empty list.

jml commented

Thanks!