Copyright | (c) Dong Han 2017-2018 |
---|---|
License | BSD |
Maintainer | winterland1989@gmail.com |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
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
Builder
s into a smallBytes
with line buffer instead of leaving allBuilder
s 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
- data Logger
- data LoggerConfig = LoggerConfig {
- loggerMinFlushInterval :: !Int
- loggerTsCache :: IO (Builder ())
- loggerLineBufSize :: !Int
- loggerShowDebug :: Bool
- loggerShowTS :: Bool
- newLogger :: Output o => LoggerConfig -> MVar (BufferedOutput o) -> IO Logger
- loggerFlush :: Logger -> IO ()
- setStdLogger :: Logger -> IO ()
- getStdLogger :: IO Logger
- withStdLogger :: IO () -> IO ()
- debug :: Builder () -> IO ()
- info :: Builder () -> IO ()
- warn :: Builder () -> IO ()
- fatal :: Builder () -> IO ()
- otherLevel :: Builder () -> Bool -> Builder () -> IO ()
- debugWith :: Logger -> Builder () -> IO ()
- infoWith :: Logger -> Builder () -> IO ()
- warnWith :: Logger -> Builder () -> IO ()
- fatalWith :: Logger -> Builder () -> IO ()
- otherLevelWith :: Logger -> Builder () -> Bool -> Builder () -> IO ()
A simple Logger type
data LoggerConfig Source #
LoggerConfig | |
|
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.