System.Log.FastLogger

fast-logger-3.2.5: A fast logging system

Safe Haskell | None
Language | Haskell2010

System.Log.FastLogger

Contents

- FastLogger
- Timed FastLogger
- Log messages
- Buffer size
- LoggerSet
- Date cache
- File rotation
- Types

Description

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 :: forall a. (a -> IO ()) -> IO () -> LogType' a
- 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
  - toLogStr :: msg -> LogStr
- 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 () #

`FastLogger` simply log `logStr`.

type LogType = LogType' LogStr #

data LogType' a where #

Logger Type.

Constructors

LogNone |
Fields :: LogType' LogStr No logging.
LogStdout |
Fields :: BufSize -> LogType' LogStr Logging to stdout. `BufSize` is a buffer size for each capability.
LogStderr |
Fields :: BufSize -> LogType' LogStr Logging to stderr. `BufSize` is a buffer size for each capability.
LogFileNoRotate |
Fields :: FilePath -> BufSize -> LogType' LogStr Logging to a file. `BufSize` is a buffer size for each capability.
LogFile |
Fields :: FileLogSpec -> BufSize -> LogType' LogStr Logging to a file. `BufSize` is a buffer size for each capability. File rotation is done on-demand.
LogFileTimedRotate |
Fields :: TimedFileLogSpec -> BufSize -> LogType' LogStr Logging to a file. `BufSize` is a buffer size for each capability. Rotation happens based on check specified in `TimedFileLogSpec`.
LogCallback |
Fields :: forall a. (a -> IO ()) -> IO () -> LogType' a Logging with a log and flush action. run flush after log each message.

newFastLogger :: LogType' v -> IO (v -> IO (), IO ()) #

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 ()) #

Like `newFastLogger`, but creating a logger that uses only 1 internal builder. This scales less on multi-core machines and consumes more memory because of an internal queue but provides time-ordered output.

withFastLogger :: LogType -> (FastLogger -> IO a) -> IO a #

`bracket` version of `newFastLogger`

# Timed FastLogger

type TimedFastLogger = (FormattedTime -> LogStr) -> IO () #

`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")

newTimedFastLogger #

Arguments

:: IO FormattedTime | How do we get `FormattedTime`? System.Log.FastLogger.Date provide cached formatted time.
-> 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 #

`bracket` version of `newTimeFastLogger`

# Log messages

data LogStr #

Log message builder. Use (`<>`) to append two LogStr in O(1).

#### Instances

Instances details

ToLogStr LogStr # |
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: LogStr -> LogStr #
Monoid LogStr # |
Instance details Defined in System.Log.FastLogger.LogStr Methods mempty :: LogStr # mappend :: LogStr -> LogStr -> LogStr # mconcat :: [LogStr] -> LogStr #
Semigroup LogStr # |
Instance details Defined in System.Log.FastLogger.LogStr Methods (<>) :: LogStr -> LogStr -> LogStr # sconcat :: NonEmpty LogStr -> LogStr # stimes :: Integral b => b -> LogStr -> LogStr #
IsString LogStr # |
Instance details Defined in System.Log.FastLogger.LogStr Methods fromString :: String -> LogStr #
Show LogStr # |
Instance details Defined in System.Log.FastLogger.LogStr Methods showsPrec :: Int -> LogStr -> ShowS # show :: LogStr -> String # showList :: [LogStr] -> ShowS #
Eq LogStr # |
Instance details Defined in System.Log.FastLogger.LogStr Methods (==) :: LogStr -> LogStr -> Bool # (/=) :: LogStr -> LogStr -> Bool #

class ToLogStr msg where #

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.

Methods

toLogStr :: msg -> LogStr #

#### Instances

Instances details

ToLogStr Builder # |
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Builder -> LogStr #
ToLogStr ByteString # |
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: ByteString -> LogStr #
ToLogStr ByteString # |
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: ByteString -> LogStr #
ToLogStr ShortByteString # |
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: ShortByteString -> LogStr #
ToLogStr LogStr # |
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: LogStr -> LogStr #
ToLogStr Int16 # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Int16 -> LogStr #
ToLogStr Int32 # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Int32 -> LogStr #
ToLogStr Int64 # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Int64 -> LogStr #
ToLogStr Int8 # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Int8 -> LogStr #
ToLogStr Word16 # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Word16 -> LogStr #
ToLogStr Word32 # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Word32 -> LogStr #
ToLogStr Word64 # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Word64 -> LogStr #
ToLogStr Word8 # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Word8 -> LogStr #
ToLogStr Text # |
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Text -> LogStr #
ToLogStr Text # |
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Text -> LogStr #
ToLogStr Integer # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Integer -> LogStr #
ToLogStr String # |
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: String -> LogStr #
ToLogStr Double # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Double -> LogStr #
ToLogStr Float # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Float -> LogStr #
ToLogStr Int # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Int -> LogStr #
ToLogStr Word # | Since: 2.4.14
Instance details Defined in System.Log.FastLogger.LogStr Methods toLogStr :: Word -> LogStr #

fromLogStr :: LogStr -> ByteString #

Converting `LogStr` to `ByteString`.

logStrLength :: LogStr -> Int #

Obtaining the length of `LogStr`.

# Buffer size

type BufSize = Int #

The type for buffer size of each core.

defaultBufSize :: BufSize #

The default buffer size (4,096 bytes).

# LoggerSet

module System.Log.FastLogger.LoggerSet

# Date cache

module System.Log.FastLogger.Date

# File rotation

module System.Log.FastLogger.File

# Types

module System.Log.FastLogger.Types