hledger-lib-1.19.1: A reusable library providing the core functionality of hledger

Safe Haskell | None
Language | Haskell2010

Hledger.Utils.Debug

Description

Debugging helpers.

You can enable increasingly verbose debug output by adding --debug [1-9] to a hledger command line. --debug with no argument means --debug 1. This is implemented by calling dbgN or similar helpers, defined below. These calls can be found throughout hledger code; they have been added organically where it seemed likely they would be needed again. The choice of debug level has not been very systematic. 202006 Here's a start at some guidelines, not yet applied project-wide:

Debug level: What to show: ------------ --------------------------------------------------------- 0 normal command output only (no warnings, eg) 1 (--debug) useful warnings, most common troubleshooting info, eg valuation 2 common troubleshooting info, more detail 3 report options selection 4 report generation 5 report generation, more detail 6 input file reading 7 input file reading, more detail 8 command line parsing 9 any other rarely needed / more in-depth info

Tip: when debugging with GHCI, the first run after loading Debug.hs sets the debug level. If you need to change it, you must touch Debug.hs, :reload in GHCI, then run the command with a new --debug value. Or, often it's more convenient to add a temporary dbg0 and :reload (dbg0 always prints).

Synopsis

- pprint :: Show a => a -> IO ()
- pshow :: Show a => a -> String
- ptrace :: Show a => a -> a
- traceWith :: Show a => (a -> String) -> a -> a
- traceAt :: Int -> String -> a -> a
- traceAtWith :: (a -> String) -> a -> a
- debugLevel :: Int
- ptraceAt :: Show a => Int -> String -> a -> a
- ptraceAtWith :: Show a => Int -> (a -> String) -> a -> a
- dbg0 :: Show a => String -> a -> a
- dbg1 :: Show a => String -> a -> a
- dbg2 :: Show a => String -> a -> a
- dbg3 :: Show a => String -> a -> a
- dbg4 :: Show a => String -> a -> a
- dbg5 :: Show a => String -> a -> a
- dbg6 :: Show a => String -> a -> a
- dbg7 :: Show a => String -> a -> a
- dbg8 :: Show a => String -> a -> a
- dbg9 :: Show a => String -> a -> a
- dbg0With :: Show a => (a -> String) -> a -> a
- dbg1With :: Show a => (a -> String) -> a -> a
- dbg2With :: Show a => (a -> String) -> a -> a
- dbg3With :: Show a => (a -> String) -> a -> a
- dbg4With :: Show a => (a -> String) -> a -> a
- dbg5With :: Show a => (a -> String) -> a -> a
- dbg6With :: Show a => (a -> String) -> a -> a
- dbg7With :: Show a => (a -> String) -> a -> a
- dbg8With :: Show a => (a -> String) -> a -> a
- dbg9With :: Show a => (a -> String) -> a -> a
- dbgExit :: Show a => String -> a -> a
- ptraceAtIO :: (MonadIO m, Show a) => Int -> String -> a -> m ()
- dbg0IO :: (MonadIO m, Show a) => String -> a -> m ()
- dbg1IO :: (MonadIO m, Show a) => String -> a -> m ()
- dbg2IO :: (MonadIO m, Show a) => String -> a -> m ()
- dbg3IO :: (MonadIO m, Show a) => String -> a -> m ()
- dbg4IO :: (MonadIO m, Show a) => String -> a -> m ()
- dbg5IO :: (MonadIO m, Show a) => String -> a -> m ()
- dbg6IO :: (MonadIO m, Show a) => String -> a -> m ()
- dbg7IO :: (MonadIO m, Show a) => String -> a -> m ()
- dbg8IO :: (MonadIO m, Show a) => String -> a -> m ()
- dbg9IO :: (MonadIO m, Show a) => String -> a -> m ()
- plog :: Show a => String -> a -> a
- plogAt :: Show a => Int -> String -> a -> a
- traceParse :: String -> TextParser m ()
- dbgparse :: Int -> String -> TextParser m ()
- module Debug.Trace

# Documentation

pprint :: Show a => a -> IO () Source #

Pretty print. Easier alias for pretty-show's pPrint.

pshow :: Show a => a -> String Source #

Pretty show. Easier alias for pretty-show's ppShow.

ptrace :: Show a => a -> a Source #

Pretty trace. Easier alias for traceShowId + ppShow.

traceWith :: Show a => (a -> String) -> a -> a Source #

Like traceShowId, but uses a custom show function to render the value. traceShowIdWith was too much of a mouthful.

traceAt :: Int -> String -> a -> a Source #

