monad-logger-logstash-0.2.0.1: Logstash backend for monad-logger.
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Logger.Logstash

Contents

Description

This module implements runLogstashLoggingT which can be used to write log messages that arise in a LoggingT computation to a given LogstashContext. The following example demonstrates how to use the runLogstashLoggingT function with a TCP connection to Logstash, the default retry policy from Retry, a 1s timeout for each attempt, and the json_lines codec:

main :: IO ()
main = do 
   let ctx = logstashTcp def
   runLogstashLoggingT ctx retryPolicyDefault 1000000 (const stashJsonLine) $ 
        logInfoN "Hello World"

Assuming a suitable Logstash server that can receive this message, something like the following JSON document should be indexed (see the documentation for Logger for information about how to include more information in log messages):

{ 
   "@version":"1",
   "message":"Hello World",
   "log.origin.file.line":0,
   "log.origin.file.module":"<unknown>",
   "log.origin.file.package":"<unknown>",
   "log.origin.file.start.column":0,
   "log.origin.file.start.line":0,
   "log.origin.file.end.column":0,
   "log.origin.file.end.line":0,
   "log.origin.file.name":"<unknown>",
   "log.logger":"",
   "log.level":"info"
}

If an error or a timeout occurs while writing to the Logstash connection, the retry policy determines whether and when sending the message is attempted again. If all attempts fail, the most recent exception is thrown to the caller.

Synopsis

Documentation

runLogstashLoggingT :: LogstashContext ctx => ctx -> RetryPolicyM IO -> Integer -> (RetryStatus -> (Loc, LogSource, LogLevel, LogStr) -> ReaderT LogstashConnection IO ()) -> LoggingT m a -> m a Source #

runLogstashLoggingT context retryPolicy time codec logger runs a LoggingT computation which writes all log entries to the Logstash context using the given codec. The retryPolicy determines whether and how the handler should deal with failures that arise. Each attempt that is made by the retryPolicy will have a timeout of time microseconds applied to it.

stashJsonLine :: (Loc, LogSource, LogLevel, LogStr) -> ReaderT LogstashConnection IO () Source #

stashJsonLine entry serialises entry as JSON using reasonable defaults for Elasticsearch based on https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html and sends the result to Logstash using the json_lines codec.

jsonLogLine :: (Loc, LogSource, LogLevel, LogStr) -> Value Source #

jsonLogLine entry serialises entry as JSON using reasonable defaults for Elasticsearch based on https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html

withLogstashLoggingT :: (LogstashContext ctx, MonadUnliftIO m) => LogstashQueueCfg ctx -> (RetryStatus -> (Loc, LogSource, LogLevel, LogStr) -> ReaderT LogstashConnection IO ()) -> [(Loc, LogSource, LogLevel, LogStr) -> Handler ()] -> LoggingT m a -> m a Source #

withLogstashLoggingT cfg codec exceptionHandlers logger is like withLogstashQueue except for LoggingT computations so that log messages are automatically added to the queue.

runTBMQueueLoggingT :: MonadUnliftIO m => TBMQueue (Loc, LogSource, LogLevel, LogStr) -> LoggingT m a -> m a Source #

runTBMQueueLoggingT queue logger runs logger so that log messages are automatically added to queue. This can be used if the same queue and consumer should be shared among multiple producer threads. The queue should be initialised by withLogstashQueue.

unTBMQueueLoggingT :: (MonadIO m, MonadLogger m) => TBMQueue (Loc, LogSource, LogLevel, LogStr) -> m () Source #

unTBMQueueLoggingT queue is like unChanLoggingT but for a TBMQueue. Since a TBMQueue can be closed, this function does not run forever like unChanLoggingT and will return when queue is closed.

Re-exports

class LogstashContext ctx where #

A type class of types that provide Logstash connections.

Instances

Instances details
LogstashContext LogstashPool 
Instance details

Defined in Logstash

LogstashContext (Acquire LogstashConnection) 
Instance details

Defined in Logstash