co-log-0.4.0.1: Composable Contravariant Comonadic Logging Library
Copyright(c) 2018-2020 Kowainik
LicenseMPL-2.0
MaintainerKowainik <xrom.xkov@gmail.com>
Stabilityexperimental
Safe HaskellNone
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
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 #

Show Limit Source # 
Instance details

Defined in Colog.Rotation

Methods

showsPrec :: Int -> Limit -> ShowS #

show :: Limit -> String #

showList :: [Limit] -> ShowS #

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.