Safe Haskell | None |
---|---|
Language | Haskell2010 |
Small layer on top of fast-logger
which adds log-levels and
timestamp support and not much more.
- data Settings
- defSettings :: Settings
- logLevel :: Settings -> Level
- setLogLevel :: Level -> Settings -> Settings
- logLevelOf :: Text -> Settings -> Maybe Level
- setLogLevelOf :: Text -> Level -> Settings -> Settings
- output :: Settings -> Output
- setOutput :: Output -> Settings -> Settings
- format :: Settings -> DateFormat
- setFormat :: DateFormat -> Settings -> Settings
- delimiter :: Settings -> ByteString
- setDelimiter :: ByteString -> Settings -> Settings
- netstrings :: Settings -> Bool
- setNetStrings :: Bool -> Settings -> Settings
- bufSize :: Settings -> Int
- setBufSize :: Int -> Settings -> Settings
- name :: Settings -> Maybe Text
- setName :: Maybe Text -> Settings -> Settings
- data Logger
- data Level
- data Output
- data DateFormat
- iso8601UTC :: DateFormat
- new :: MonadIO m => Settings -> m Logger
- create :: MonadIO m => Output -> m Logger
- level :: Logger -> Level
- flush :: MonadIO m => Logger -> m ()
- close :: MonadIO m => Logger -> m ()
- clone :: Maybe Text -> Logger -> Logger
- settings :: Logger -> Settings
- log :: MonadIO m => Logger -> Level -> (Msg -> Msg) -> m ()
- trace :: MonadIO m => Logger -> (Msg -> Msg) -> m ()
- debug :: MonadIO m => Logger -> (Msg -> Msg) -> m ()
- info :: MonadIO m => Logger -> (Msg -> Msg) -> m ()
- warn :: MonadIO m => Logger -> (Msg -> Msg) -> m ()
- err :: MonadIO m => Logger -> (Msg -> Msg) -> m ()
- fatal :: MonadIO m => Logger -> (Msg -> Msg) -> m ()
Settings
defSettings :: Settings Source
Default settings:
logLevel
=Debug
output
=StdOut
format
=iso8601UTC
delimiter
= ", "netstrings
= FalsebufSize
=defaultBufSize
name
= Nothing
setLogLevel :: Level -> Settings -> Settings Source
setLogLevelOf :: Text -> Level -> Settings -> Settings Source
Specify a log level for the given named logger. When a logger is
clone
d and given a name, the logLevel
of the cloned logger will be
the provided here.
format :: Settings -> DateFormat Source
The time and date format used for the timestamp part of a log line.
setFormat :: DateFormat -> Settings -> Settings Source
delimiter :: Settings -> ByteString Source
Delimiter string which separates log line parts.
setDelimiter :: ByteString -> Settings -> Settings Source
netstrings :: Settings -> Bool Source
Whether to use netstring encoding for log lines.
setNetStrings :: Bool -> Settings -> Settings Source
setBufSize :: Int -> Settings -> Settings Source
Type definitions
iso8601UTC :: DateFormat Source
ISO 8601 date-time format.
Core API
new :: MonadIO m => Settings -> m Logger Source
Create a new Logger
with the given Settings
.
Please note that the logLevel
can be dynamically adjusted by setting
the environment variable LOG_LEVEL
accordingly. Likewise the buffer
size can be dynamically set via LOG_BUFFER
and netstrings encoding
can be enabled with LOG_NETSTR=True
Since version 0.11 one can also use LOG_LEVEL_MAP
to specify log
levels per (named) logger. The syntax uses standard haskell syntax for
association lists of type [(Text, Level)]
. For example:
$ LOG_LEVEL=Info LOG_LEVEL_MAP='[("foo", Warn), ("bar", Trace)]' cabal repl > g1 <- new defSettings > let g2 = clone (Just "foo") g > let g3 = clone (Just "bar") g > let g4 = clone (Just "xxx") g > logLevel (settings g1) Info > logLevel (settings g2) Warn > logLevel (settings g3) Trace > logLevel (settings g4) Info
create :: MonadIO m => Output -> m Logger Source
Invokes new
with default settings and the given output as log sink.
clone :: Maybe Text -> Logger -> Logger Source
Clone the given logger and optionally give it a name
(use Nothing
to clear).
If logLevelOf
returns a custom Level
for this name
then the cloned logger will use it for its log messages.
Logging
log :: MonadIO m => Logger -> Level -> (Msg -> Msg) -> m () Source
Logs a message with the given level if greater or equal to the logger's threshold.
trace :: MonadIO m => Logger -> (Msg -> Msg) -> m () Source
Abbreviation of log
using the corresponding log level.
debug :: MonadIO m => Logger -> (Msg -> Msg) -> m () Source
Abbreviation of log
using the corresponding log level.
info :: MonadIO m => Logger -> (Msg -> Msg) -> m () Source
Abbreviation of log
using the corresponding log level.
warn :: MonadIO m => Logger -> (Msg -> Msg) -> m () Source
Abbreviation of log
using the corresponding log level.