stdio-0.2.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

Std.IO.Logger

Contents

Description

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

  • All log functions lives in IO.
  • A logger connected to stderr, setStdLogger are always available.
  • Each logging thread are responsible for building log Builders into a small Bytes with line buffer instead of leaving all Builders to the flushing thread so that:
  • We won't keep garbage 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 is atomic, Logging order is preserved under concurrent settings.

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

import Std.IO.Logger

main :: IO ()
main = withStdLogger $ do
    ....
Synopsis

A simple Logger type

data LoggerConfig Source #

Logger configuration.

Constructors

LoggerConfig 

Fields

newLogger :: Output o => LoggerConfig -> 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 stderr 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

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

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

otherLevelWith Source #

Arguments

:: Logger 
-> Builder ()

log level

-> Bool

flush immediately?

-> Builder ()

log content

-> IO ()