log-warper-1.1.0: examples/Playground.hs
-- | Testing module to play with logging.
module Main where
import Universum
import Data.Monoid ((<>))
import Data.Yaml.Pretty (defConfig, encodePretty)
import System.Wlog (CanLog, buildAndSetupYamlLogging, dispatchEvents,
logDebug, logError, logInfo, logNotice, logWarning,
modifyLoggerName, parseLoggerConfig, prefixB,
productionB, releaseAllHandlers, runPureLog,
usingLoggerName)
testLoggerConfigPath :: FilePath
testLoggerConfigPath = "logger-config-example.yaml"
testToJsonConfigOutput :: MonadIO m => m ()
testToJsonConfigOutput = do
cfg <- parseLoggerConfig testLoggerConfigPath
let builtConfig = cfg <> productionB <> prefixB "logs"
putStrLn $ encodePretty defConfig builtConfig
testLogging :: (CanLog m) => m ()
testLogging = usingLoggerName "node" $ do
logDebug "skovoroda"
logInfo "patak"
logNotice "boroda"
logWarning "haha"
modifyLoggerName (<> "server") $ do
logDebug "provoda"
logNotice "Ggurda"
logError "BARDAQ"
showPureLog :: IO ()
showPureLog = do
(res, pureLog) <- runPureLog testLogging
putText "Pure log:"
usingLoggerName "naked" $ do
logWarning $ "Pure log for result = " <> show res <> ":"
dispatchEvents pureLog
main :: IO ()
main = do
testToJsonConfigOutput
bracket_
(buildAndSetupYamlLogging (productionB <> prefixB "logs") testLoggerConfigPath)
releaseAllHandlers
(testLogging >> showPureLog)