co-log-0.6.1.0: Composable Contravariant Comonadic Logging Library
Copyright(c) 2018-2022 Kowainik 2023-2024 Co-Log
LicenseMPL-2.0
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Colog.Rotation

Description

NOTE: This functionality is not to be considered stable or ready for production use. While we enourage you to try it out and report bugs, we cannot assure you that everything will work as advertised :)

Synopsis

Documentation

data Limit Source #

Limit for the logger rotation. Used for two purposes:

  1. Limit the number of kept files.
  2. Limit the size of the files.

Constructors

LimitTo Natural 
Unlimited 

Instances

Instances details
Show Limit Source # 
Instance details

Defined in Colog.Rotation

Methods

showsPrec :: Int -> Limit -> ShowS #

show :: Limit -> String #

showList :: [Limit] -> ShowS #

Eq Limit Source # 
Instance details

Defined in Colog.Rotation

Methods

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

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

Ord Limit Source # 
Instance details

Defined in Colog.Rotation

Methods

compare :: Limit -> Limit -> Ordering #

(<) :: Limit -> Limit -> Bool #

(<=) :: Limit -> Limit -> Bool #

(>) :: Limit -> Limit -> Bool #

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

max :: Limit -> Limit -> Limit #

min :: Limit -> Limit -> Limit #

withLogRotation Source #

Arguments

:: forall r msg m. MonadIO m 
=> Limit

Max allowed file size in bytes

-> Limit

Max allowed number of files to have

-> FilePath

File path to log

-> (FilePath -> IO ())

What to do with old files; pass removeFile here for deletion

-> (Handle -> LogAction m msg)

Action that writes to file handle

-> (LogAction m msg -> IO r)

Continuation action

-> IO r 

Logger rotation action. Takes name of the logging file file.foo. Always writes new logs to file named file.foo (given file name, also called as hot log).

  • If the size of the file exceeds given limit for file sizes then this action renames file.foo to file.foo.(n + 1) (where n is the number of latest renamed file).
  • If the number of files on the filesystem is bigger than the files number limit then the given FilePath -> IO () action is called on the oldest file. As simple solution, you can pass removeFile function to delete old files but you can also pass some archiving function if you don't want to lose old logs.