From 2c2d10f9c249029df3c2fca2d9d4d55ca5096401 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 17 Oct 2018 07:25:39 -0700 Subject: [PATCH] lib: plog, plogAt: add missing newline, note issue --- hledger-lib/Hledger/Utils/Debug.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Hledger/Utils/Debug.hs b/hledger-lib/Hledger/Utils/Debug.hs index 055282dfc..4c3e2b432 100644 --- a/hledger-lib/Hledger/Utils/Debug.hs +++ b/hledger-lib/Hledger/Utils/Debug.hs @@ -192,12 +192,15 @@ dbg9IO :: (MonadIO m, Show a) => String -> a -> m () dbg9IO = ptraceAtIO 9 -- | Log a message and a pretty-printed showable value to ./debug.log, then return it. +-- Can fail, see plogAt. plog :: Show a => String -> a -> a plog = plogAt 0 -- | Log a message and a pretty-printed showable value to ./debug.log, -- if the global debug level is at or above the specified level. -- At level 0, always logs. Otherwise, uses unsafePerformIO. +-- XXX Can fail due to log file contention if called multiple times +-- ("*** Exception: debug.log: openFile: resource busy (file is locked)"). plogAt :: Show a => Int -> String -> a -> a plogAt lvl | lvl > 0 && debugLevel < lvl = flip const @@ -208,13 +211,11 @@ plogAt lvl | otherwise = " " ++ take (10 - length s) (repeat ' ') ls' | length ls > 1 = map (" "++) ls | otherwise = ls - output = s++":"++nlorspace++intercalate "\n" ls' + output = s++":"++nlorspace++intercalate "\n" ls'++"\n" in unsafePerformIO $ appendFile "debug.log" output >> return a --- XXX redundant ? More/less robust than log0 ? +-- XXX redundant ? More/less robust than plogAt ? -- -- | Like dbg, but writes the output to "debug.log" in the current directory. --- -- Uses unsafePerformIO. Can fail due to log file contention if called too quickly --- -- ("*** Exception: debug.log: openFile: resource busy (file is locked)"). -- dbglog :: Show a => String -> a -> a -- dbglog label a = -- (unsafePerformIO $