Trace (print to stderr) a string if the global debug level is at or above the specified level. At level 0, always prints. Otherwise, uses unsafePerformIO.

traceAtWith :: (a -> String) -> a -> a Source #

Trace (print to stderr) a showable value using a custom show function.

debugLevel :: Int Source #

Global debug level, which controls the verbosity of debug output on the console. The default is 0 meaning no debug output. The `--debug` command line flag sets it to 1, or `--debug=N` sets it to a higher value (note: not `--debug N` for some reason). This uses unsafePerformIO and can be accessed from anywhere and before normal command-line processing. When running with :main in GHCI, you must touch and reload this module to see the effect of a new --debug option. After command-line processing, it is also available as the `debug_` field of `CliOpts`. {--} {--}

ptraceAt :: Show a => Int -> String -> a -> a Source #

Pretty-print a label and a showable value to the console if the global debug level is at or above the specified level. At level 0, always prints. Otherwise, uses unsafePerformIO.

ptraceAtWith :: Show a => Int -> (a -> String) -> a -> a Source #

Like ptraceAt, but takes a custom show function instead of a label.

dbg0 :: Show a => String -> a -> a Source #

Pretty-print a label and the showable value to the console, then return it.

dbg1 :: Show a => String -> a -> a Source #

Pretty-print a label and the showable value to the console when the global debug level is >= 1, then return it. Uses unsafePerformIO.

dbg2 :: Show a => String -> a -> a Source #

dbg3 :: Show a => String -> a -> a Source #

dbg4 :: Show a => String -> a -> a Source #

dbg5 :: Show a => String -> a -> a Source #

dbg6 :: Show a => String -> a -> a Source #

dbg7 :: Show a => String -> a -> a Source #

dbg8 :: Show a => String -> a -> a Source #

dbg9 :: Show a => String -> a -> a Source #

dbg0With :: Show a => (a -> String) -> a -> a Source #

Like dbg0, but takes a custom show function instead of a label.

dbg1With :: Show a => (a -> String) -> a -> a Source #

dbg2With :: Show a => (a -> String) -> a -> a Source #

dbg3With :: Show a => (a -> String) -> a -> a Source #

dbg4With :: Show a => (a -> String) -> a -> a Source #

dbg5With :: Show a => (a -> String) -> a -> a Source #

dbg6With :: Show a => (a -> String) -> a -> a Source #

dbg7With :: Show a => (a -> String) -> a -> a Source #

dbg8With :: Show a => (a -> String) -> a -> a Source #

dbg9With :: Show a => (a -> String) -> a -> a Source #

dbgExit :: Show a => String -> a -> a Source #

Like dbg0, but also exit the program. Uses unsafePerformIO.

ptraceAtIO :: (MonadIO m, Show a) => Int -> String -> a -> m () Source #

Like ptraceAt, but convenient to insert in an IO monad and enforces monadic sequencing (plus convenience aliases). XXX These have a bug; they should use traceIO, not trace, otherwise GHC can occasionally over-optimise (cf lpaste a few days ago where it killed/blocked a child thread).

dbg0IO :: (MonadIO m, Show a) => String -> a -> m () Source #

dbg1IO :: (MonadIO m, Show a) => String -> a -> m () Source #

dbg2IO :: (MonadIO m, Show a) => String -> a -> m () Source #

dbg3IO :: (MonadIO m, Show a) => String -> a -> m () Source #

dbg4IO :: (MonadIO m, Show a) => String -> a -> m () Source #

dbg5IO :: (MonadIO m, Show a) => String -> a -> m () Source #

dbg6IO :: (MonadIO m, Show a) => String -> a -> m () Source #

dbg7IO :: (MonadIO m, Show a) => String -> a -> m () Source #

dbg8IO :: (MonadIO m, Show a) => String -> a -> m () Source #

dbg9IO :: (MonadIO m, Show a) => String -> a -> m () Source #

plog :: Show a => String -> a -> a Source #

Log a label and a pretty-printed showable value to ./debug.log, then return it. Can fail, see plogAt.

plogAt :: Show a => Int -> String -> a -> a Source #

Log a label 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. Tends to fail if called more than once, at least when built with -threaded (Exception: debug.log: openFile: resource busy (file is locked)).

traceParse :: String -> TextParser m () Source #

Print the provided label (if non-null) and current parser state (position and next input) to the console. (See also megaparsec's dbg.)

dbgparse :: Int -> String -> TextParser m () Source #

Convenience alias for traceParseAt

module Debug.Trace