From 3c889cb56511af08b438047a9a3bceb9becd6940 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 20 Nov 2021 07:49:41 -1000 Subject: [PATCH] imp: lib: dlog --- hledger-lib/Hledger/Utils/Debug.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Utils/Debug.hs b/hledger-lib/Hledger/Utils/Debug.hs index 988943fbc..a77a6b291 100644 --- a/hledger-lib/Hledger/Utils/Debug.hs +++ b/hledger-lib/Hledger/Utils/Debug.hs @@ -93,7 +93,7 @@ module Hledger.Utils.Debug ( ,module Debug.Trace ,useColorOnStdout ,useColorOnStderr - ) + ,dlog) where import Control.Monad (when) @@ -305,6 +305,10 @@ ptraceAtWith level f -- in trace (s++":"++nlorspace++intercalate "\n" ls') a in trace p a +-- | Log a pretty-printed showable value to "./debug.log". Uses unsafePerformIO. +dlog :: Show a => a -> a +dlog x = unsafePerformIO $ appendFile "debug.log" (pshow x ++ "\n") >> return x + -- "dbg" would clash with megaparsec. -- | Pretty-print a label and the showable value to the console, then return it. dbg0 :: Show a => String -> a -> a