Log Text instead of String

This commit is contained in:
Paul Brinkmeier
2026-09-15 18:35:55 +02:00
parent ad348e2c60
commit de08373d2d
3 changed files with 10 additions and 5 deletions
+9 -2
View File
@@ -1,11 +1,18 @@
module Yore.Log (Yore.Log.error, info) where
module Yore.Log (Yore.Log.error, info, setup) where
import Control.Monad.IO.Class (MonadIO (..))
import Data.Time (ZonedTime, getZonedTime)
import Data.Time.Format (defaultTimeLocale, formatTime)
import GHC.Stack (HasCallStack, SrcLoc (..), callStack, getCallStack)
import System.IO (BufferMode (..), hSetBuffering, stdout)
import Text.Printf (printf)
import qualified Data.Text as Text
import qualified Data.Text.IO as TextIO
setup :: IO ()
setup = hSetBuffering stdout LineBuffering
info :: (HasCallStack, MonadIO m) => String -> m ()
info = doLog "INF"
@@ -16,7 +23,7 @@ doLog :: (HasCallStack, MonadIO m) => String -> String -> m ()
doLog level msg = liftIO $ do
now <- getZonedTime
let location = getLocation $ getCallStack callStack
printf "(%s) (%s) (%s) %s\n" (iso8601Show now) level location msg
TextIO.putStrLn $ Text.pack $ printf "(%s) (%s) (%s) %s" (iso8601Show now) level location msg
where
getLocation :: [(String, SrcLoc)] -> String
-- First entry is always a function from this module, skip it