Safe Haskell | None |
---|
Synopsis
- newtype Bytes = Bytes Integer
- data LogStr
- type BufSize = Int
- type TimeFormat = ByteString
- data RotateSettings
- = NoRotate
- | SizeRotate !Bytes !Int
- | TimedRotate !TimeFormat (FormattedTime -> FormattedTime -> Bool) (FilePath -> IO ())
- toLogStr :: ToLogStr msg => msg -> LogStr
- fromLogStr :: LogStr -> ByteString
- defaultBufSize :: BufSize
- simpleTimeFormat :: TimeFormat
- simpleTimeFormat' :: TimeFormat
- data Logger = Logger {}
- data LogLevel
- data LogDestination
- type LoggingProvider context = HasField "logger" context Logger
- data LoggerSettings = LoggerSettings {}
- type LogFormatter = FormattedTime -> LogLevel -> LogStr -> LogStr
- type FormattedTime = ByteString
- newLogger :: LoggerSettings -> IO Logger
- defaultLogger :: IO Logger
- defaultDestination :: LogDestination
- defaultFormatter :: LogFormatter
- withLevelFormatter :: LogFormatter
- withTimeFormatter :: LogFormatter
- withTimeAndLevelFormatter :: LogFormatter
Documentation
type TimeFormat = ByteString #
data RotateSettings Source #
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 } |
fromLogStr :: LogStr -> ByteString #
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.
Instances
HasField "logger" ControllerContext Logger Source # | |
Defined in IHP.Controller.Context getField :: ControllerContext -> Logger # | |
HasField "logger" Logger Logger Source # | |
Defined in IHP.Log.Types |
Debug | For general messages to help with debugging during development.
Default log level in development.
Also the log level used for SQL queries.
See |
Info | For info messages that help montior application usage.
Default log level for production.
See |
Warn | For warning messages when something might be wrong.
See |
Error | For application errors that can be recovered from.
See |
Fatal | For application errors that are fatal
See |
Unknown | For miscallenaous log messages. Highest log level - will always be logged
See |
Instances
Enum LogLevel Source # | |
Show LogLevel Source # | |
ToLogStr LogLevel Source # | |
Defined in IHP.Log.Types | |
Eq LogLevel Source # | |
Ord LogLevel Source # | |
Defined in IHP.Log.Types |
data LogDestination Source #
Where logged messages will be delivered to.
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 |
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
Default LoggerSettings Source # | |
Defined in IHP.Log.Types 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.