Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make debug logging configurable #84

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

warmwaffles
Copy link

@warmwaffles warmwaffles commented Sep 11, 2024

I noticed that Logger.configure is called during compilation to try and shut the logger up for normal use. Instead I lifted all of the Logger.debug calls to a helper log_debug function that effectively no-ops when not in debug mode.

In exqlite I use the V=1 environment variable to spit out compilation debug info for make files. I don't know if this is something desired for the project, so I just stuck with DEBUG as the env var.

With debug log enabled

# DEBUG=yes mix compile --force
Compiling 22 files (.ex)

10:50:17.327 [debug] ----- Territory -----

10:50:17.334 [debug] %ExPhoneNumber.Metadata.P
.....

With debug log disabled

#mix compile --force
Compiling 22 files (.ex)
Generated ex_phone_number app

You may also specify debug_log: true in your configuration prior to compilation as well.

config :ex_phone_number,
  log_level: :debug,
  debug_log: true

And of course, at runtime you can force it to true and execute the PhoneMetadata parsing and it'll log the data out.

When the logger mode is not in debug mode, we should not be generating
strings only to have them ignored. Using `inspect/1` is not free and we
can be a little more memory efficient with this.
This forces the logger level to whatever the level is defined for
`:ex_phone_number` on compilation, but this poisons the logger
configuration downstream for other dependencies as they are compiled.
With debug log enabled

```
Compiling 22 files (.ex)

10:50:17.327 [debug] ----- Territory -----

10:50:17.334 [debug] %ExPhoneNumber.Metadata.P
.....
```

With debug log disabled

```
Compiling 22 files (.ex)
Generated ex_phone_number app
```
@warmwaffles warmwaffles changed the title Stop generating interpolated strings for debug log Make debug logging configurable Sep 11, 2024
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