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

Modulelog-effectful-1.0.0.0Haskell2010

Effectful.Log

Logging via MonadLog.

  • 8 types
  • 1 class
  • 24 values

Effect

1 declaration

Handlers

valuerunLog
  1. :: IOE :> es
  2. => Text

    Application component name to use.

  3. -> Logger

    The logging back-end to use.

  4. -> LogLevel

    The maximum log level allowed to be logged.

  5. -> Eff (Log ': es) a

    The computation to run.

  6. -> Eff es a
#

Run the Log effect.

Note: this is the effectful version of runLogT.

Re-exports

32 declarations
datadata Logger
#

An object used for communication with a logger thread that outputs LogMessages using e.g. PostgreSQL, Elasticsearch or stdout (depending on the back-end chosen).

Instances2Semigroup, Monoid
datadata LogLevel
#

Available log levels. Note that ordering in this definintion determines what the maximum log level is. See Log.Monad.leMaxLogLevel.

Instances7Bounded, Eq, Ord, Show, NFData, FromJSON, …
classclass Monad m => MonadLog (m :: Type -> Type) where
#

Represents the family of monads with logging capabilities. Each MonadLog carries with it some associated state (the logging environment) that can be modified locally with localData and localDomain.

Methods

Instances3MonadLog
datadata UTCTime
#

This is the simplest representation of UTC. It consists of the day number, and a time offset from midnight. Note that if a day has a leap second added to it, it will have 86401 seconds.

Instances17Eq, Data, Ord, Read, Show, Generic, …
valuelogInfo :: (MonadLog m, ToJSON a) => Text -> a -> m ()
#

Log a message and its associated data using current time as the event time and the LogInfo log level.

datadata LogMessage
#

Represents message to be logged.

Constructors

Instances5Eq, Show, NFData, FromJSON, ToJSON
valueshutdownLogger :: Logger -> IO ()
#

Shutdown the logger thread associated with this Logger object. Subsequent attempts to write messages via this Logger will result in an exception.

valuemkBulkLogger :: Text -> ([LogMessage] -> IO ()) -> IO () -> IO Logger
#

Start an asynchronous logger thread that consumes all queued messages once per second.

Note: a bounded queue of size 1000000 is used internally to avoid unrestricted memory consumption.

To make sure that the messages get written out in the presence of exceptions, use high-level wrappers like withLogger, Log.Backend.ElasticSearch.withElasticSearchLogger or withBulkStdOutLogger instead of this function directly.

Note: some messages can be lost when the main thread shuts down without making sure that all logger threads have written out all messages, because in that case child threads are not given a chance to clean up by the RTS. This is apparently a feature: https://mail.haskell.org/pipermail/haskell-cafe/2014-February/112754.html

To work around this issue, make sure that the main thread doesn't exit until all its children have terminated. The async package makes this easy.

Problematic example:

import Control.Concurrent.Async

main :: IO ()
main = do
   logger <- Log.Backend.ElasticSearch.elasticSearchLogger
   a <- Control.Concurrent.Async.async (Log.Backend.ElasticSearch.withElasticSearchLogger $ \logger ->
               runLogT "main" logger defaultLogLevel $ logTrace_ "foo")
   -- Main thread exits without waiting for the child
   -- to finish and without giving the child a chance
   -- to do proper cleanup.

Fixed example:

import Control.Concurrent.Async

main :: IO ()
main = do
   logger <- Log.Backend.ElasticSearch.elasticSearchLogger
   a <- Control.Concurrent.Async.async (Log.Backend.ElasticSearch.withElasticSearchLogger $ \logger ->
               runLogT "main" logger defaultLogLevel $ logTrace_ "foo")
   Control.Concurrent.Async.wait a
   -- Main thread waits for the child to finish, giving
   -- it a chance to shut down properly. This works even
   -- in the presence of exceptions in the child thread.
valuemkLogger :: Text -> (LogMessage -> IO ()) -> IO Logger
#

Start a logger thread that consumes one queued message at a time.

Note: a bounded queue of size 1000000 is used internally to avoid unrestricted memory consumption.

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

Monad transformer that adds logging capabilities to the underlying monad.

Constructors

Instances23MonadTrans, MonadTransControl, MFunctor, MonadError, MonadReader, MonadState, …
valuegetLoggerIO :: MonadLog m => m (UTCTime -> LogLevel -> Text -> Value -> IO ())
#

Return an IO action that logs messages using the current MonadLog context. Useful for interfacing with libraries such as aws or amazonka that accept logging callbacks operating in IO.

valuerunLogT
  1. :: Text

    Application component name to use.

  2. -> Logger

    The logging back-end to use.

  3. -> LogLevel

    The maximum log level allowed to be logged. Only messages less or equal than this level with be logged.

  4. -> LogT m a

    The LogT computation to run.

  5. -> m a
#

Run a LogT computation.

Note that in the case of asynchronous/bulk loggers runLogT doesn't guarantee that all messages are actually written to the log once it finishes. Use withPGLogger or withElasticSearchLogger for that.

valueobject :: [Pair] -> Value
#

Create a Value from a list of name/value Pairs. If duplicate keys arise, later keys and their associated values win.

Orphan instances

1 instance