Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
This module provides the facilities needed for a decoupled logging system.
The MonadLogger
class is implemented by monads that give access to a
logging facility. If you're defining a custom monad, then you may define an
instance of MonadLogger
that routes the log messages to the appropriate
place (e.g., that's what yesod-core
's HandlerT
does). Otherwise, you
may use the LoggingT
monad included in this module (see
runStderrLoggingT
). To simply discard log message, use NoLoggingT
.
As a user of the logging facility, we provide you some convenient Template
Haskell splices that use the MonadLogger
class. They will record their
source file and position, which is very helpful when debugging. See
logDebug
for more information.
Synopsis
- class Monad m => MonadLogger m where
- class (MonadLogger m, MonadIO m) => MonadLoggerIO m where
- data LogLevel
- type LogSource = Text
- data LogStr
- class ToLogStr msg where
- newtype LoggingT m a = LoggingT {}
- runStderrLoggingT :: MonadIO m => LoggingT m a -> m a
- runStdoutLoggingT :: MonadIO m => LoggingT m a -> m a
- runChanLoggingT :: MonadIO m => Chan LogLine -> LoggingT m a -> m a
- runFileLoggingT :: MonadBaseControl IO m => FilePath -> LoggingT m a -> m a
- unChanLoggingT :: (MonadLogger m, MonadIO m) => Chan LogLine -> m void
- withChannelLogger :: (MonadBaseControl IO m, MonadIO m) => Int -> LoggingT m a -> LoggingT m a
- filterLogger :: (LogSource -> LogLevel -> Bool) -> LoggingT m a -> LoggingT m a
- newtype NoLoggingT m a = NoLoggingT {
- runNoLoggingT :: m a
- mapNoLoggingT :: (m a -> n b) -> NoLoggingT m a -> NoLoggingT n b
- newtype WriterLoggingT m a = WriterLoggingT {
- unWriterLoggingT :: m (a, DList LogLine)
- execWriterLoggingT :: Functor m => WriterLoggingT m a -> m [LogLine]
- runWriterLoggingT :: Functor m => WriterLoggingT m a -> m (a, [LogLine])
- mapLoggingT :: (m a -> n b) -> LoggingT m a -> LoggingT n b
- logDebug :: Q Exp
- logInfo :: Q Exp
- logWarn :: Q Exp
- logError :: Q Exp
- logOther :: Text -> Q Exp
- logDebugSH :: Q Exp
- logInfoSH :: Q Exp
- logWarnSH :: Q Exp
- logErrorSH :: Q Exp
- logOtherSH :: Text -> Q Exp
- logDebugS :: Q Exp
- logInfoS :: Q Exp
- logWarnS :: Q Exp
- logErrorS :: Q Exp
- logOtherS :: Q Exp
- liftLoc :: Loc -> Q Exp
- logDebugN :: MonadLogger m => Text -> m ()
- logInfoN :: MonadLogger m => Text -> m ()
- logWarnN :: MonadLogger m => Text -> m ()
- logErrorN :: MonadLogger m => Text -> m ()
- logOtherN :: MonadLogger m => LogLevel -> Text -> m ()
- logWithoutLoc :: (MonadLogger m, ToLogStr msg) => LogSource -> LogLevel -> msg -> m ()
- logDebugNS :: MonadLogger m => Text -> Text -> m ()
- logInfoNS :: MonadLogger m => Text -> Text -> m ()
- logWarnNS :: MonadLogger m => Text -> Text -> m ()
- logErrorNS :: MonadLogger m => Text -> Text -> m ()
- logOtherNS :: MonadLogger m => Text -> LogLevel -> Text -> m ()
- logDebugCS :: MonadLogger m => CallStack -> Text -> m ()
- logInfoCS :: MonadLogger m => CallStack -> Text -> m ()
- logWarnCS :: MonadLogger m => CallStack -> Text -> m ()
- logErrorCS :: MonadLogger m => CallStack -> Text -> m ()
- logOtherCS :: MonadLogger m => CallStack -> LogLevel -> Text -> m ()
- defaultLogStr :: Loc -> LogSource -> LogLevel -> LogStr -> LogStr
- data Loc = Loc {}
- defaultLoc :: Loc
MonadLogger
class Monad m => MonadLogger m where Source #
A Monad
which has the ability to log messages in some manner.
monadLoggerLog :: ToLogStr msg => Loc -> LogSource -> LogLevel -> msg -> m () Source #
monadLoggerLog :: (MonadLogger m', MonadTrans t, MonadLogger (t m'), ToLogStr msg, m ~ t m') => Loc -> LogSource -> LogLevel -> msg -> m () Source #
Instances
class (MonadLogger m, MonadIO m) => MonadLoggerIO m where Source #
An extension of MonadLogger
for the common case where the logging action
is a simple IO
action. The advantage of using this typeclass is that the
logging function itself can be extracted as a first-class value, which can
make it easier to manipulate monad transformer stacks, as an example.
Since: monad-logger-0.3.10
askLoggerIO :: m (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) Source #
Request the logging function itself.
Since: monad-logger-0.3.10
askLoggerIO :: (MonadTrans t, MonadLoggerIO n, m ~ t n) => m (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) Source #
Request the logging function itself.
Since: monad-logger-0.3.10
Instances
Re-export from fast-logger
Log message builder. Use (<>
) to append two LogStr in O(1).
Instances
ToLogStr ByteString | |
Defined in System.Log.FastLogger.LogStr toLogStr :: ByteString -> LogStr # | |
ToLogStr ByteString | |
Defined in System.Log.FastLogger.LogStr toLogStr :: ByteString -> LogStr # | |
ToLogStr Text | |
Defined in System.Log.FastLogger.LogStr | |
ToLogStr Text | |
Defined in System.Log.FastLogger.LogStr | |
ToLogStr String | |
Defined in System.Log.FastLogger.LogStr | |
ToLogStr LogStr | |
Defined in System.Log.FastLogger.LogStr |
Helper transformers
Monad transformer that adds a new logging function.
Since: monad-logger-0.2.2
Instances
runStderrLoggingT :: MonadIO m => LoggingT m a -> m a Source #
Run a block using a MonadLogger
instance which prints to stderr.
Since: monad-logger-0.2.2
runStdoutLoggingT :: MonadIO m => LoggingT m a -> m a Source #
Run a block using a MonadLogger
instance which prints to stdout.
Since: monad-logger-0.2.2
runChanLoggingT :: MonadIO m => Chan LogLine -> LoggingT m a -> m a Source #
Run a block using a MonadLogger
instance which writes tuples to an
unbounded channel.
The tuples can be extracted (ie. in another thread) with unChanLoggingT
or a custom extraction funtion, and written to a destination.
Since: monad-logger-0.3.17
runFileLoggingT :: MonadBaseControl IO m => FilePath -> LoggingT m a -> m a Source #
Run a block using a MonadLogger
instance which appends to the specified file.
Since: monad-logger-0.3.22
unChanLoggingT :: (MonadLogger m, MonadIO m) => Chan LogLine -> m void Source #
Read logging tuples from an unbounded channel and log them into a
MonadLoggerIO
monad, forever.
For use in a dedicated thread with a channel fed by runChanLoggingT
.
Since: monad-logger-0.3.17
:: (MonadBaseControl IO m, MonadIO m) | |
=> Int | Number of messages to keep |
-> LoggingT m a | |
-> LoggingT m a |
Within the LoggingT
monad, capture all log messages to a bounded
channel of the indicated size, and only actually log them if there is an
exception.
Since: monad-logger-0.3.2
filterLogger :: (LogSource -> LogLevel -> Bool) -> LoggingT m a -> LoggingT m a Source #
Only log messages passing the given predicate function.
This can be a convenient way, for example, to ignore debug level messages.
Since: monad-logger-0.3.13
newtype NoLoggingT m a Source #
Monad transformer that disables logging.
Since: monad-logger-0.2.4
NoLoggingT | |
|
Instances
mapNoLoggingT :: (m a -> n b) -> NoLoggingT m a -> NoLoggingT n b Source #
Map the unwrapped computation using the given function.
Since: monad-logger-0.3.29
newtype WriterLoggingT m a Source #
Since: monad-logger-0.3.28
WriterLoggingT | |
|
Instances
execWriterLoggingT :: Functor m => WriterLoggingT m a -> m [LogLine] Source #
Run a block using a MonadLogger
instance. Return logs in a list
| @since 0.3.28
runWriterLoggingT :: Functor m => WriterLoggingT m a -> m (a, [LogLine]) Source #
Run a block using a MonadLogger
instance. Return a value and logs in a list
| @since 0.3.28
mapLoggingT :: (m a -> n b) -> LoggingT m a -> LoggingT n b Source #
Map the unwrapped computation using the given function.
Since: monad-logger-0.3.29
TH logging
Generates a function that takes a Text
and logs a LevelDebug
message. Usage:
$(logDebug) "This is a debug log message"
logOther :: Text -> Q Exp Source #
Generates a function that takes a Text
and logs a LevelOther
message. Usage:
$(logOther "My new level") "This is a log message"
TH logging of showable values
logDebugSH :: Q Exp Source #
Generates a function that takes a 'Show a => a' and logs a LevelDebug
message. Usage:
$(logDebugSH) (Just "This is a debug log message")
Since: monad-logger-0.3.18
logErrorSH :: Q Exp Source #
See logDebugSH
logOtherSH :: Text -> Q Exp Source #
Generates a function that takes a 'Show a => a' and logs a LevelOther
message. Usage:
$(logOtherSH "My new level") "This is a log message"
TH logging with source
Generates a function that takes a LogSource
and Text
and logs a LevelDebug
message. Usage:
$logDebugS "SomeSource" "This is a debug log message"
Generates a function that takes a LogSource
, a level name and a Text
and logs a LevelOther
message. Usage:
$logOtherS "SomeSource" "My new level" "This is a log message"
TH util
Non-TH logging
logDebugN :: MonadLogger m => Text -> m () Source #
logInfoN :: MonadLogger m => Text -> m () Source #
logWarnN :: MonadLogger m => Text -> m () Source #
logErrorN :: MonadLogger m => Text -> m () Source #
Non-TH logging with source
logWithoutLoc :: (MonadLogger m, ToLogStr msg) => LogSource -> LogLevel -> msg -> m () Source #
Since: monad-logger-0.3.23
logDebugNS :: MonadLogger m => Text -> Text -> m () Source #
logErrorNS :: MonadLogger m => Text -> Text -> m () Source #
logOtherNS :: MonadLogger m => Text -> LogLevel -> Text -> m () Source #
Callstack logging
logDebugCS :: MonadLogger m => CallStack -> Text -> m () Source #
logInfoCS :: MonadLogger m => CallStack -> Text -> m () Source #
See logDebugCS
Since: monad-logger-0.3.19
logWarnCS :: MonadLogger m => CallStack -> Text -> m () Source #
See logDebugCS
Since: monad-logger-0.3.19
logErrorCS :: MonadLogger m => CallStack -> Text -> m () Source #
See logDebugCS
Since: monad-logger-0.3.19
logOtherCS :: MonadLogger m => CallStack -> LogLevel -> Text -> m () Source #
See logDebugCS
Since: monad-logger-0.3.19
utilities for defining your own loggers
Loc | |
|
Instances
Eq Loc | |
Data Loc | |
Defined in Language.Haskell.TH.Syntax gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Loc -> c Loc # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Loc # dataTypeOf :: Loc -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Loc) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Loc) # gmapT :: (forall b. Data b => b -> b) -> Loc -> Loc # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Loc -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Loc -> r # gmapQ :: (forall d. Data d => d -> u) -> Loc -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Loc -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Loc -> m Loc # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Loc -> m Loc # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Loc -> m Loc # | |
Ord Loc | |
Show Loc | |
Generic Loc | |
type Rep Loc | |
Defined in Language.Haskell.TH.Syntax type Rep Loc = D1 (MetaData "Loc" "Language.Haskell.TH.Syntax" "template-haskell" False) (C1 (MetaCons "Loc" PrefixI True) ((S1 (MetaSel (Just "loc_filename") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String) :*: S1 (MetaSel (Just "loc_package") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String)) :*: (S1 (MetaSel (Just "loc_module") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 String) :*: (S1 (MetaSel (Just "loc_start") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 CharPos) :*: S1 (MetaSel (Just "loc_end") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 CharPos))))) |
defaultLoc :: Loc Source #
dummy location, used with logWithoutLoc
Since: monad-logger-0.3.23