mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-28 12:54:07 +03:00
lib: debug: add a log0 that writes to debug.log in the current directory
Seems to work somewhat, might have some laziness issues.
This commit is contained in:
parent
f666d5fc25
commit
1d5f3a44d5
@ -151,7 +151,7 @@ dbg9IO :: (MonadIO m, Show a) => String -> a -> m ()
|
||||
dbg9IO = tracePrettyAtIO 9
|
||||
|
||||
-- | Pretty-print a message and a showable value to the console if the debug level is at or above the specified level.
|
||||
-- dbtAt 0 always prints. Otherwise, uses unsafePerformIO.
|
||||
-- At level 0, always prints. Otherwise, uses unsafePerformIO.
|
||||
tracePrettyAt :: Show a => Int -> String -> a -> a
|
||||
tracePrettyAt lvl = dbgppshow lvl
|
||||
|
||||
@ -171,6 +171,25 @@ tracePrettyAt lvl = dbgppshow lvl
|
||||
tracePrettyAtIO :: (MonadIO m, Show a) => Int -> String -> a -> m ()
|
||||
tracePrettyAtIO lvl lbl x = liftIO $ tracePrettyAt lvl lbl x `seq` return ()
|
||||
|
||||
log0 :: Show a => String -> a -> a
|
||||
log0 = logPrettyAt 0
|
||||
|
||||
-- | Log a message and a pretty-printed showable value to ./debug.log,
|
||||
-- if the debug level is at or above the specified level.
|
||||
-- At level 0, always logs. Otherwise, uses unsafePerformIO.
|
||||
logPrettyAt :: Show a => Int -> String -> a -> a
|
||||
logPrettyAt lvl
|
||||
| lvl > 0 && debugLevel < lvl = flip const
|
||||
| otherwise = \s a ->
|
||||
let p = ppShow a
|
||||
ls = lines p
|
||||
nlorspace | length ls > 1 = "\n"
|
||||
| otherwise = " " ++ take (10 - length s) (repeat ' ')
|
||||
ls' | length ls > 1 = map (" "++) ls
|
||||
| otherwise = ls
|
||||
output = s++":"++nlorspace++intercalate "\n" ls'
|
||||
in unsafePerformIO $ appendFile "debug.log" output >> return a
|
||||
|
||||
-- | print this string to the console before evaluating the expression,
|
||||
-- if the global debug level is at or above the specified level. Uses unsafePerformIO.
|
||||
-- dbgtrace :: Int -> String -> a -> a
|
||||
|
Loading…
Reference in New Issue
Block a user