packages feed

micrologger 0.4.0.0 → 0.4.0.1

raw patch · 4 files changed

+15/−17 lines, 4 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ LuminescentDreams.Logger.Internal: tzFormat :: String

Files

micrologger.cabal view
@@ -1,5 +1,5 @@ name:                micrologger-version:             0.4.0.0+version:             0.4.0.1 synopsis:            A super simple logging module. Only for use for very simple projects. description:         A super simple logging module. Only for use for very simple projects. homepage:            https://github.com/savannidgerinel/micrologger#readme
src/LuminescentDreams/Logger/Internal.hs view
@@ -12,6 +12,9 @@               | LogEmergency               deriving (Eq, Ord, Show) +tzFormat :: String+tzFormat = "%Y-%m-%dT%H:%M:%S%Q%z"+ {- | The primary data structure to contain a logger of any kind. -} data Logger = Logger { logCmd_ :: (T.Text -> IO ())                        -- ^ Any IO action that accepts the log message
src/LuminescentDreams/Logger/JSON.hs view
@@ -5,6 +5,7 @@ {-# LANGUAGE OverloadedStrings  #-} module LuminescentDreams.Logger.JSON ( logMsgJs, formatMsgJs ) where +import           Control.Monad            (when) import           Data.Monoid import qualified Data.Aeson               as Aeson import qualified Data.Map                 as M@@ -19,16 +20,14 @@ {- | Log a message in LogZ format. This uses `formatMsgJs` to generate the actual format string. -} logMsgJs :: Logger -> LogLevel -> [(String, Aeson.Value)] -> IO () logMsgJs (Logger writer pri) lvl msg =-  if lvl >= pri-    then do-      t <- Time.getCurrentTime-      writer $ formatMsgJs t lvl msg-    else return ()+    when (lvl >= pri) $ do+        t <- Time.getCurrentTime+        writer $ formatMsgJs t lvl msg  {- | Format a message for LogZ JSON format. -} formatMsgJs :: Time.UTCTime -> LogLevel -> [(String, Aeson.Value)] -> T.Text formatMsgJs time level msg =-  let msg_ = msg <> [ ("@timestamp", fromString $ Time.formatTime Time.defaultTimeLocale "%Y-%m-%dT%H:%M:%S" time)+  let msg_ = msg <> [ ("@timestamp", fromString $ Time.formatTime Time.defaultTimeLocale tzFormat time)                     , ("@level", Aeson.String $ T.toStrict $ TF.format "{}" (TF.Only level))                     ]   in TEnc.decodeUtf8 $ Aeson.encode $ M.fromList msg_
src/LuminescentDreams/Logger/Standard.hs view
@@ -1,12 +1,10 @@-{-# LANGUAGE DeriveFunctor          #-} {-# LANGUAGE FlexibleInstances      #-}-{-# LANGUAGE FunctionalDependencies #-} {-# LANGUAGE MultiParamTypeClasses  #-} {-# LANGUAGE OverloadedStrings      #-}-{-# LANGUAGE RecordWildCards        #-} {-# OPTIONS_GHC -fno-warn-orphans   #-} module LuminescentDreams.Logger.Standard ( logMsgStd, formatMsgStd ) where +import           Control.Monad            (when) import           Data.Monoid import qualified Data.Text.Format         as TF import qualified Data.Text.Lazy           as T@@ -24,16 +22,14 @@  logMsg_ :: Logger -> LogMsg -> IO () logMsg_ (Logger writer pri) msg@(LogMsg lvl _ _) =-  if lvl >= pri-    then do-      t <-  Time.getCurrentTime-      writer $ formatMsgStd t msg-    else return ()+    when (lvl >= pri) $ do+        t <-  Time.getCurrentTime+        writer $ formatMsgStd t msg   formatMsgStd :: Time.UTCTime -> LogMsg -> T.Text formatMsgStd t (LogMsg lvl tags text) =-  TF.format "{} {} {} {}" (Time.formatTime Time.defaultTimeLocale "%Y-%m-%d %H:%M:%S" t, lvl, tags, text)+  TF.format "{} {} {} {}" (Time.formatTime Time.defaultTimeLocale tzFormat t, lvl, tags, text)   instance TFB.Buildable (String, String) where@@ -43,5 +39,5 @@   -- build lst = TFB.build "[" <> TFB.build `fmap` lst "]"   build lst =     mconcat $ [TFB.build ("[" :: String)]-           <>  (List.intersperse (TFB.build (", " :: String)) (TFB.build `fmap` lst))+           <> List.intersperse (TFB.build (", " :: String)) (TFB.build `fmap` lst)            <> [TFB.build ("]" :: String)]