Add request logging
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
module Yore.Log (info) where
|
||||
|
||||
import Data.Time (getZonedTime)
|
||||
import GHC.Stack (HasCallStack, SrcLoc (..), callStack, getCallStack)
|
||||
import Text.Printf (printf)
|
||||
|
||||
info :: (HasCallStack) => String -> IO ()
|
||||
info = doLog "INF"
|
||||
|
||||
doLog :: (HasCallStack) => String -> String -> IO ()
|
||||
doLog level msg = do
|
||||
now <- getZonedTime
|
||||
let location = getLocation $ getCallStack callStack
|
||||
printf "(%s) (%s) (%s) %s\n" (show now) location level msg
|
||||
where
|
||||
getLocation :: [(String, SrcLoc)] -> String
|
||||
-- First entry is always a function from this module, skip it
|
||||
getLocation (_ : (_, srcLoc) : _) = printf "%s:%d" (srcLocFile srcLoc) (srcLocStartLine srcLoc)
|
||||
getLocation _ = ""
|
||||
Reference in New Issue
Block a user