Safe Haskell | None |
---|---|
Language | Haskell2010 |
Fast start
Create log config:
myCfg = logCfg [("", Info), ("app", Trace), ("app.sub", Debug)]
Create log and run log monad
run ∷ IO () run = runLog myCfg [handler text (file "out.log")] $ yourFunction
Function within log monad:
yourFunction ∷ MonadLog m ⇒ m () yourFunction = component "app" $ scope "your" $ do sendLog Trace "Hello from your function"
Each component can have different level in config, subcomponents are specified with '.' Components have independent scopes Scopes can be nested and separated with '/':
function2 ∷ MonadLog m ⇒ m () function2 = component "app.sub" $ scope "foo" $ do scope "bar/baz" $ do sendLog Info "Component app.sub and scope foobarbaz" sendLog Trace "Invisible: app.sub configured with debug level" sendLog Info "Same component and scope foo" component "module" $ sendLog Info "Component module and root scope"
You can update config with updateLogConfig
(or modifyLogConfig
within log monad) function
And change handlers with updateLogHandlers
(modifyLogHandlers
)
There're also global logger globalLog
, that can be used with runGlobalLog
test ∷ IO () test = do updateLogHandlers globalLog ([handler text (file "test.log")]:) runGlobalLog $ do sendLog Info "This will go to test.log too" modifyLogConfig (set (ix "") Debug) sendLog Debug "Now debug is logged too"
Documentation
module System.Log.Simple.Base
module System.Log.Simple.Monad
module System.Log.Simple.Text
module System.Log.Simple.Stream
module System.Log.Simple.File
runGlobalLog :: LogT m a -> m a Source #