| Copyright | (c) Dong Han 2017-2018 |
|---|---|
| License | BSD |
| Maintainer | winterland1989@gmail.com |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Std.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. - A logger connected to stderr,
setStdLoggerare always available. - Each logging thread are responsible for building log
Builders into a smallByteswith line buffer instead of leaving allBuilders 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
Bytesinto 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
- data Logger
- data LoggerConfig = LoggerConfig {
- loggerMinFlushInterval :: !Int
- loggerTsCache :: IO (Builder ())
- loggerLineBufSize :: !Int
- loggerShowDebug :: Bool
- loggerShowTS :: Bool
- newLogger :: Output o => LoggerConfig -> 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 #
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.
getStdLogger :: IO Logger Source #
withStdLogger :: IO () -> IO () Source #
Flush stderr logger when program exits.