Skip to content
Debug mode log/assertion for C/Objective-C in a file
Objective-C Ruby Objective-C++
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.

cdebug is tiny debug utility for C/Objective-C

cdebug is designed to allow C/Objective-C developers to enable debug mode log/assertion with a single file.

  • Functions can be effortlessly 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



dprintf is shallow wrapper for printf.

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


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 is shallow wrapper for assert.

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


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


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)
You can’t perform that action at this time.