snap-server-1.1.2.1: A web server for the Snap Framework

Safe Haskell | None
Language | Haskell2010

System.FastLogger

Synopsis

- data Logger
- timestampedLogEntry :: ByteString -> IO ByteString
- combinedLogEntry :: ByteString -> Maybe ByteString -> ByteString -> Int -> Word64 -> Maybe ByteString -> ByteString -> IO ByteString
- newLogger :: FilePath -> IO Logger
- newLoggerWithCustomErrorFunction :: (ByteString -> IO ()) -> FilePath -> IO Logger
- withLogger :: FilePath -> (Logger -> IO a) -> IO a
- withLoggerWithCustomErrorFunction :: (ByteString -> IO ()) -> FilePath -> (Logger -> IO a) -> IO a
- stopLogger :: Logger -> IO ()
- logMsg :: Logger -> ByteString -> IO ()

# Documentation

data Logger #

Holds the state for a logger.

timestampedLogEntry :: ByteString -> IO ByteString #

Prepares a log message with the time prepended.

combinedLogEntry #

Arguments

:: ByteString | remote host
-> Maybe ByteString | remote user
-> ByteString | request line (up to you to ensure there are no quotes in here)
-> Int | status code
-> Word64 | num bytes sent
-> Maybe ByteString | referer (up to you to ensure there are no quotes in here)
-> ByteString | user agent (up to you to ensure there are no quotes in here)
-> IO ByteString |

Prepares a log message in "combined" format.

newLogger #

Arguments

:: FilePath | log file to use
-> IO Logger |

Creates a new logger, logging to the given file. If the file argument is "-", then log to stdout; if it's "stderr" then we log to stderr, otherwise we log to a regular file in append mode. The file is closed and re-opened every 15 minutes to facilitate external log rotation.

newLoggerWithCustomErrorFunction #

Arguments

:: (ByteString -> IO ()) | logger uses this action to log any error messages of its own
-> FilePath | log file to use
-> IO Logger |

Like `newLogger`, but uses a custom error action if the logger needs to print an error message of its own (for instance, if it can't open the output file.)

withLogger #

Arguments

:: FilePath | log file to use
-> (Logger -> IO a) |
-> IO a |

Creates a Logger and passes it into the given function, cleaning up with "stopLogger" afterwards.

withLoggerWithCustomErrorFunction #

Arguments

:: (ByteString -> IO ()) | logger uses this action to log any error messages of its own
-> FilePath | log file to use
-> (Logger -> IO a) |
-> IO a |

Creates a Logger with "newLoggerWithCustomErrorFunction" and passes it into the given function, cleaning up with "stopLogger" afterwards.

stopLogger :: Logger -> IO () #

Kills a logger thread, causing any unwritten contents to be flushed out to disk

logMsg :: Logger -> ByteString -> IO () #

Sends out a log message verbatim with a newline appended. Note: if you want a fancy log message you'll have to format it yourself (or use `combinedLogEntry`).