debug.cr icon indicating copy to clipboard operation
debug.cr copied to clipboard

Proposed changes/additions extracted from how I patched this library for use with the Crystal OpenTelemetry project

Open wyhaines opened this issue 3 years ago • 0 comments

This change does a couple of things. It expands the allowable mechanisms to turn on debugging, so that the -DDEBUG flag, at compilation, also enables debugging. This allows one to build a binary that has debugging always enabled, regardless of ENV settings. It also establishes that any shell-truth value (not empty, not 0, and not false) is an enabling value for the environment variable. i.e.

DEBUG=true my_crystal_program

is logically the same as

DEBUG=1 my_crystal_program

In addition, it adds a macro_debug! macro that inserts macro debugging code. For example:

macro method_missing(call)
  macro_debug!("Method missing: {{ call.name }}")
  (raise NotImplementedError.new([{{ @type.id.stringify }}, "{{ call.name.id }} not implemented"].join("#")))
end

This will print a compile-time debugging message about the missing method, if debugging is enabled.

Both of these are extracted from the Crystal OpenTelemetry project, where I have included them as a substantial monkeypatch in order to use them for internal debugging.

wyhaines avatar Jun 14 '22 22:06 wyhaines