System.Log.Logger.TH
Description
This module provides functions that generate hslogger functions using Template Haskell.
- deriveLoggers :: String -> [Priority] -> Q [Dec]
Documentation
Arguments
:: String | Must match qualifier on import of System.Log.Logger. |
-> [Priority] | List of priorities for which to generate logging functions. |
-> Q [Dec] |
Generate hslogger functions for a list of priorities.
Example usage:
module Foo.Bar ( ... ) where import System.Log.Logger.TH (deriveLoggers) import qualified System.Log.Logger as HSL $(deriveLoggers "HSL" [HSL.DEBUG, HSL.INFO])
Used this way, deriveLoggers
would generate the following functions:
infoM :: String -> IO () infoM s = HSL.infoM "Foo.Bar" ((++) "Foo.Bar: " s) debugM :: String -> IO () debugM s = HSL.debugM "Foo.Bar" ((++) "Foo.Bar: " s)
The other hslogger priorities follow the same pattern.
So
infoM "hi there"
would generate the INFO-level log event
Foo.Bar: hi there
Notes:
- System.Log.Logger must be imported qualified, and the qualifier must
match the qualifier given to
deriveLoggers
. - Don't forget to enable Template Haskell preprocessing: specify the
pragma
LANGUAGE TemplateHaskell
at the top of your source file orextensions: TemplateHaskell
in your cabal file, etc.