driusan / dgit

A Pure Go Git Implementation
MIT License
112 stars 10 forks source link

git library is noisy #245

Open driusan opened 5 years ago

driusan commented 5 years ago

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.

guidopola commented 5 years ago

Hi @driusan I would love to work on this!

driusan commented 5 years ago

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.