Skip to content

Conversation

wyhaines
Copy link

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 added 3 commits June 14, 2022 13:13
…sms 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. In addition, it adds a `macro_debug!` macro that inserts _macro_ debugging code. Both of these are extracted from the Crystal OpenTelemetry project, where I have included them as a massive monkeypatch in order to use them for internal debugging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant