Add request logging

This commit is contained in:
Paul Brinkmeier
2025-08-20 19:04:13 +02:00
parent c7da029c7e
commit b264b50b01
3 changed files with 34 additions and 3 deletions
+19
View File
@@ -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 _ = ""