System.Log.FastLogger

fast-logger-2.4.6: A fast logging system

Safe Haskell | None
Language | Haskell98

System.Log.FastLogger

Contents

- Creating a logger set
- Buffer size
- Renewing and removing a logger set
- Log messages
- Writing a log message
- Flushing buffered log messages
- FastLogger
- Date cache
- File rotation

Description

This module provides a fast logging system which scales on multicore environments (i.e. +RTS -N<x>).

Synopsis

- data LoggerSet
- newFileLoggerSet :: BufSize -> FilePath -> IO LoggerSet
- newStdoutLoggerSet :: BufSize -> IO LoggerSet
- newStderrLoggerSet :: BufSize -> IO LoggerSet
- newLoggerSet :: BufSize -> Maybe FilePath -> IO LoggerSet
- type BufSize = Int
- defaultBufSize :: BufSize
- renewLoggerSet :: LoggerSet -> IO ()
- rmLoggerSet :: LoggerSet -> IO ()
- data LogStr
- class ToLogStr msg where
- fromLogStr :: LogStr -> ByteString
- logStrLength :: LogStr -> Int
- pushLogStr :: LoggerSet -> LogStr -> IO ()
- pushLogStrLn :: LoggerSet -> LogStr -> IO ()
- flushLogStr :: LoggerSet -> IO ()
- type FastLogger = LogStr -> IO ()
- type TimedFastLogger = (FormattedTime -> LogStr) -> IO ()
- data LogType
  - = LogNone
  - | LogStdout BufSize
  - | LogStderr BufSize
  - | LogFileNoRotate FilePath BufSize
  - | LogFile FileLogSpec BufSize
  - | LogCallback (LogStr -> IO ()) (IO ())
- newFastLogger :: LogType -> IO (FastLogger, IO ())
- withFastLogger :: LogType -> (FastLogger -> IO a) -> IO a
- newTimedFastLogger :: IO FormattedTime -> LogType -> IO (TimedFastLogger, IO ())
- withTimedFastLogger :: IO FormattedTime -> LogType -> (TimedFastLogger -> IO a) -> IO a
- module System.Log.FastLogger.Date
- module System.Log.FastLogger.File

# Creating a logger set

data LoggerSet #

A set of loggers. The number of loggers is the capabilities of GHC RTS. You can specify it with "+RTS -N<x>". A buffer is prepared for each capability.

newFileLoggerSet :: BufSize -> FilePath -> IO LoggerSet #

Creating a new `LoggerSet` using a file.

newStdoutLoggerSet :: BufSize -> IO LoggerSet #

Creating a new `LoggerSet` using stdout.

newStderrLoggerSet :: BufSize -> IO LoggerSet #

Creating a new `LoggerSet` using stderr.

newLoggerSet :: BufSize -> Maybe FilePath -> IO LoggerSet #

Deprecated: Use newFileLoggerSet etc instead

Creating a new `LoggerSet`. If `Nothing` is specified to the second argument, stdout is used. Please note that the minimum `BufSize` is 1.

# Buffer size

type BufSize = Int #

The type for buffer size of each core.

defaultBufSize :: BufSize #

The default buffer size (4,096 bytes).

# Renewing and removing a logger set

renewLoggerSet :: LoggerSet -> IO () #

Renewing the internal file information in `LoggerSet`. This does nothing for stdout and stderr.

rmLoggerSet :: LoggerSet -> IO () #

Flushing the buffers, closing the internal file information and freeing the buffers.

# Log messages

data LogStr #

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

Instances

IsString LogStr # |
Methods fromString :: String -> LogStr #
Monoid LogStr # |
Methods mempty :: LogStr # mappend :: LogStr -> LogStr -> LogStr # mconcat :: [LogStr] -> LogStr #
ToLogStr LogStr # |
Methods toLogStr :: LogStr -> LogStr #

class ToLogStr msg where #

Minimal complete definition

toLogStr

Methods

toLogStr :: msg -> LogStr #

Instances

ToLogStr String # |
Methods toLogStr :: String -> LogStr #
ToLogStr ByteString # |
Methods toLogStr :: ByteString -> LogStr #
ToLogStr ByteString # |
Methods toLogStr :: ByteString -> LogStr #
ToLogStr Text # |
Methods toLogStr :: Text -> LogStr #
ToLogStr Text # |
Methods toLogStr :: Text -> LogStr #
ToLogStr LogStr # |
Methods toLogStr :: LogStr -> LogStr #

fromLogStr :: LogStr -> ByteString #

Converting `LogStr` to `ByteString`.

logStrLength :: LogStr -> Int #

Obtaining the length of `LogStr`.

# Writing a log message

pushLogStr :: LoggerSet -> LogStr -> IO () #

Writing a log message to the corresponding buffer. If the buffer becomes full, the log messages in the buffer are written to its corresponding file, stdout, or stderr.

pushLogStrLn :: LoggerSet -> LogStr -> IO () #

Same as `pushLogStr` but also appends a newline.

# Flushing buffered log messages

flushLogStr :: LoggerSet -> IO () #

Flushing log messages in buffers. This function must be called explicitly when the program is being terminated.

Note: Since version 2.1.6, this function does not need to be explicitly called, as every push includes an auto-debounced flush courtesy of the auto-update package. Since version 2.2.2, this function can be used to force flushing outside of the debounced flush calls.

# FastLogger

type FastLogger = LogStr -> IO () #

`FastLogger` simply log `logStr`.

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.

data LogType #

Logger Type.

Constructors

LogNone | No logging.
LogStdout BufSize | Logging to stdout. `BufSize` is a buffer size
LogStderr BufSize | Logging to stdout. `BufSize` is a buffer size for each capability.
LogFileNoRotate FilePath BufSize | Logging to a file. `BufSize` is a buffer size for each capability.
LogFile FileLogSpec BufSize | Logging to a file. `BufSize` is a buffer size for each capability. File rotation is done on-demand.
LogCallback (LogStr -> IO ()) (IO ()) | Logging with a log and flush action. run flush after log each message.

newFastLogger :: LogType -> IO (FastLogger, IO ()) #

Initialize a `FastLogger` without attaching timestamp a tuple of logger and clean up action are returned.

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

`bracket` version of `newFastLogger`

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`

# Date cache

module System.Log.FastLogger.Date

# File rotation

module System.Log.FastLogger.File