1

I am using a third party library in one of my tools that uses the standard logging from golang. The library is https://github.com/jason0x43/go-toggl

Now I wrote a command line utility that instruments toggl and I do not want to have the logging written there. I found Go: Disable a log.Logger? but this deals with disabling within the own code. How can I disable logging in a library?

Community
  • 1
  • 1
Sascha
  • 10,231
  • 4
  • 41
  • 65

1 Answers1

3

That package defines it's own logger, doesn't export it, and provides no hooks to modify the output. You won't be able to change the log destination without modifying the package code.

Another option in this case is that since the logger writes to os.Stderr, you could redefine os.Stderr as your own io.Writer to intercept and filter the log output there. That may be as simple as buffering up all stderr output, and only printing it out in the case of an error.

JimB
  • 104,193
  • 13
  • 262
  • 255