Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for code snippet - Recommended way to do request logging #199

Open
saurabhnanda opened this issue Jan 22, 2017 · 4 comments
Open

Comments

@saurabhnanda
Copy link

Would it basically be a middleware based on https://hackage.haskell.org/package/wai-extra-3.0.19.1/docs/Network-Wai-Middleware-RequestLogger.html ? Will it also log time taken to complete the request?

@robertjlooby
Copy link

Yes, you can use Network.Wai.Middleware.RequestLogger. It includes a couple default loggers, or you can tweak the configs if you want. As an example:

module Main where

import Network.Wai.Middleware.RequestLogger (logStdout)
import Web.Scotty

main :: IO ()
main = do
  scotty 3000 $ do
    middleware logStdout
    ...

will produce "prod" type log statements like

Setting phasers to stun... (port 3000) (ctrl-c to quit)
127.0.0.1 - - [08/Jun/2017:18:28:02 -0500] "GET / HTTP/1.1" 200 - "" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
127.0.0.1 - - [08/Jun/2017:18:28:02 -0500] "GET /init HTTP/1.1" 404 - "http://localhost:3000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

if you swap in logStdoutDev for logStdout you get more "dev" type log statements like

Setting phasers to stun... (port 3000) (ctrl-c to quit)
GET /
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  Status: 200 OK 0.001119s
GET /init
  Accept: */*
  Status: 404 Not Found 0.000061s

@arafangion

This comment was marked as resolved.

@arafangion

This comment was marked as resolved.

@arafangion

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants