simple-log 0.1 → 0.1.1
raw patch · 5 files changed
+55/−9 lines, 5 files
Files
- simple-log.cabal +1/−1
- src/System/Log.hs +48/−2
- src/System/Log/Base.hs +4/−4
- src/System/Log/Monad.hs +1/−1
- src/System/Log/Text.hs +1/−1
simple-log.cabal view
@@ -1,5 +1,5 @@ Name: simple-log -Version: 0.1 +Version: 0.1.1 Synopsis: Simple log for Haskell Description: Log library for Haskell with removing unnecessary traces License: BSD3
src/System/Log.hs view
@@ -1,5 +1,51 @@--- | The main ideas of this log library are: +-- | Fast start -- +-- The best way is to define config file, which is auto reloaded periodically, so you can change config while program is running to turn on tracing some function. +-- +-- Typical config file with rule for root scope (see below for explanation): +-- +-- @ +-- \/: use default +-- @ +-- +-- If you want to trace scope named \"foo\", just add: +-- +-- @ +-- \/: use default +-- foo: low trace +-- @ +-- +-- Now \"foo\" and children will be traced even there are no errors. To trace only \"foo\" without children: +-- +-- @ +-- \/: use default +-- foo: low trace +-- foo\/: use default +-- @ +-- +-- \"foo\/\" defines rules for children of \"foo\". +-- +-- Note, that by default all function will log their traces on error, so there is no need to turn on trace manually. You may want to turn on tracing when there are logic errors present without explicit errors (exceptions, or messages with error level). +-- +-- Now we can run our log with auto reloading config every 60 seconds: +-- +-- @ +--run :: IO () +--run = do +-- l <- newLog (fileCfg \"log.cfg\" 60) [logger text (file \"out.log\")] +-- withLog l yourFunction +-- @ +-- +-- And use it: +-- +-- @ +--yourFunction :: (MonadLog m) => m () +--yourFunction = scope \"your\" $ do +-- log Trace \"Hello from your function\" +-- @ +-- +-- The main ideas of this log library are: +-- -- * we don't want to see all unnecessary trace messages when there are no errors, -- -- * but we want to have all possible information about error. @@ -96,7 +142,7 @@ -- rule (relative [\"foo\"]) $ low Trace] -- @ -- --- From now all scope-paths, that contains \"foo\" (all scopes with name "foo") will have politics with 'low' set to Trace. +-- From now all scope-paths, that contains \"foo\" (all scopes with name \"foo\") will have politics with 'low' set to Trace. -- -- We may adjust politics for scope 'foo', that is nested directly in scope 'quux': --
src/System/Log/Base.hs view
@@ -133,11 +133,11 @@ -- | Log message data Message = Message { - messageTime :: UTCTime, + messageTime :: ZonedTime, messageLevel :: Level, messagePath :: [Text], messageText :: Text } - deriving (Eq, Ord, Read, Show) + deriving (Read, Show) instance NFData Message where rnf (Message t l p m) = t `seq` l `seq` rnf p `seq` rnf m @@ -190,7 +190,7 @@ loggerLog' l m = E.handle onError (m `deepseq` loggerLog l m) where onError :: E.SomeException -> IO () onError e = E.handle ignoreError $ do - tm <- getCurrentTime + tm <- getZonedTime loggerLog l $ Message tm Error ["*"] $ fromString $ "Exception during logging message: " ++ show e ignoreError :: E.SomeException -> IO () ignoreError _ = return () @@ -202,7 +202,7 @@ -- | Write message to log writeLog :: Log -> Level -> Text -> IO () writeLog (Log post _) l msg = do - tm <- getCurrentTime + tm <- getZonedTime post $ PostMessage (Message tm l [] msg) -- | New log-scope
src/System/Log/Monad.hs view
@@ -31,7 +31,7 @@ log :: (MonadLog m) => Level -> Text -> m () log l msg = do (Log post _) <- askLog - tm <- liftIO getCurrentTime + tm <- liftIO getZonedTime liftIO $ post $ PostMessage (Message tm l [] msg) scope_ :: (MonadLog m) => Text -> m a -> m a
src/System/Log/Text.hs view
@@ -10,7 +10,7 @@ import System.Log.Base -- | Default time format -defaultTimeFormat = "%d/%m/%y %T" +defaultTimeFormat = "%d/%m/%y %T %z" -- | Text log converter with time format textFmt :: String -> Converter Text