[web-devel] Error logging in Yesod

Michael Snoyman michael at snoyman.com
Fri Apr 1 08:20:21 CEST 2011

Hi all,

Hot on the heels of the decision to remove logging from WAI, I would
like to add it to Yesod. I think (at least to start with), we really
need two modifications: a new method in the Yesod typeclass that
specifies what to do with log messages, and a function living in the
Handler monad that calls that method. I do not have any strong
opinions on this topic, so I would appreciate input. Here's a strawman

data LogLevel = LevelInfo | LevelWarn | LevelError | LevelOther Text

class Yesod a where
    messageLogger :: a -> LogLevel -> Text -> IO ()
    messageLogger _ level msg = formatLogMessage level msg >>=
Data.Text.Lazy.IO.hPutStrLn System.IO.stderr

formatLogMessage :: LogLevel -> Text -> IO Text
formatLogMessage = ...
-- print timestamp, log level, message, maybe process ID? to stderr
-- make sure to expose the

logInfo :: MonadIO m => Text -> GGHandler sub master m ()
logInfo t = do
    y < getYesod
    liftIO $ messageLogger y LevelInfo t

... and so on and so forth

This should give completely flexibility to users to send their logs
anywhere (database, printer, missiles) and in whatever format they

Other ideas:

* It would be nice to include file/line number information, but I'm
not sure how easy/possible that will be without requiring the user to
manually enter CPP macros.
* Actually, that was my only other idea :)


More information about the web-devel mailing list