diff --git a/src/Yore/Log.hs b/src/Yore/Log.hs index 845eb07..8b4705b 100644 --- a/src/Yore/Log.hs +++ b/src/Yore/Log.hs @@ -1,6 +1,7 @@ module Yore.Log (Yore.Log.error, info) where -import Data.Time (getZonedTime) +import Data.Time (ZonedTime, getZonedTime) +import Data.Time.Format (defaultTimeLocale, formatTime) import GHC.Stack (HasCallStack, SrcLoc (..), callStack, getCallStack) import Text.Printf (printf) @@ -14,9 +15,14 @@ doLog :: (HasCallStack) => String -> String -> IO () doLog level msg = do now <- getZonedTime let location = getLocation $ getCallStack callStack - printf "(%s) (%s) (%s) %s\n" (show now) location level msg + printf "(%s) (%s) (%s) %s\n" (iso8601Show now) location level msg where getLocation :: [(String, SrcLoc)] -> String -- First entry is always a function from this module, skip it getLocation (_ : (_, srcLoc) : _) = printf "%s:%d" (srcLocFile srcLoc) (srcLocStartLine srcLoc) getLocation _ = "" + +-- | Unlike 'Data.Time.Format.ISO8601.iso8601Show', this function +-- aligns the second decimals. This is purely for asthetic reasons. +iso8601Show :: ZonedTime -> String +iso8601Show = formatTime defaultTimeLocale "%FT%T%02Q%Ez"