log-warper-1.8.1: Flexible, configurable, monadic and pretty logging

Copyright(c) Serokell 2016
LicenseGPL-3 (see the file LICENSE)
MaintainerSerokell <hi@serokell.io>
PortabilityPOSIX, GHC
Safe HaskellNone



Parser for configuring and initializing logger from YAML file. Logger configuration should look like this:

rotation:                    # [optional] parameters for logging rotation
    logLimit: 1024           # max size of log file in bytes
    keepFiles: 3             # number of files with logs to keep including current one
    severity: Warning+       # severities for «root» logger
    node:                    # logger named «node»
        severity: Warning+   # severities for logger «node»
        comm:                # logger named «node.comm»
            severity: Info+  # severity for logger «node.comm»
            file: patak.jpg  # messages will be also printed to patak.jpg

And this configuration corresponds two loggers with LoggerName's node and node.comm.



buildAndSetupYamlLogging :: MonadIO m => LoggerConfig -> FilePath -> m () Source #

Applies given builder to parsed logger config and initializes logging.

defaultConfig :: LoggerName -> LoggerConfig Source #

Default logging configuration with the given LoggerName.

Enabled flags:


defaultConfig "example" will produce such configurations:

rotation: null
showTid: false
showTime: true
printOutput: true
      _ltSubloggers: {}
      - Debug
      - Info
      - Notice
      - Warning
      - Error
      _ltFiles: []
  - Warning
  - Error
  _ltFiles: []
termSeveritiesOut: null
filePrefix: null
termSeveritiesErr: null

launchFromFile :: (MonadIO m, MonadMask m) => FilePath -> LoggerName -> LoggerNameBox m a -> m a Source #

Initializes logging using given FilePath to logger configurations, runs the action with the given LoggerName.

launchSimpleLogging :: (MonadIO m, MonadMask m) => LoggerName -> LoggerNameBox m a -> m a Source #

Set ups the logging with defaultConfig and runs the action with the given LoggerName.


Here we can see very simple working example of logging:

ghci> :{
ghci| launchSimpleLogging "app" $ do
ghci|     logDebug "Debug message"
ghci|     putStrLn "Usual printing"
ghci|     logInfo "Job's done!"
ghci| :}
[app:DEBUG] [2017-12-07 11:25:06.47 UTC] Debug message
Usual printing
[app:INFO] [2017-12-07 11:25:06.47 UTC] Job's done!

parseLoggerConfig :: MonadIO m => FilePath -> m LoggerConfig Source #

Parses logger config from given file path.

setupLogging :: MonadIO m => Maybe (UTCTime -> Text) -> LoggerConfig -> m () Source #

This function traverses LoggerConfig initializing all subloggers with Severities and redirecting output in file handlers. See LoggerConfig for more details.