From fb2f643efae7d2a70845ecd205812403b9fbaf5a Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Wed, 8 Jan 2025 10:44:52 -0500 Subject: [PATCH] Make logging lazy in the string Make the logging functions accept a Lazy String so we don't pay formatting costs when we don't need to --- src/Main.md | 4 ++-- src/Util/Eff.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Main.md b/src/Main.md index 726b85e..b8aae63 100644 --- a/src/Main.md +++ b/src/Main.md @@ -250,7 +250,7 @@ Putting this in its own function makes dealing with the potential error returned ```idris -- print to standard error - ePutStrLn : String -> IO () + ePutStrLn : Lazy String -> IO () ePutStrLn str = do _ <- fPutStrLn stderr str pure () @@ -274,7 +274,7 @@ This function uses the provided `String -> IO ()` to remove the `Writer` from th -- Lowers logging into IO within the effect using the given IO function handleLog : Has (WriterL "log" String) fs => Has IO (fs - WriterL "log" String) => - (tell : String -> IO ()) -> Eff fs a -> Eff (fs - (WriterL "log" String)) a + (tell : Lazy String -> IO ()) -> Eff fs a -> Eff (fs - (WriterL "log" String)) a handleLog tell x = handle (\msg, f => diff --git a/src/Util/Eff.md b/src/Util/Eff.md index 4c6975c..358cf0a 100644 --- a/src/Util/Eff.md +++ b/src/Util/Eff.md @@ -20,19 +20,19 @@ namespace Logging --> ```idris export - info : Has (WriterL "log" String) fs => String -> Eff fs () + info : Has (WriterL "log" String) fs => Lazy String -> Eff fs () info str = let tag = show . bolden . show . colored Green $ "[INFO]" in tellAt "log" (tag ++ ": " ++ str ++ "\n") export - debug : Has (WriterL "log" String) fs => String -> Eff fs () + debug : Has (WriterL "log" String) fs => Lazy String -> Eff fs () debug str = let tag = show . bolden . show . colored BrightWhite $ "[DEBUG]" in tellAt "log" (tag ++ ": " ++ str ++ "\n") export - warn : Has (WriterL "log" String) fs => String -> Eff fs () + warn : Has (WriterL "log" String) fs => Lazy String -> Eff fs () warn str = let tag = show . bolden . show . colored Yellow $ "[WARN]" in tellAt "log" (tag ++ ": " ++ str ++ "\n")