bazel-gazelle icon indicating copy to clipboard operation
bazel-gazelle copied to clipboard

Add link to bazel-gazelle-debug extension.

Open pcj opened this issue 3 years ago • 9 comments

Add link to bazel-gazelle-debug extension.

pcj avatar Oct 25 '21 18:10 pcj

@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?

achew22 avatar Oct 25 '21 21:10 achew22

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?

pcj avatar Oct 26 '21 05:10 pcj

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?

achew22 avatar Oct 26 '21 09:10 achew22

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.

pcj avatar Oct 26 '21 18:10 pcj

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?

achew22 avatar Oct 28 '21 20:10 achew22

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.

pcj avatar Oct 29 '21 15:10 pcj

No rush then. Let's leave this open as a placeholder to remind us. I'll see you in a couple of weeks 😄

achew22 avatar Oct 29 '21 16:10 achew22

Friendly bump here, any updates on if/when the debug lang might be merged upstream?

Whoaa512 avatar Apr 28 '22 02:04 Whoaa512

Perhaps we can incorporate this using https://pkg.go.dev/log/slog which landed with Go 1.21?

gaurav-narula avatar Mar 06 '24 12:03 gaurav-narula