dgit icon indicating copy to clipboard operation
dgit copied to clipboard

git library is noisy

Open driusan opened this issue 6 years ago • 2 comments

The git subpackage uses Go's log package to print debugging information, which is suppressed by package main unless DGIT_TRACE is set.

I think this logic is backwards, because anyone who imports "github.com/driusan/dgit/git" to work with a git repo gets the noisy output by default and needs to manually suppress it. It also means that anyone using package log for their own purposes can't use the library.

We should probably be setting a logger in an init function in package git which discards by default, and adding a SetDebug(log.Logger) method (or perhaps something on the client object) to make the git subpackage more useful outside of the dgit command line without jumping through extra hoops.

driusan avatar Apr 05 '19 14:04 driusan

Hi @driusan I would love to work on this!

guidopola avatar Apr 05 '19 18:04 guidopola

Feel free.. I think the best way to do it is to add a logger to the Client struct which initializes from NewClient similarly to how func main() does when DGIT_TRACE isn't set so that it discards the output, then update all the log.X calls to c.log.X, and then invert the logic in main so that it sets the client's logger to stderr if DGIT_TRACE is set, instead of suppressing it if it's not, that way anyone else using the package is free to use the log package however they want without conflicting.

driusan avatar Apr 06 '19 01:04 driusan