Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Debug mode log/assertion for C/Objective-C in a file
C Ruby Objective-C++ Objective-C
tree: 9eb416b1e6

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
supports
.gitignore
LICENSE
README.md
debug.h

README.md

cdebug is tiny debug utility for C/Objective-C code

  • Functions are enabled/disabled by debug macro 'DEBUG'
  • Conditional log, assertion with log

See document on Github

How to setup

To take advantage of this feature, do one of below:

  • Insert #define DEBUG 1
  • Add compiler option -DDEBUG

To force disabling this function without eliminating 'DEBUG' macro, set NO_DEBUG

functions

dprintf

dprintf is shallow wrapper for printf.

dprintf insert filename, line number, timestamp, newline by options

dlog

dlog is dprintf with test.

dlog is triggered only if first parameter condition passes test. For example:

  • #define LOG_ERROR 3
  • #define LOG_WARNING 2
  • #define LOG_INFO 1
  • dlog(LOG_WARNING, "Warn!");

This would be triggered only if DEBUG_LOGLEVEL is lesser than DEBUG_WARNING.

You can redefine test. See DEBUG_LOGTEST in options.

dassert

dassert is shallow wrapper for assert.

dassert is triggered only in debug mode. For release mode, use raw 'assert'.

dassertlog

dassertlog is dassert + dprintf When condition is false, both dprintf and dassert triggered.

options

Define options if you don't like default

  1. DEBUG_WITH_FILE to enable __FILE__ macro (default: enabled)
  2. DEBUG_WITH_LINE to enable __LINE__ macro (default: enabled)
  3. DEBUG_WITH_TIME to enable runtime timestamp (default: enabled)
  4. DEBUG_NEWLINE to enable newline insertion (default: enabled)
  5. DEBUG_LOGLEVEL to define dlog trigger level (default: enabled)
  6. DEBUG_LOGTEST(LV) to define dlog trigger test. (default: LV >= DEBUG_LOGLEVEL)
  7. DEBUG_ASSERT to enable real assert in dassert (default: enabled)
  8. DEBUG_PRINTF to define printf function (default: printf in stdio.h)
  9. DEBUG_USE_NSLOG to enable automated NSLog flag for objective-c context (default: enabled)
Something went wrong with that request. Please try again.