JSONLogger: fix incorrect caller when using Log function

Issue #48 resolved
Saxon Milton created an issue

There’s an occasional pattern where we have a function that takes a logging function e.g.

type Log func(level int8, msg string, args ...interface{})

// Dial connects to RTMP server specified by the given URL and returns the connection.
func Dial(url string, log Log, options ...func(*Conn) error) (*Conn, error) {
  ...
}

Instead of a logging.Logger interface,

func newRtmpSender(url string, retries int, rb *pool.Buffer, log logging.Logger, report func(sent int)) (*rtmpSender, error) {

In the prior cases, we pass the JSONLogger.Log method, but the problem is that the caller skip is tuned to the caller level corresponding to use of the wrappers (like JSONLogger.Debug(), JSONLogger.Info() etc) that call Log, not when Log is called directly. Therefore, the caller path in the resultant log is incorrect when this pattern is used. What we should do to fix this is create an internal JSONLogger.log method which both the logging wrappers e.g. JSONLogger.Debug(), JSONLogger.Info() and JSONLogger.Log wrap.

Comments (2)

  1. Log in to comment