log-warper 1.8.3 → 1.8.4
raw patch · 7 files changed
+59/−15 lines, 7 filesdep +microlens
Dependencies added: microlens
Files
- CHANGES.md +7/−0
- README.md +1/−1
- examples/Playground.hs +8/−6
- log-warper.cabal +2/−1
- src/System/Wlog/IOLogger.hs +2/−2
- src/System/Wlog/Launcher.hs +1/−5
- src/System/Wlog/LoggerConfig.hs +38/−0
CHANGES.md view
@@ -1,3 +1,10 @@+1.8.4+=====++* [#86](https://github.com/serokell/log-warper/issues/86):+ Add lens for changing properties of the particular logger.+* Ungrade `universum` to the `1.0.2`.+ 1.8.3 =====
README.md view
@@ -15,7 +15,7 @@ 1. Output is colored :star: 2. Supports logging initialization from `.yaml` configuration file-3. Has wrapper for pure logging via `WriterT`+3. Has wrapper for pure logging via `StateT` 4. Supports log rotation 5. Flexibles and easy setting up of loggers (using monoidal builders and lenses) 6. Ability to acquire last `N` megabytes of logs from in-memory cache
examples/Playground.hs view
@@ -5,10 +5,11 @@ import Universum import Data.Yaml.Pretty (defConfig, encodePretty)+import Lens.Micro ((?~)) -import System.Wlog (CanLog, defaultConfig, launchFromFile, launchSimpleLogging, logDebug, logError,- logInfo, logNotice, logWarning, modifyLoggerName, parseLoggerConfig,- productionB, usingLoggerName)+import System.Wlog (CanLog, atLogger, defaultConfig, infoPlus, launchFromFile, launchWithConfig,+ logDebug, logError, logInfo, logNotice, logWarning, ltSeverity,+ modifyLoggerName, parseLoggerConfig, productionB, usingLoggerName) testLoggerConfigPath :: FilePath testLoggerConfigPath = "logger-config-example.yaml"@@ -44,9 +45,10 @@ testToJsonConfigOutput let runPlayLog = testLogging >> showSomeLog - putStrLn $ encodePretty defConfig $ defaultConfig "example"- putTextLn "Default configurations.."- launchSimpleLogging "node" runPlayLog+ putTextLn "Default configurations with modification.."+ launchWithConfig (defaultConfig "node" & atLogger "node" . ltSeverity ?~ infoPlus)+ "node"+ runPlayLog putTextLn "\nFrom file configurations.." launchFromFile testLoggerConfigPath "node" runPlayLog
log-warper.cabal view
@@ -1,5 +1,5 @@ name: log-warper-version: 1.8.3+version: 1.8.4 synopsis: Flexible, configurable, monadic and pretty logging homepage: https://github.com/serokell/log-warper license: MIT@@ -85,6 +85,7 @@ build-depends: log-warper , universum >= 0.3+ , microlens >= 0.4 , yaml >= 0.8.20 hs-source-dirs: examples
src/System/Wlog/IOLogger.hs view
@@ -172,8 +172,8 @@ createLoggers :: [LoggerName] -> LogTree -> LogTree createLoggers xs lt = foldl' addLoggerToTree lt xs -- Add logger to tree - addLoggerToTree :: LogTree -> LoggerName -> LogTree- addLoggerToTree lt x =+ addLoggerToTree :: LoggerName -> LogTree ->LogTree+ addLoggerToTree x lt = if M.member x lt then lt else M.insert x (defaultLogger & lName .~ x) lt
src/System/Wlog/Launcher.hs view
@@ -224,8 +224,4 @@ => LoggerName -> LoggerNameBox m a -> m a-launchSimpleLogging loggerName action =- bracket_- (setupLogging Nothing $ defaultConfig loggerName)- removeAllHandlers- (usingLoggerName loggerName action)+launchSimpleLogging loggerName = launchWithConfig (defaultConfig loggerName) loggerName
src/System/Wlog/LoggerConfig.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE Rank2Types #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-} @@ -42,6 +43,7 @@ , lcTermSeverityErr , lcTree , zoomLogger+ , atLogger -- ** Builders for 'LoggerConfig' , consoleActionB@@ -73,7 +75,9 @@ import qualified Data.HashMap.Strict as HM hiding (HashMap) import qualified Data.Set as Set+import qualified Data.Text as Text import qualified Data.Vector as Vector+import qualified GHC.Show as Show ---------------------------------------------------------------------------- -- Utilites & helpers@@ -351,3 +355,37 @@ -- | Setup 'lcLogsDirectory' inside 'LoggerConfig' to specific prefix. logsDirB :: FilePath -> LoggerConfig logsDirB = maybeLogsDirB . Just++-- | Lens to help to change some particular logger properties.+--+-- For example if you want to use default configurations,+-- but need to change logger's severity to 'warningPlus'+-- you can do it this way:+--+-- @+-- 'System.Wlog.Launcher.launchWithConfig'+-- ( defaultConfig "myLogger"+-- & 'atLogger' "myLogger"+-- . 'ltSeverity' ?~ 'warningPlus' )+-- "myLogger"+-- action+-- @+--+atLogger :: LoggerName -> Traversal' LoggerConfig LoggerTree+atLogger logName = lcTree . leveldown (LoggerName <$> Text.splitOn "." (getLoggerName logName))+ where+ leveldown :: [LoggerName] -> Traversal' LoggerTree LoggerTree+ leveldown [] = bug EmptyLoggerName+ leveldown [x] = getSublogger x+ leveldown (x:xs) = getSublogger x . leveldown xs++ getSublogger :: LoggerName -> Traversal' LoggerTree LoggerTree+ getSublogger x = ltSubloggers . at x . _Just++-- | Exceptions for handling logger exceptions with lens.+data LoggerLensException = EmptyLoggerName++instance Exception LoggerLensException++instance Show LoggerLensException where+ show EmptyLoggerName = "Logger name should be provided"