Export defaults for logging methods of Yesod.
This commit is contained in:
parent
b1bc30addd
commit
bd161ef5f7
@ -30,6 +30,11 @@ module Yesod.Core
|
|||||||
, AuthResult (..)
|
, AuthResult (..)
|
||||||
, unauthorizedI
|
, unauthorizedI
|
||||||
-- * Logging
|
-- * Logging
|
||||||
|
, defaultMakeLogger
|
||||||
|
, defaultMessageLoggerSource
|
||||||
|
, defaultShouldLog
|
||||||
|
, defaultShouldLogIO
|
||||||
|
, formatLogMessage
|
||||||
, LogLevel (..)
|
, LogLevel (..)
|
||||||
, logDebug
|
, logDebug
|
||||||
, logInfo
|
, logInfo
|
||||||
|
|||||||
@ -207,17 +207,14 @@ class RenderRoute site => Yesod site where
|
|||||||
-- method return that already created value. That way, you can use that
|
-- method return that already created value. That way, you can use that
|
||||||
-- same @Logger@ for printing messages during app initialization.
|
-- same @Logger@ for printing messages during app initialization.
|
||||||
--
|
--
|
||||||
-- Default: Sends to stdout and automatically flushes on each write.
|
-- Default: the 'defaultMakeLogger' function.
|
||||||
makeLogger :: site -> IO Logger
|
makeLogger :: site -> IO Logger
|
||||||
makeLogger _ = do
|
makeLogger _ = defaultMakeLogger
|
||||||
loggerSet' <- newStdoutLoggerSet defaultBufSize
|
|
||||||
(getter, _) <- clockDateCacher
|
|
||||||
return $! Logger loggerSet' getter
|
|
||||||
|
|
||||||
-- | Send a message to the @Logger@ provided by @getLogger@.
|
-- | Send a message to the @Logger@ provided by @getLogger@.
|
||||||
--
|
--
|
||||||
-- Default implementation: checks if the message should be logged using
|
-- Default: the 'defaultMessageLoggerSource' function, using
|
||||||
-- 'shouldLog' and, if so, formats using 'formatLogMessage'.
|
-- 'shouldLogIO' to check whether we should log.
|
||||||
messageLoggerSource :: site
|
messageLoggerSource :: site
|
||||||
-> Logger
|
-> Logger
|
||||||
-> Loc -- ^ position in source code
|
-> Loc -- ^ position in source code
|
||||||
@ -225,10 +222,7 @@ class RenderRoute site => Yesod site where
|
|||||||
-> LogLevel
|
-> LogLevel
|
||||||
-> LogStr -- ^ message
|
-> LogStr -- ^ message
|
||||||
-> IO ()
|
-> IO ()
|
||||||
messageLoggerSource a logger loc source level msg = do
|
messageLoggerSource site = defaultMessageLoggerSource $ shouldLogIO site
|
||||||
sl <- shouldLogIO a source level
|
|
||||||
when sl $
|
|
||||||
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,
|
||||||
-- 'BottomOfBody'. Alternatively use the built in async yepnope loader:
|
-- 'BottomOfBody'. Alternatively use the built in async yepnope loader:
|
||||||
@ -260,9 +254,9 @@ class RenderRoute site => Yesod site where
|
|||||||
|
|
||||||
-- | Should we log the given log source/level combination.
|
-- | Should we log the given log source/level combination.
|
||||||
--
|
--
|
||||||
-- Default: Logs everything at or above 'logLevel'
|
-- Default: the 'shouldLog' function.
|
||||||
shouldLog :: site -> LogSource -> LogLevel -> Bool
|
shouldLog :: site -> LogSource -> LogLevel -> Bool
|
||||||
shouldLog _ _ level = level >= LevelInfo
|
shouldLog _ = defaultShouldLog
|
||||||
|
|
||||||
-- | Should we log the given log source/level combination.
|
-- | Should we log the given log source/level combination.
|
||||||
--
|
--
|
||||||
@ -300,6 +294,43 @@ class RenderRoute site => Yesod site where
|
|||||||
yesodWithInternalState _ _ = bracket createInternalState closeInternalState
|
yesodWithInternalState _ _ = bracket createInternalState closeInternalState
|
||||||
{-# INLINE yesodWithInternalState #-}
|
{-# INLINE yesodWithInternalState #-}
|
||||||
|
|
||||||
|
-- | Default implementation of 'makeLogger'. Sends to stdout and
|
||||||
|
-- automatically flushes on each write.
|
||||||
|
defaultMakeLogger :: IO Logger
|
||||||
|
defaultMakeLogger = do
|
||||||
|
loggerSet' <- newStdoutLoggerSet defaultBufSize
|
||||||
|
(getter, _) <- clockDateCacher
|
||||||
|
return $! Logger loggerSet' getter
|
||||||
|
|
||||||
|
-- | Default implementation of 'messageLoggerSource'. Checks if the
|
||||||
|
-- message should be logged using the provided function, and if so,
|
||||||
|
-- formats using 'formatLogMessage'. You can use 'defaultShouldLogIO'
|
||||||
|
-- as the provided function.
|
||||||
|
defaultMessageLoggerSource ::
|
||||||
|
(LogSource -> LogLevel -> IO Bool) -- ^ Check whether we should
|
||||||
|
-- log this
|
||||||
|
-> Logger
|
||||||
|
-> Loc -- ^ position in source code
|
||||||
|
-> LogSource
|
||||||
|
-> LogLevel
|
||||||
|
-> LogStr -- ^ message
|
||||||
|
-> IO ()
|
||||||
|
defaultMessageLoggerSource ckLoggable logger loc source level msg = do
|
||||||
|
loggable <- ckLoggable source level
|
||||||
|
when loggable $
|
||||||
|
formatLogMessage (loggerDate logger) loc source level msg >>=
|
||||||
|
loggerPutStr logger
|
||||||
|
|
||||||
|
-- | Default implementation of 'shouldLog'. Logs everything at or
|
||||||
|
-- above 'logLevel'.
|
||||||
|
defaultShouldLog :: LogSource -> LogLevel -> Bool
|
||||||
|
defaultShouldLog _ level = level >= LevelInfo
|
||||||
|
|
||||||
|
-- | A default implementation of 'shouldLogIO' that can be used with
|
||||||
|
-- 'defaultMessageLoggerSource'. Just uses 'defaultShouldLog'.
|
||||||
|
defaultShouldLogIO :: LogSource -> LogLevel -> IO Bool
|
||||||
|
defaultShouldLogIO a b = return $ defaultShouldLog a b
|
||||||
|
|
||||||
-- | Default implementation of 'yesodMiddleware'. Adds the response header
|
-- | Default implementation of 'yesodMiddleware'. Adds the response header
|
||||||
-- \"Vary: Accept, Accept-Language\" and performs authorization checks.
|
-- \"Vary: Accept, Accept-Language\" and performs authorization checks.
|
||||||
--
|
--
|
||||||
@ -577,6 +608,7 @@ asyncHelper render scripts jscript jsLoc =
|
|||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
Just j -> Just $ jelper j
|
Just j -> Just $ jelper j
|
||||||
|
|
||||||
|
-- | Default formatting for log messages.
|
||||||
formatLogMessage :: IO ZonedDate
|
formatLogMessage :: IO ZonedDate
|
||||||
-> Loc
|
-> Loc
|
||||||
-> LogSource
|
-> LogSource
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user