bazel-gazelle
bazel-gazelle copied to clipboard
Add link to bazel-gazelle-debug extension.
Add link to bazel-gazelle-debug extension.
@pcj honestly, I think this is just a really useful debugging feature. Would you have any interest in including it as a "language" in the main repo of Gazelle?
Thanks @achew22, I'd be happy to contribute it upstream. I'll do a little thinking on the best way to do that. Are you OK with taking on an additional dependency?
As always, it's about what the trade-offs are? What's the library that you need to import? Is it one that we already have functionality coverage from a different dependency or the standard library?
I ended up using https://github.com/rs/zerolog for this and really like the structured logging API.
I was thinking, if we did merge it upstream, to make the getDebugConfig
(and the debugConfig
) public, so other extensions, languages could access the logging capabilities.
Ah, interesting. The Gazelle repo currently uses stdlib
's log
package. I'm not sure if you're familiar with it, but it is a configurable logger that can include timestamp information, logging line (and path) information, etc. In no way do I object to structured logging or anything like that, I'm just trying to keep the 3p deps that consumers actually depend upon to a minimum because they can make things very complicated (Gazelle can depend on a specific version of a dep that's incompatible with someone who's using Gazelle for example). I guess what I'm saying is that the library you grabbed looks too good to be brought in as a 3p dep 😉 .
I did a quick check on this theory:
achew@localhost /tmp/bazel-gazelle-debug (master)$ ag dc\\.
language/debug/generate.go
26: dc.Debug().
33: dc.Debug().
41: dc.Trace().
53: if dc.generaterulesSlowWarnDuration != 0 && diff > dc.generaterulesSlowWarnDuration {
54: dc.Warn().
62: dc.Debug().
68: if dc.showTotalElapsedTimeMessages {
69: dc.Info().
language/debug/debugconfig.go
18: return dc.(*debugConfig)
language/debug/resolve.go
47: dc.Debug().
language/debug/config.go
28: dc.Logger = dc.Logger.Level(level)
32: dc.showTotalElapsedTimeMessages = (progress == "true" || progress == "1")
44: dc.Debug().
68: dc.Debug().Str("dir", rel).Msg("visiting")
72: dc.Debug().
83: dc.Logger = dc.Logger.Level(level)
88: dc.showTotalElapsedTimeMessages = true
90: dc.showTotalElapsedTimeMessages = false
97: dc.generaterulesSlowWarnDuration = threshold
Given that there are on the order of 10 of these, WDYT about explicitly printing the values?
// As an example
dc.Debug().Str("dir", rel).Msg("visiting")
// Could become
log.Printf("dir %s, visiting" rel)
Or possibly providing a very lite Logger
struct that exposes Debug
, Trace
and whatever logging levels are necessary?
Yes, I agree. I used that dependency and I like it, but it's not justified for inclusion into gazelle proper, it can be done reasonably well with stdlib Logger. I probably won't be able to circle back on making a PR until second half of November.
No rush then. Let's leave this open as a placeholder to remind us. I'll see you in a couple of weeks 😄
Friendly bump here, any updates on if/when the debug lang might be merged upstream?
Perhaps we can incorporate this using https://pkg.go.dev/log/slog which landed with Go 1.21?