monad-logger-0.3.13.1: A class of monads which can log messages.

Safe HaskellNone
LanguageHaskell98

Control.Monad.Logger

Contents

Description

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 GHandler 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

MonadLogger

class Monad m => MonadLogger m where Source

A Monad which has the ability to log messages in some manner.

Methods

monadLoggerLog :: ToLogStr msg => 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 transfomrer stacks, as an example.

Since 0.3.10

Minimal complete definition

Nothing

Methods

askLoggerIO :: m (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) Source

Request the logging function itself.

Since 0.3.10

type LogSource = Text Source

Re-export from fast-logger

class ToLogStr msg where

Methods

toLogStr :: msg -> LogStr

Helper transformer

newtype LoggingT m a Source

Monad transformer that adds a new logging function.

Since 0.2.2

Constructors

LoggingT 

Fields

runLoggingT :: (Loc -> LogSource -> LogLevel -> LogStr -> IO ()) -> m a
 

Instances

MonadTrans LoggingT 
MonadTransControl LoggingT 
MonadRWS r w s m => MonadRWS r w s (LoggingT m) 
MonadBaseControl b m => MonadBaseControl b (LoggingT m) 
MonadBase b m => MonadBase b (LoggingT m) 
MonadError e m => MonadError e (LoggingT m) 
MonadWriter w m => MonadWriter w (LoggingT m) 
MonadState s m => MonadState s (LoggingT m) 
MonadReader r m => MonadReader r (LoggingT m) 
Monad m => Monad (LoggingT m) 
Monad m => Functor (LoggingT m) 
Monad m => Applicative (LoggingT m) 
MonadIO m => MonadIO (LoggingT m) 
MonadResource m => MonadResource (LoggingT m) 
MonadThrow m => MonadThrow (LoggingT m) 
MonadMask m => MonadMask (LoggingT m) 
MonadCatch m => MonadCatch (LoggingT m) 
MonadCont m => MonadCont (LoggingT m) 
MonadActive m => MonadActive (LoggingT m) 
MonadIO m => MonadLoggerIO (LoggingT m) 
MonadIO m => MonadLogger (LoggingT m) 
data StT LoggingT = StReader {} 
data StM (LoggingT m) = StMT (StM m a) 

runStderrLoggingT :: MonadIO m => LoggingT m a -> m a Source

Run a block using a MonadLogger instance which prints to stderr.

Since 0.2.2

runStdoutLoggingT :: MonadIO m => LoggingT m a -> m a Source

Run a block using a MonadLogger instance which prints to stdout.

Since 0.2.2

withChannelLogger Source

Arguments

:: (MonadBaseControl IO m, MonadIO m) 
=> Int

Number of mesasges 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 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 0.3.13

newtype NoLoggingT m a Source

Monad transformer that disables logging.

Since 0.2.4

Constructors

NoLoggingT 

Fields

runNoLoggingT :: m a
 

Instances

MonadTrans NoLoggingT 
MonadTransControl NoLoggingT 
MonadBaseControl b m => MonadBaseControl b (NoLoggingT m) 
MonadBase b m => MonadBase b (NoLoggingT m) 
MonadError e m => MonadError e (NoLoggingT m) 
MonadWriter w m => MonadWriter w (NoLoggingT m) 
MonadState s m => MonadState s (NoLoggingT m) 
Monad m => Monad (NoLoggingT m) 
Monad m => Functor (NoLoggingT m) 
Monad m => Applicative (NoLoggingT m) 
MonadIO m => MonadIO (NoLoggingT m) 
MonadResource m => MonadResource (NoLoggingT m) 
MonadThrow m => MonadThrow (NoLoggingT m) 
MonadMask m => MonadMask (NoLoggingT m) 
MonadCatch m => MonadCatch (NoLoggingT m) 
MonadActive m => MonadActive (NoLoggingT m) 
MonadIO m => MonadLoggerIO (NoLoggingT m) 
Monad m => MonadLogger (NoLoggingT m) 
data StT NoLoggingT = StIdent {} 
data StM (NoLoggingT m) = StMT' (StM m a) 

TH logging

logDebug :: Q Exp Source

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 with source

logDebugS :: Q Exp Source

Generates a function that takes a LogSource and Text and logs a LevelDebug message. Usage:

$logDebugS "SomeSource" "This is a debug log message"

logOtherS :: Q Exp Source

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

liftLoc :: Loc -> Q Exp Source

Lift a location into an Exp.

Since 0.3.1

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

logOtherN :: MonadLogger m => LogLevel -> Text -> m () Source

Non-TH logging with source

logDebugNS :: MonadLogger m => Text -> Text -> m () Source

logInfoNS :: MonadLogger m => Text -> Text -> m () Source

logWarnNS :: MonadLogger m => Text -> Text -> m () Source

logErrorNS :: MonadLogger m => Text -> Text -> m () Source

logOtherNS :: MonadLogger m => Text -> LogLevel -> Text -> m () Source

utilities for defining your own loggers

data Loc :: *