diff --git a/src/System/Logger.hs b/src/System/Logger.hs index cc7ede45227e8638cd5eb686b1355b70a26b1c29..376eaacc344d9b76a281a80e5326f8e6065a165e 100644 --- a/src/System/Logger.hs +++ b/src/System/Logger.hs @@ -32,7 +32,7 @@ module System.Logger , Logger , Level (..) , Output (..) - , DateFormat + , DateFormat (..) , iso8601UTC -- * Core API @@ -57,7 +57,6 @@ module System.Logger ) where import Control.Applicative -import Control.AutoUpdate import Control.Monad import Control.Monad.IO.Class import Data.Maybe (fromMaybe) @@ -120,9 +119,8 @@ new s = liftIO $ do fn StdErr = FL.newStderrLoggerSet fn (Path p) = flip FL.newFileLoggerSet p - mkGetDate "" = return (return id) - mkGetDate f = mkAutoUpdate defaultUpdateSettings - { updateAction = msg . formatUnixTimeGMT (template f) <$> getUnixTime } + mkGetDate Nothing = return (return id) + mkGetDate (Just f) = return (msg . (display f) <$> getUnixTime) mergeWith m e = Map.fromList (readNote "Invalid LOG_LEVEL_MAP" e) `Map.union` m diff --git a/src/System/Logger/Settings.hs b/src/System/Logger/Settings.hs index f8f1c1cb9dfecc2e27f777991dab4880dc3dbf27..236ab0e88a435254fa7df49dde9e4590e18ca9d8 100644 --- a/src/System/Logger/Settings.hs +++ b/src/System/Logger/Settings.hs @@ -38,18 +38,19 @@ import Data.ByteString (ByteString) import Data.ByteString.Char8 (pack) import Data.Map.Strict as Map import Data.Text (Text) +import Data.UnixTime import System.Log.FastLogger (defaultBufSize) import System.Logger.Message data Settings = Settings - { _logLevel :: !Level -- ^ messages below this log level will be suppressed - , _levelMap :: !(Map Text Level) -- ^ log level per named logger - , _output :: !Output -- ^ log sink - , _format :: !DateFormat -- ^ the timestamp format (use \"\" to disable timestamps) - , _delimiter :: !ByteString -- ^ text to intersperse between fields of a log line - , _netstrings :: !Bool -- ^ use encoding (fixes delimiter to \",\") - , _bufSize :: !Int -- ^ how many bytes to buffer before commiting to sink - , _name :: !(Maybe Text) -- ^ logger name + { _logLevel :: !Level -- ^ messages below this log level will be suppressed + , _levelMap :: !(Map Text Level) -- ^ log level per named logger + , _output :: !Output -- ^ log sink + , _format :: !(Maybe DateFormat) -- ^ the timestamp format + , _delimiter :: !ByteString -- ^ text to intersperse between fields of a log line + , _netstrings :: !Bool -- ^ use encoding (fixes delimiter to \",\") + , _bufSize :: !Int -- ^ how many bytes to buffer before commiting to sink + , _name :: !(Maybe Text) -- ^ logger name , _nameMsg :: !(Msg -> Msg) } @@ -60,11 +61,11 @@ setOutput :: Output -> Settings -> Settings setOutput x s = s { _output = x } -- | The time and date format used for the timestamp part of a log line. -format :: Settings -> DateFormat +format :: Settings -> Maybe DateFormat format = _format setFormat :: DateFormat -> Settings -> Settings -setFormat x s = s { _format = x } +setFormat x s = s { _format = Just x } bufSize :: Settings -> Int bufSize = _bufSize @@ -135,11 +136,11 @@ data Output deriving (Eq, Ord, Show) newtype DateFormat = DateFormat - { template :: ByteString - } deriving (Eq, Ord, Show) + { display :: UnixTime -> ByteString + } instance IsString DateFormat where - fromString = DateFormat . pack + fromString = DateFormat . formatUnixTimeGMT . pack -- | ISO 8601 date-time format. iso8601UTC :: DateFormat @@ -162,5 +163,13 @@ iso8601UTC = "%Y-%0m-%0dT%0H:%0M:%0SZ" -- * 'name' = Nothing -- defSettings :: Settings -defSettings = Settings Debug Map.empty StdOut iso8601UTC ", " False defaultBufSize Nothing id - +defSettings = Settings + Debug + Map.empty + StdOut + (Just iso8601UTC) + ", " + False + defaultBufSize + Nothing + id diff --git a/tinylog.cabal b/tinylog.cabal index c76531ea8429f48a9f1c6c2ba82a8691cd116414..33581c490f49e9e5c725be59528f9890e907db56 100644 --- a/tinylog.cabal +++ b/tinylog.cabal @@ -37,7 +37,6 @@ library build-depends: base >= 4.6 && < 5 , bytestring >= 0.10.4 && < 1.0 - , auto-update >= 0.1 && < 0.2 , containers >= 0.5 , double-conversion >= 0.2 && < 3.0 , fast-logger >= 2.1.4 && < 3.0