Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4985

Clean up logging in go library



    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 0.14.0
    • Go - Library
    • None


      As principals:

      1. As a library, the library itself shouldn't do any logging. It should always return the error to the caller (library user), and let them to decide how to handle them (logging, panic, etc.)
      2. In some cases it's not possible to return the error to the caller, so some logging is necessary, but those should be kept minimal, and made more controllable to the caller.

      Looking at how we do logging in go library now:

      1. We have logging inside TZlibTransport, which fits Principal 1 above and should be removed
      2. We have logging inside TSimpleServer, which fits Principal 2 above (those are in the accept loop so there's no easy way to return the errors to the caller)

      For Principal 2, one of the problem is that we can't just force all the callers to use the same logging library. There are a lot of logging libraries and it's not always possible to convert them into each other. Some people might be using go-kit logger because they want structured logging, or because they are already using go-kit for other things, and some people might be using zap for its performance. They are both incompatible to the stdlib log library.

      This, combined with the part that we should keep the logging minimal, is why I propose a simple, common ground that's easy to wrap any logging library into:

      type Logger func(msg string)

      Whatever logging library the user is already using, it's easy to write a lambda to convert that to this common ground, for example for the stdlib log library:

      func StdLogger(logger *log.Logger) Logger {
        return func(msg string) {

      You can even have one to be used in tests, because the purpose of logging is that it's only used for situations that is bad, we can make it that whenever the logging is called we should fail the test:

      func TestLogger(tb testing.TB) Logger {
        return func(msg string) {
          tb.Errorf("logger called with msg: %q", msg)

      This way, the caller can make sure that the logging from inside the thrift library is using the same logger as what they are already using, or they can suppress the logging entirely if they choose to.


        Issue Links



              Unassigned Unassigned
              fishywang Yuxuan Wang
              0 Vote for this issue
              2 Start watching this issue



                Time Tracking

                  Original Estimate - Not Specified
                  Not Specified
                  Remaining Estimate - 0h
                  Time Spent - 20m