Z-IO-0.1.0.0: A simple and high performance IO toolkit for Haskell
Copyright(c) Dong Han 2017-2018
LicenseBSD
Maintainerwinterland1989@gmail.com
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Z.IO.Logger

Description

Simple, high performance logger. The design choice of this logger is biased towards simplicity instead of generlization:

  • All log functions lives in IO.
  • By default this logger is connected to stderr, use setStdLogger to customize.
  • When logging each thread will build log Builders into a small Bytes with line buffer instead of leaving all Builders to the flushing thread:
  • Logger won't keep heap data for too long simply because they're referenced by log's Builder.
  • Each logging thread only need perform a CAS to prepend log Bytes into a list, which reduces contention.
  • Each log call is atomic, Logging order is preserved under concurrent settings.

Flushing is automatic and throttled for debug, info, warn to boost performance, but a fatal log will always flush logger's buffer. This could lead to a problem that if main thread exits too early logs may missed, to add a flushing when program exits, use withStdLogger like:

import Z.IO.Logger

main :: IO ()
main = withStdLogger $ do
    ....
    debug "..."   -- So that this log won't be missed
    ...
Synopsis

A simple Logger type

data LoggerConfig Source #

Constructors

LoggerConfig 

Fields

newLogger :: Output o => LoggerConfig -> MVar (BufferedOutput o) -> IO Logger Source #

Make a new logger

loggerFlush :: Logger -> IO () Source #

flush logger's buffer to output device

setStdLogger :: Logger -> IO () Source #

Change the global logger.

getStdLogger :: IO Logger Source #

Get the global logger.

withStdLogger :: IO () -> IO () Source #

Flush stderr logger when program exits.

logging functions

debug :: Builder () -> IO () Source #

info :: Builder () -> IO () Source #

warn :: Builder () -> IO () Source #

fatal :: Builder () -> IO () Source #

otherLevel Source #

Arguments

:: Builder ()

log level

-> Bool

flush immediately?

-> Builder ()

log content

-> IO () 

logging functions with specific logger

debugWith :: Logger -> Builder () -> IO () Source #

infoWith :: Logger -> Builder () -> IO () Source #

warnWith :: Logger -> Builder () -> IO () Source #

fatalWith :: Logger -> Builder () -> IO () Source #

otherLevelWith Source #

Arguments

:: Logger 
-> Builder ()

log level

-> Bool

flush immediately?

-> Builder ()

log content

-> IO ()