fast-logger-3.0.0: A fast logging system

Safe HaskellNone
LanguageHaskell2010

System.Log.FastLogger

Contents

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

Creating a logger set

data LoggerSet Source #

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 Source #

Creating a new LoggerSet using a file.

newStdoutLoggerSet :: BufSize -> IO LoggerSet Source #

Creating a new LoggerSet using stdout.

newStderrLoggerSet :: BufSize -> IO LoggerSet Source #

Creating a new LoggerSet using stderr.

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

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 Source #

The type for buffer size of each core.

defaultBufSize :: BufSize Source #

The default buffer size (4,096 bytes).

Renewing and removing a logger set

renewLoggerSet :: LoggerSet -> IO () Source #

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

rmLoggerSet :: LoggerSet -> IO () Source #

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

Log messages

data LogStr Source #

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

Instances
Eq LogStr Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

Methods

(==) :: LogStr -> LogStr -> Bool #

(/=) :: LogStr -> LogStr -> Bool #

Show LogStr Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

IsString LogStr Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

Methods

fromString :: String -> LogStr #

Semigroup LogStr Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

Monoid LogStr Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr LogStr Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

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.

Methods

toLogStr :: msg -> LogStr Source #

Instances
ToLogStr Double Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Float Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Int Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

Methods

toLogStr :: Int -> LogStr Source #

ToLogStr Int8 Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

Methods

toLogStr :: Int8 -> LogStr Source #

ToLogStr Int16 Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Int32 Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Int64 Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Integer Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Word Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

Methods

toLogStr :: Word -> LogStr Source #

ToLogStr Word8 Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Word16 Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Word32 Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Word64 Source #

Since: 2.4.14

Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr String Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr ByteString Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr ByteString Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Builder Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

ToLogStr Text Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

Methods

toLogStr :: Text -> LogStr Source #

ToLogStr Text Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

Methods

toLogStr :: Text -> LogStr Source #

ToLogStr LogStr Source # 
Instance details

Defined in System.Log.FastLogger.LogStr

logStrLength :: LogStr -> Int Source #

Obtaining the length of LogStr.

Writing a log message

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

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

Same as pushLogStr but also appends a newline.

Flushing buffered log messages

flushLogStr :: LoggerSet -> IO () Source #

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

FastLogger simply log logStr.

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:

{--}

log :: TimedFastLogger -> LogStr -> IO ()
log logger msg = logger (time -> toLogStr (show time) <> " " <> msg <> "n")

data LogType' a where Source #

Logger Type.

Constructors

LogNone 

Fields

LogStdout 

Fields

LogStderr 

Fields

LogFileNoRotate 

Fields

LogFile 

Fields

LogFileTimedRotate 

Fields

LogCallback 

Fields

  • :: (v -> IO ())
     
  • -> IO ()
     
  • -> LogType' v

    Logging with a log and flush action. run flush after log each message.

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

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

newTimedFastLogger Source #

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 Source #

bracket version of newTimeFastLogger

Date cache

File rotation

Types