wai-logger-buffered-0.1.0.1: Buffer requets before logging them

Copyright(c) 2017 Chris Coffey
LicenseMIT
MaintainerChris Coffey <chris@foldl.io>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Network.Wai.Logging.Buffered

Contents

Description

Middleware for buffering log messages instead of immediately writing them to a handle.

This allows easy integration with tools providing bulk publish apis like Graphite or Elasticsearch.

   main :: IO ()
   main = do
     forkIO $ runBufferedRequestLogger def
     run 8080 $ bufferedRequestLogger def waiApplication

A note about wildcards: the * wildcard is used to collapse similar URLs for easier reporting on external platforms.

Synopsis

Types

data Config Source #

Configuration arguments for draining the buffer

Constructors

Config 

Fields

  • maxSize :: Int

    The maximum size allowed for the buffer. After this is hit messages are pushed to stdOut. Defaults to 1000

  • publishIntervalSeconds :: Int

    How frequently to publish events to the sink. Defaults to 10 (seconds)

  • pubFunc :: Publish

    The sink function. Defaults to print

  • useWildcards :: Bool

    Determines whether to publish the original path and a * wildcarded version. Defaults to True

Instances

data Event Source #

Tracks a single Request

Constructors

Event 

Fields

Instances

Eq Event Source # 

Methods

(==) :: Event -> Event -> Bool #

(/=) :: Event -> Event -> Bool #

Ord Event Source # 

Methods

compare :: Event -> Event -> Ordering #

(<) :: Event -> Event -> Bool #

(<=) :: Event -> Event -> Bool #

(>) :: Event -> Event -> Bool #

(>=) :: Event -> Event -> Bool #

max :: Event -> Event -> Event #

min :: Event -> Event -> Event #

Show Event Source # 

Methods

showsPrec :: Int -> Event -> ShowS #

show :: Event -> String #

showList :: [Event] -> ShowS #

type Publish = [Event] -> IO () Source #

$setup

>>> :set -XOverloadedStrings
>>> import qualified Data.Map as M
>>> import Data.Time.Clock
>>> now <- getCurrentTime
>>> let events = Event "dummy" now <$> [1..]

A log sink.

Functions

bufferedRequestLogger :: Config -> Middleware Source #

Collect timing on all Requests and add them to the buffer. Configuration is controlled via the provided Config

runBufferedRequestLogger :: Config -> IO () Source #

Based on the provided Config publishes the logged requests & drains the buffer. The ideal configuration depends on your workload, but know that each request is stored as is. I.e. if you handle 1k req/s, then you should make sure 'maxSize'/'publishIntervalSeconds' > 1000.