Skip to content
Browse files

adding rudimentary logging

  • Loading branch information...
1 parent fb67a6c commit 27948dbb34507b81331c1adb959fc0262505ac72 @jasondew jasondew committed with
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/Bird/BirdResponder.hs
12 src/Bird/BirdResponder.hs
@@ -7,11 +7,19 @@ import Data.Maybe
import Bird.Reply
import Bird.Request
import qualified Data.Map as Hash
+import Text.Printf
+import System.CPUTime
type BirdResponder = StateT Reply (ReaderT Request IO)
-runBirdResponder request router =
- runReaderT (execStateT (router request) def) request
+runBirdResponder request router = do
+ printf "Processing %s request of %s with %s\n" (show $ verb request) (show $ path request) (show $ params request)
+ start <- getCPUTime
+ reply <- runReaderT (execStateT (router request) def) request
+ end <- getCPUTime
+ printf " Response code: %s\n" (show $ replyStatus reply)
+ printf " Response time: %0.3fs\n\n" (((fromIntegral (end - start)) / (10^12)) :: Double)
+ return reply
body b = do
reply <- get

1 comment on commit 27948db


thanks jason! i'm merging into a "logging" branch, if the baby gives me enough free time today i'll refactor it a bit; planning on adding a WriterT monad into the BirdResponder monad stack, so that both the framework and users of the framework can use the logger.

Please sign in to comment.
Something went wrong with that request. Please try again.