IHP Api Reference
Safe HaskellSafe-Inferred

IHP.Log.Types

Description

 
Synopsis

Documentation

newtype Bytes Source #

A number of bytes, used in RotateSettings

Constructors

Bytes Integer 

data LogStr #

Instances

Instances details
IsString LogStr 
Instance details

Defined in System.Log.FastLogger.LogStr

Methods

fromString :: String -> LogStr #

Monoid LogStr 
Instance details

Defined in System.Log.FastLogger.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 #

Show LogStr 
Instance details

Defined in System.Log.FastLogger.LogStr

Methods

showsPrec :: Int -> LogStr -> ShowS #

show :: LogStr -> String

showList :: [LogStr] -> ShowS #

ToLogStr LogStr 
Instance details

Defined in System.Log.FastLogger.LogStr

Methods

toLogStr :: LogStr -> LogStr #

Eq LogStr 
Instance details

Defined in System.Log.FastLogger.LogStr

Methods

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

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

type BufSize = Int #

data RotateSettings Source #

Constructors

NoRotate

Log messages to a file which is never rotated.

newLogger def {
   destination = File "Log/production.log" NoRotate defaultBufSize
   }
SizeRotate Bytes Int

Log messages to a file and rotate the file after it reaches the given size in bytes. Third argument is the max number of rotated log files to keep around before overwriting the oldest one.

Example: log to a file rotated once it is 4MB, and keep 7 files before overwriting the first file.

   newLogger def {
     destination = File "Log/production.log" (SizeRotate (Bytes (4 * 1024 * 1024)) 7) defaultBufSize
     }
TimedRotate TimeFormat (FormattedTime -> FormattedTime -> Bool) (FilePath -> IO ())

Log messages to a file rotated on a timed basis. Expects a time format string as well as a function which compares two formatted time strings which is used to determine if the file should be rotated. Last argument is a function which is called on a log file once its rotated.

Example: rotate a file daily and compress the log file once rotated.

  let
      filePath = "Log/production.log"
      formatString = "%FT%H%M%S"
      timeCompare = (==) on C8.takeWhile (/=T))
      compressFile fp = void . forkIO $
          callProcess "tar" [ "--remove-files", "-caf", fp <> ".gz", fp ]
  in
    newLogger def {
       destination = File
         filePath
         (TimedRotate formatString timeCompare compressFile)
         defaultBufSize
       }

toLogStr :: ToLogStr msg => msg -> LogStr #

data Logger Source #

Interal logger type that encapsulates information needed to perform logging operations. Users can also access this though the LoggingProvider class in controller and model actions to perform logic based on the set log level.

Constructors

Logger 

Fields

Instances

Instances details
HasField "logger" ControllerContext Logger Source # 
Instance details

Defined in IHP.Controller.Context

HasField "logger" Logger Logger Source # 
Instance details

Defined in IHP.Log.Types

Methods

getField :: Logger -> Logger #

data LogLevel Source #

Constructors

Debug

For general messages to help with debugging during development. Default log level in development. Also the log level used for SQL queries. See debug for example usage.

Info

For info messages that help montior application usage. Default log level for production. See info for example usage.

Warn

For warning messages when something might be wrong. See warn for example usage.

Error

For application errors that can be recovered from. See error for example usage.

Fatal

For application errors that are fatal See fatal for example usage.

Unknown

For miscallenaous log messages. Highest log level - will always be logged See unknown for example usage.

Instances

Instances details
Enum LogLevel Source # 
Instance details

Defined in IHP.Log.Types

Show LogLevel Source # 
Instance details

Defined in IHP.Log.Types

Methods

showsPrec :: Int -> LogLevel -> ShowS #

show :: LogLevel -> String

showList :: [LogLevel] -> ShowS #

ToLogStr LogLevel Source # 
Instance details

Defined in IHP.Log.Types

Methods

toLogStr :: LogLevel -> LogStr #

Eq LogLevel Source # 
Instance details

Defined in IHP.Log.Types

Ord LogLevel Source # 
Instance details

Defined in IHP.Log.Types

data LogDestination Source #

Where logged messages will be delivered to.

Constructors

None 
Stdout BufSize

Log messages to standard output.

Stderr BufSize

Log messages to standard error.

File FilePath RotateSettings BufSize

Log message to a file. Rotate the log file with the behavior given by RotateSettings.

Callback (LogStr -> IO ()) (IO ())

Send logged messages to a callback. Flush action called after every log.

type LoggingProvider context = HasField "logger" context Logger Source #

Used to get the logger for a given environment. | Call in any instance of LoggingProvider get the the environment's current logger. Useful in controller and model actions, which both have logging contexts.

data LoggerSettings Source #

Instances

Instances details
Default LoggerSettings Source # 
Instance details

Defined in IHP.Log.Types

Methods

def :: LoggerSettings #

type LogFormatter = FormattedTime -> LogLevel -> LogStr -> LogStr Source #

Called every time a message is sent to the logger. Since this is just a function type, it's trivial to define custom formatters:

    withTimeAndLevelFormatterUpcaseAndHappy :: LogFormatter
    withTimeAndLevelFormatterUpcaseAndHappy time level msg =
       "[" <> toUpper (show level) <> "]"
         <> "[" <> time <> "] "
         <> toUpper msg <> " :) n"

type FormattedTime = ByteString Source #

The timestamp in the formatted defined by the logger's timeFormat string.

newLogger :: LoggerSettings -> IO Logger Source #

Create a new FastLogger and wrap it in an IHP Logger. Use with the default logger settings and record update syntax for nice configuration:

newLogger def { level = Error }

defaultLogger :: IO Logger Source #

Formats logs as-is to stdout.

defaultDestination :: LogDestination Source #

Logger default destination is to standard out.

defaultFormatter :: LogFormatter Source #

Formats the log as-is with a newline added.

withLevelFormatter :: LogFormatter Source #

Prepends the log level to the log message and adds a new line.

withTimeFormatter :: LogFormatter Source #

Prepends the timestamp to the log message and adds a new line.

withTimeAndLevelFormatter :: LogFormatter Source #

Prepends the log level and timestamp to the log message and adds a new line.