hslogger-template 0.1 → 0.2
raw patch · 4 files changed
+58/−41 lines, 4 filesbuild-type:Customsetup-changedPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Setup.hs +13/−0
- Setup.lhs +0/−4
- hslogger-template.cabal +5/−5
- src/System/Log/Logger/TH.hs +40/−32
+ Setup.hs view
@@ -0,0 +1,13 @@+module Main (main) where++import System.Cmd (system)++import Distribution.Simple (defaultMainWithHooks, runTests, simpleUserHooks)++main :: IO ()+main =+ defaultMainWithHooks $+ simpleUserHooks+ { runTests = \_ _ _ _ ->+ system "runhaskell -i./src -Wall -XTemplateHaskell src/test.hs" >> return ()+ }
− Setup.lhs
@@ -1,4 +0,0 @@-#! /usr/bin/env runhaskell--> import Distribution.Simple-> main = defaultMain
hslogger-template.cabal view
@@ -1,9 +1,9 @@ name: hslogger-template-version: 0.1+version: 0.2 synopsis: Automatic generation of hslogger functions description:- A function for generating hslogger functions automatically using Template- Haskell.+ Library for generating hslogger functions using Template Haskell.+homepage: http://github.com/bsl/hslogger-template license: PublicDomain author: Brian Lewis <brian@lorf.org>, Ian Taylor <ian@lorf.org>@@ -11,7 +11,7 @@ category: Interfaces cabal-version: >= 1.6-build-type: Simple+build-type: Custom library exposed-modules: System.Log.Logger.TH@@ -20,4 +20,4 @@ hs-source-dirs: src ghc-options: -Wall if impl(ghc >= 6.8)- ghc-options: -fwarn-tabs+ ghc-options: -fwarn-tabs
src/System/Log/Logger/TH.hs view
@@ -1,12 +1,12 @@--- | This module provides a function that generates hslogger functions--- automatically using Template Haskell.+-- | This module provides functions that generate hslogger functions using+-- Template Haskell. module System.Log.Logger.TH (deriveLoggers) where import qualified Language.Haskell.TH as TH import qualified System.Log.Logger as HSL --- | Generate hslogger functions for given priorities.+-- | Generate hslogger functions for a list of priorities. -- -- Example usage: --@@ -19,25 +19,31 @@ -- -- Used this way, @deriveLoggers@ would generate the following functions: ----- > info :: String -> IO ()--- > info s = HSL.infoM "Foo.Bar" ((++) "Foo.Bar: " s)+-- > infoM :: String -> IO ()+-- > infoM s = HSL.infoM "Foo.Bar" ((++) "Foo.Bar: " s) -- >--- > debug :: String -> IO ()--- > debug s = HSL.debugM "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 ----- > info "hi there"+-- > infoM "hi there" -- -- would generate the INFO-level log event -- -- > Foo.Bar: hi there ----- Note: "System.Log.Logger" must be imported qualified, and the qualifier must--- match the qualifier given to @deriveLoggers@.+-- 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 or+-- @extensions: TemplateHaskell@ in your cabal file, etc.+-- deriveLoggers :: String -- ^ Must match qualifier on import of "System.Log.Logger". -> [HSL.Priority] -- ^ List of priorities for which to generate logging functions.@@ -54,36 +60,38 @@ code = do sig <- TH.sigD th_f [t| String -> IO () |] body <- TH.funD th_f- [ TH.clause [TH.varP th_s]- (TH.normalB- (TH.appE- (TH.appE- (TH.varE th_h)- (TH.stringE moduleName)- )+ [ TH.clause+ [TH.varP th_s]+ (TH.normalB (TH.appE (TH.appE- (TH.varE '(++))- (TH.litE (TH.stringL (moduleName ++ ": ")))+ (TH.varE th_h)+ (TH.stringE moduleName) )- (TH.varE th_s)+ (TH.appE+ (TH.appE+ (TH.varE '(++))+ (TH.stringE prefix)+ )+ (TH.varE th_s)+ ) ) )- )- []+ [] ] return [sig, body] where- th_f = TH.mkName functionName- th_h = TH.mkName (concat [qualifier, ".", functionName, "M"]) th_s = TH.mkName "s"+ th_f = TH.mkName functionName+ th_h = TH.mkName (qualifier ++ "." ++ functionName)+ prefix = moduleName ++ ": " functionName = case priority of- HSL.DEBUG -> "debug"- HSL.INFO -> "info"- HSL.NOTICE -> "notice"- HSL.WARNING -> "warning"- HSL.ERROR -> "error"- HSL.CRITICAL -> "critical"- HSL.ALERT -> "alert"- HSL.EMERGENCY -> "emergency"+ HSL.DEBUG -> "debugM"+ HSL.INFO -> "infoM"+ HSL.NOTICE -> "noticeM"+ HSL.WARNING -> "warningM"+ HSL.ERROR -> "errorM"+ HSL.CRITICAL -> "criticalM"+ HSL.ALERT -> "alertM"+ HSL.EMERGENCY -> "emergencyM"