2018-05-01 23:45:06 +00:00
|
|
|
package tunnelrpc
|
|
|
|
|
|
|
|
import (
|
2019-01-10 20:55:44 +00:00
|
|
|
"context"
|
|
|
|
|
2020-11-25 06:55:13 +00:00
|
|
|
"github.com/rs/zerolog"
|
2018-05-01 23:45:06 +00:00
|
|
|
"golang.org/x/net/trace"
|
|
|
|
"zombiezen.com/go/capnproto2/rpc"
|
|
|
|
)
|
|
|
|
|
2020-11-25 06:55:13 +00:00
|
|
|
// ConnLogger wraps a Zerolog Logger for a connection.
|
2018-05-01 23:45:06 +00:00
|
|
|
type ConnLogger struct {
|
2020-11-25 06:55:13 +00:00
|
|
|
Log *zerolog.Logger
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c ConnLogger) Infof(ctx context.Context, format string, args ...interface{}) {
|
2020-11-25 06:55:13 +00:00
|
|
|
c.Log.Info().Msgf(format, args...)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c ConnLogger) Errorf(ctx context.Context, format string, args ...interface{}) {
|
2020-11-25 06:55:13 +00:00
|
|
|
c.Log.Error().Msgf(format, args...)
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-25 06:55:13 +00:00
|
|
|
func ConnLog(log *zerolog.Logger) rpc.ConnOption {
|
2018-05-01 23:45:06 +00:00
|
|
|
return rpc.ConnLog(ConnLogger{log})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnTracer wraps a trace.EventLog for a connection.
|
|
|
|
type ConnTracer struct {
|
|
|
|
Events trace.EventLog
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c ConnTracer) Infof(ctx context.Context, format string, args ...interface{}) {
|
|
|
|
c.Events.Printf(format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c ConnTracer) Errorf(ctx context.Context, format string, args ...interface{}) {
|
|
|
|
c.Events.Errorf(format, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ConnTrace(events trace.EventLog) rpc.ConnOption {
|
|
|
|
return rpc.ConnLog(ConnTracer{events})
|
|
|
|
}
|