HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulemonad-logger-0.3.42Haskell2010

Control.Monad.Logger

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.

  • 8 types
  • 3 classes
  • 47 values

MonadLogger

5 declarations
classclass Monad m => MonadLogger (m :: Type -> Type) where
#

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

Methods

Instances17MonadLogger, …
classclass (MonadLogger m, MonadIO m) => MonadLoggerIO (m :: Type -> Type) where
#

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.

Methods

Instances16MonadLoggerIO, …

Re-export from fast-logger

3 declarations
datadata LogStr
#

Log message builder. Use (<>) to append two LogStr in O(1).

Instances6Eq, Show, IsString, Semigroup, Monoid, ToLogStr
  • Eq LogStrDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • Show LogStrDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • IsString LogStrDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • Semigroup LogStrDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • Monoid LogStrDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr LogStrDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
classclass ToLogStr msg where
#

Types that can be converted to a LogStr. Instances for types from the text library use a UTF-8 encoding. Instances for numerical types use a decimal encoding.

Methods

Instances21ToLogStr, …
  • ToLogStr BuilderDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr ByteStringDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr ByteStringDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr ShortByteStringDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr LogStrDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr IntegerDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr StringDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr Int16Defined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr Int32Defined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr Int64Defined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr Int8Defined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr Word16Defined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr Word32Defined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr Word64Defined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr Word8Defined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr DoubleDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr FloatDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr IntDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr WordDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr TextDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr
  • ToLogStr TextDefined in fast-logger-3.2.6 · System.Log.FastLogger.LogStr

Helper transformers

14 declarations
newtypenewtype LoggingT (m :: Type -> Type) a
#

Monad transformer that adds a new logging function.

Constructors

Instances29MonadTrans, MonadTransControl, MonadRWS, MonadAccum, MonadError, MonadReader, …
valuerunChanLoggingT :: MonadIO m => Chan LogLine -> LoggingT m a -> m a
#

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.

newtypenewtype NoLoggingT (m :: Type -> Type) a
#

Monad transformer that disables logging.

Constructors

Instances27MonadTrans, MonadTransControl, MonadAccum, MonadError, MonadReader, MonadState, …
newtypenewtype WriterLoggingT (m :: Type -> Type) a
#

Constructors

Instances16MonadTrans, MonadTransControl, MonadBase, MonadBaseControl, Monad, Functor, …

TH logging

5 declarations
valuelogDebug :: Q Exp
#

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

$(logDebug) "This is a debug log message"
valuelogOther :: Text -> Q Exp
#

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

5 declarations
valuelogDebugSH :: Q Exp
#

Generates a function that takes a 'Show a => a' and logs a LevelDebug message. Usage:

$(logDebugSH) (Just "This is a debug log message")
valuelogOtherSH :: Text -> Q Exp
#

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

5 declarations
valuelogOtherS :: Q Exp
#

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

1 declaration

Non-TH logging

5 declarations

Non-TH logging with source

6 declarations

Callstack logging

5 declarations

utilities for defining your own loggers

4 declarations
Loc

When monad-logger is compiled with the template_haskell flag set to true (the default), the Loc below is a re-export from the template-haskell package. When the flag is false, the Loc below is a copy of that data structure defined in monad-logger itself.

If you are making a library that:

  • Uses monad-logger

  • Uses Loc in a type signature

  • But doesn't need to depend on template-haskell for other reasons

You can import Loc directly from this package, instead of adding an dependency on template-haskell and importing from there. This allows users to compile your package in environments that don't support template-haskell.

datadata Loc
#
Instances7Eq, Data, Ord, Show, Generic, Ppr, …