shouldLogIO

This commit is contained in:
Michael Snoyman 2013-08-07 07:22:28 +03:00
parent d5b66d35d5
commit aa5781d4e4
2 changed files with 17 additions and 3 deletions

View File

@ -222,8 +222,9 @@ class RenderRoute site => Yesod site where
-> LogLevel -> LogLevel
-> LogStr -- ^ message -> LogStr -- ^ message
-> IO () -> IO ()
messageLoggerSource a logger loc source level msg = messageLoggerSource a logger loc source level msg = do
when (shouldLog a source level) $ sl <- shouldLogIO a source level
when sl $
formatLogMessage (loggerDate logger) loc source level msg >>= loggerPutStr logger formatLogMessage (loggerDate logger) loc source level msg >>= loggerPutStr logger
-- | Where to Load sripts from. We recommend the default value, -- | Where to Load sripts from. We recommend the default value,
@ -260,6 +261,19 @@ class RenderRoute site => Yesod site where
shouldLog :: site -> LogSource -> LogLevel -> Bool shouldLog :: site -> LogSource -> LogLevel -> Bool
shouldLog _ _ level = level >= LevelInfo shouldLog _ _ level = level >= LevelInfo
-- | Should we log the given log source/level combination.
--
-- Note that this is almost identical to @shouldLog@, except the result
-- lives in @IO@. This allows you to dynamically alter the logging level of
-- your application by having this result depend on, e.g., an @IORef@.
--
-- The default implementation simply uses @shouldLog@. Future versions of
-- Yesod will remove @shouldLog@ and use this method exclusively.
--
-- Since 1.2.4
shouldLogIO :: site -> LogSource -> LogLevel -> IO Bool
shouldLogIO a b c = return (shouldLog a b c)
-- | A Yesod middleware, which will wrap every handler function. This -- | A Yesod middleware, which will wrap every handler function. This
-- allows you to run code before and after a normal handler. -- allows you to run code before and after a normal handler.
-- --

View File

@ -1,5 +1,5 @@
name: yesod-core name: yesod-core
version: 1.2.3.1 version: 1.2.4
license: MIT license: MIT
license-file: LICENSE license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com> author: Michael Snoyman <michael@snoyman.com>