nictuku / dht

Kademlia/Mainline DHT node in Go.
Other
826 stars 144 forks source link

Disable some/all logging output #61

Closed cenkalti closed 6 years ago

cenkalti commented 6 years ago

I am using dht as a library in my application and I don't want it to print any log statements to the output. The output of dht library does not make sense to the user of my application.

There are messages showing as

ERROR: logging before flag.Parse: W1103 08:59:46.124232   26525 dht.go:566] DHT: readResponse Error: unexpected EOF, "d1:rd2:id20:d\xe9ᢇN>\r\x03-\xc8t\xcd\xfc\xca\x15L.\xe6D5:nodes4368:...

in the output of my program. There are 2 issues that causes this:

IMO, a good library must not print any output and should provide a way of returning internal events and errors. I propose removing glog from this library and take a logger implementation from outside that implements dht.Logger interface. I can provide a PR for this if you are OK with the idea.

If you don't want to remove glog, for just solving the output problem, we can replace direct calls to glog.Info and glog.Warning functions into glog.V(1).Info calls. In other words, do not log output at level 0. I can provide a PR for this too.

@nictuku what do you think?

nictuku commented 6 years ago

Hi Cenk,

Thank you for opening the issue and the feedback.

I agree with the overall goals that you propose. And I'd be happy to consider a PR to move towards a pluggable logging API that is not tightly coupled with glog.

A few concerns/ideas:

On Sat, Nov 3, 2018, 6:15 AM Cenk Altı <notifications@github.com wrote:

I am using dht as a library in my application and I don't want it to print any log statements to the output. The output of dht library does not make sense to the user of my application.

There are messages showing as

ERROR: logging before flag.Parse: W1103 08:59:46.124232 26525 dht.go:566] DHT: readResponse Error: unexpected EOF, "d1:rd2:id20:d\xe9ᢇN>\r\x03-\xc8t\xcd\xfc\xca\x15L.\xe6D5:nodes4368:...

in the output of my program. There are 2 issues that causes this:

  • glog requires flag.Parse() to be called before logging any output. My program does not call flag.Parse().
  • dht logs at level zero (V(0)).

IMO, a good library must not print any output and should provide a way of returning internal events and errors. I propose removing glog from this library and take a logger implementation from outside that implements dht.Logger interface. I can provide a PR for this if you are OK with the idea.

If you don't want to remove glog, for just solving the output problem, we can replace direct calls to glog.Info and glog.Warning functions into glog.V(1).Info calls. In other words, do not log output at level 0. I can provide a PR for this too.

@nictuku https://github.com/nictuku what do you think?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nictuku/dht/issues/61, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMY9qNGiDw4uA1Tany-8YTU0ZcFp-KTks5urZb4gaJpZM4YMy7U .