| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Control.Monad.Logger.Logstash
Contents
Description
This module implements runLogstashLoggerT 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
runLogstashLoggerT 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
runLogstashLoggerT 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
- runLogstashLoggerT :: LogstashContext ctx => ctx -> RetryPolicyM IO -> Integer -> (RetryStatus -> (Loc, LogSource, LogLevel, LogStr) -> ReaderT LogstashConnection IO ()) -> LoggingT m a -> m a
- stashJsonLine :: (Loc, LogSource, LogLevel, LogStr) -> ReaderT LogstashConnection IO ()
- withLogstashLoggerT :: (LogstashContext ctx, MonadUnliftIO m) => LogstashQueueCfg ctx -> (RetryStatus -> (Loc, LogSource, LogLevel, LogStr) -> ReaderT LogstashConnection IO ()) -> [(Loc, LogSource, LogLevel, LogStr) -> Handler ()] -> LoggingT m a -> m a
- class LogstashContext ctx where
- runLogstash :: (MonadMask m, MonadUnliftIO m) => ctx -> RetryPolicyM m -> Integer -> (RetryStatus -> ReaderT LogstashConnection m a) -> m a
Documentation
runLogstashLoggerT :: LogstashContext ctx => ctx -> RetryPolicyM IO -> Integer -> (RetryStatus -> (Loc, LogSource, LogLevel, LogStr) -> ReaderT LogstashConnection IO ()) -> LoggingT m a -> m a Source #
runLogstashLoggerT 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.
withLogstashLoggerT :: (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 #
withLogstashLoggerT cfg codec exceptionHandlers logger is like
withLogstashQueue except for LoggingT computations so that log messages
are automatically added to the queue.
Re-exports
class LogstashContext ctx where #
A type class of types that provide Logstash connections.
Methods
runLogstash :: (MonadMask m, MonadUnliftIO m) => ctx -> RetryPolicyM m -> Integer -> (RetryStatus -> ReaderT LogstashConnection m a) -> m a #
Instances
| LogstashContext LogstashPool | |
Defined in Logstash Methods runLogstash :: (MonadMask m, MonadUnliftIO m) => LogstashPool -> RetryPolicyM m -> Integer -> (RetryStatus -> ReaderT LogstashConnection m a) -> m a # | |
| LogstashContext (Acquire LogstashConnection) | |
Defined in Logstash Methods runLogstash :: (MonadMask m, MonadUnliftIO m) => Acquire LogstashConnection -> RetryPolicyM m -> Integer -> (RetryStatus -> ReaderT LogstashConnection m a) -> m a # | |