easy-logger 0.1.0.0 → 0.1.0.2
raw patch · 5 files changed
+33/−15 lines, 5 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ EasyLogger.Util: liftLoc :: Loc -> Q Exp
Files
- README.md +1/−1
- easy-logger.cabal +2/−1
- src/EasyLogger/Logger.hs +10/−12
- src/EasyLogger/Util.hs +18/−0
- test/Spec.hs +2/−1
README.md view
@@ -18,7 +18,7 @@ # At the end of your program, flush the buffers: finalizeAllLoggers -You can also include the logs of the libraries that you use and which use the @easy-logger@ package+You can also include the logs of the libraries that you use and which use the `easy-logger` package for logging. If the library maintainer is nice, (s)he allows you to turn on/off logging for that library only. See the Library section below how to do it. To turn logging for all packages (that use easy-logger) on, do this:
easy-logger.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: easy-logger-version: 0.1.0.0+version: 0.1.0.2 synopsis: Logging made easy. description: Please see the README on GitHub at <https://github.com/githubuser/easy-logger#readme> category: Logging@@ -33,6 +33,7 @@ EasyLogger.LoggerSet EasyLogger.LogStr EasyLogger.Push+ EasyLogger.Util other-modules: Paths_easy_logger hs-source-dirs:
src/EasyLogger/Logger.hs view
@@ -48,8 +48,11 @@ import EasyLogger.LogStr import EasyLogger.LoggerSet import EasyLogger.Push+import EasyLogger.Util (liftLoc) +import Debug.Trace+ -- | Add a @LoggerSet@ to the known loggers. setLoggerSet :: String -> LoggerSet -> IO () setLoggerSet pkgName set = modifyIORef' loggerSets (M.insert pkgName set)@@ -142,6 +145,10 @@ defaultLogPkgName :: String defaultLogPkgName = "__default__" +mainLogPkgName :: String+mainLogPkgName = "main"++ -- | The default buffer size (4,096 bytes). defaultBufSize :: BufSize defaultBufSize = 4096@@ -175,8 +182,9 @@ now <- join (readIORef cachedTime) readIORef loggerSets >>= \sets -> case getLogger sets of- -- Nothing | M.null sets -> error "You must call `initLogger` at the start of your application! See the documentation of `EasyLogger.Logger`."- Nothing -> return ()+ Nothing -- Check the package name of the caller, as otherwise any library logging would halt the process.+ | M.null sets && pkg == mainLogPkgName -> error "You must call `initLogger` at the start of your application! See the documentation of `EasyLogger.Logger`."+ Nothing -> return () Just set -> pushLogStr set (defaultLogStr loc now level (toLogStr msg)) where getLogger sets = M.lookup pkg sets <|> M.lookup defaultLogPkgName sets@@ -349,15 +357,5 @@ defaultMinLogMsgLen :: Int defaultMinLogMsgLen = 60---liftLoc :: Loc -> Q Exp-liftLoc (Loc a b c (d1, d2) (e1, e2)) = [|Loc- $(TH.lift a)- $(TH.lift b)- $(TH.lift c)- ($(TH.lift d1), $(TH.lift d2))- ($(TH.lift e1), $(TH.lift e2))- |]
+ src/EasyLogger/Util.hs view
@@ -0,0 +1,18 @@+{-# LANGUAGE TemplateHaskell #-}+module EasyLogger.Util+ ( liftLoc+ ) where++import Language.Haskell.TH.Syntax as TH+++liftLoc :: Loc -> Q Exp+liftLoc (Loc a b c (d1, d2) (e1, e2)) = [|Loc+ $(TH.lift a)+ $(TH.lift b)+ $(TH.lift c)+ ($(TH.lift d1), $(TH.lift d2))+ ($(TH.lift e1), $(TH.lift e2))+ |]++
test/Spec.hs view
@@ -6,7 +6,7 @@ -- imports import qualified Data.Text as T-import Logging+import EasyLogger import Test.QuickCheck -- file Spec.hs@@ -66,3 +66,4 @@ describe "initialization" $ do it "throws an exception if not initialized" $ prop_NoInit `shouldThrow` anyException+