| Copyright | (c) 2017 Chris Coffey |
|---|---|
| License | MIT |
| Maintainer | Chris Coffey <chris@foldl.io> |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Network.Wai.Logging.Buffered
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.
- data Config = Config {}
- data Event = Event {
- path :: !ByteString
- reportedTime :: !UTCTime
- duration :: !NominalDiffTime
- type Publish = [Event] -> IO ()
- bufferedRequestLogger :: Config -> Middleware
- runBufferedRequestLogger :: Config -> IO ()
Types
Configuration arguments for draining the buffer
Constructors
| Config | |
Fields
| |
Tracks a single Request
Constructors
| Event | |
Fields
| |
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
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.