Spock icon indicating copy to clipboard operation
Spock copied to clipboard

Custom logging using e.g. katip/monad-logger

Open philipcunningham opened this issue 8 years ago • 4 comments

Hey folks, thanks for writing Spock!

This might not be the place for this request but I was wondering if you could perhaps add some advice to the documentation about how Spock users should go about adding logging to a Spock application. I know there are things like wai-extras that have a wai middleware for logging requests but, at least in the applications I work on, I'd also like to do some custom logging.

Specifically, I'm interested in how I should go about integrating with common libraries like monad-logger or katip but I'd appreciate any general advice you have.

philipcunningham avatar Dec 13 '17 11:12 philipcunningham

I've added a repo with a minimal Spock app here on the offhand that someone has already done this in the past 😄

https://github.com/filib/spock-katip-example/blob/master/app/Main.hs

philipcunningham avatar Dec 13 '17 18:12 philipcunningham

I think the quickest way to achieve this is to add a logging interface to either:

  • add a logging interface data type to your st param which you can get via getState. Write some combinators to wrap this neatly.
  • use a logging solution that uses a global logger like simple-logger
  • send a PR to support logging within Spock :-)

agrafix avatar Dec 14 '17 03:12 agrafix

I had to get things up and running quickly and simple-logger was just the ticket. Do you think that this would make a good Spock tutorial or would you prefer it be done on e.g. a personal blog post instead?

philipcunningham avatar Dec 16 '17 12:12 philipcunningham

A writeup on the Spock blog would also work for me.

agrafix avatar Dec 17 '17 16:12 agrafix