Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides a fast logging system which scales on multicore environments (i.e. +RTS -N<x>).
Note: This library does not guarantee correct ordering of log messages when program is run on more than one core thus users should rely more on message timestamps than on their order in the log.
Synopsis
- type FastLogger = LogStr -> IO ()
- type LogType = LogType' LogStr
-
data
LogType'
a
where
- LogNone :: LogType' LogStr
- LogStdout :: BufSize -> LogType' LogStr
- LogStderr :: BufSize -> LogType' LogStr
- LogFileNoRotate :: FilePath -> BufSize -> LogType' LogStr
- LogFile :: FileLogSpec -> BufSize -> LogType' LogStr
- LogFileTimedRotate :: TimedFileLogSpec -> BufSize -> LogType' LogStr
- LogCallback :: (v -> IO ()) -> IO () -> LogType' v
- newFastLogger :: LogType' v -> IO (v -> IO (), IO ())
- newFastLogger1 :: LogType' v -> IO (v -> IO (), IO ())
- withFastLogger :: LogType -> ( FastLogger -> IO a) -> IO a
- type TimedFastLogger = ( FormattedTime -> LogStr ) -> IO ()
- newTimedFastLogger :: IO FormattedTime -> LogType -> IO ( TimedFastLogger , IO ())
- withTimedFastLogger :: IO FormattedTime -> LogType -> ( TimedFastLogger -> IO a) -> IO a
- data LogStr
- class ToLogStr msg where
- fromLogStr :: LogStr -> ByteString
- logStrLength :: LogStr -> Int
- type BufSize = Int
- defaultBufSize :: BufSize
- module System.Log.FastLogger.LoggerSet
- module System.Log.FastLogger.Date
- module System.Log.FastLogger.File
- module System.Log.FastLogger.Types
FastLogger
type FastLogger = LogStr -> IO () Source #
FastLogger
simply log
logStr
.
data LogType' a where Source #
Logger Type.
LogNone | |
LogStdout | |
LogStderr | |
LogFileNoRotate | |
LogFile | |
|
|
LogFileTimedRotate | |
|
|
LogCallback | |
newFastLogger :: LogType' v -> IO (v -> IO (), IO ()) Source #
Initialize a
FastLogger
without attaching timestamp
a tuple of logger and clean up action are returned.
This type signature should be read as:
newFastLogger :: LogType -> IO (FastLogger, IO ())
This logger uses
numCapabilities
many buffers, and thus
does not provide time-ordered output.
For time-ordered output, use
newFastLogger1
.
newFastLogger1 :: LogType' v -> IO (v -> IO (), IO ()) Source #
Like
newFastLogger
, but creating a logger that uses only 1
capability. This scales less well on multi-core machines,
but provides time-ordered output.
withFastLogger :: LogType -> ( FastLogger -> IO a) -> IO a Source #
bracket
version of
newFastLogger
Timed FastLogger
type TimedFastLogger = ( FormattedTime -> LogStr ) -> IO () Source #
TimedFastLogger
pass
FormattedTime
to callback and simply log its result.
this can be used to customize how to log timestamp.
Usually, one would write a wrapper on top of
TimedFastLogger
, for example:
{-# LANGUAGE OverloadedStrings #-} log :: TimedFastLogger -> LogStr -> IO () log logger msg = logger (\time -> toLogStr (show time) <> " " <> msg <> "\n")
:: IO FormattedTime |
How do we get
|
-> LogType | |
-> IO ( TimedFastLogger , IO ()) |
Initialize a
FastLogger
with timestamp attached to each message.
a tuple of logger and clean up action are returned.
withTimedFastLogger :: IO FormattedTime -> LogType -> ( TimedFastLogger -> IO a) -> IO a Source #
bracket
version of
newTimeFastLogger
Log messages
Log message builder. Use (
<>
) to append two LogStr in O(1).
class ToLogStr msg where Source #
Types that can be converted to a
LogStr
. Instances for
types from the
text
library use a UTF-8 encoding. Instances
for numerical types use a decimal encoding.
Instances
ToLogStr Double Source # |
Since: 2.4.14 |
ToLogStr Float Source # |
Since: 2.4.14 |
ToLogStr Int Source # |
Since: 2.4.14 |
ToLogStr Int8 Source # |
Since: 2.4.14 |
ToLogStr Int16 Source # |
Since: 2.4.14 |
ToLogStr Int32 Source # |
Since: 2.4.14 |
ToLogStr Int64 Source # |
Since: 2.4.14 |
ToLogStr Integer Source # |
Since: 2.4.14 |
ToLogStr Word Source # |
Since: 2.4.14 |
ToLogStr Word8 Source # |
Since: 2.4.14 |
ToLogStr Word16 Source # |
Since: 2.4.14 |
ToLogStr Word32 Source # |
Since: 2.4.14 |
ToLogStr Word64 Source # |
Since: 2.4.14 |
ToLogStr String Source # | |
ToLogStr ShortByteString Source # | |
Defined in System.Log.FastLogger.LogStr toLogStr :: ShortByteString -> LogStr Source # |
|
ToLogStr ByteString Source # | |
Defined in System.Log.FastLogger.LogStr toLogStr :: ByteString -> LogStr Source # |
|
ToLogStr ByteString Source # | |
Defined in System.Log.FastLogger.LogStr toLogStr :: ByteString -> LogStr Source # |
|
ToLogStr Builder Source # | |
ToLogStr Text Source # | |
ToLogStr Text Source # | |
ToLogStr LogStr Source # | |
fromLogStr :: LogStr -> ByteString Source #
Converting
LogStr
to
ByteString
.
Buffer size
defaultBufSize :: BufSize Source #
The default buffer size (4,096 bytes).
LoggerSet
Date cache
module System.Log.FastLogger.Date
File rotation
module System.Log.FastLogger.File
Types
module System.Log.FastLogger.Types