File: logwrapper.go

package info (click to toggle)
golang-github-go-kit-kit 0.6.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, experimental, sid
  • size: 4,848 kB
  • sloc: sh: 65; makefile: 14
file content (27 lines) | stat: -rw-r--r-- 636 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package zk

import (
	"fmt"

	"github.com/samuel/go-zookeeper/zk"

	"github.com/go-kit/kit/log"
)

// wrapLogger wraps a Go kit logger so we can use it as the logging service for
// the ZooKeeper library, which expects a Printf method to be available.
type wrapLogger struct {
	log.Logger
}

func (logger wrapLogger) Printf(format string, args ...interface{}) {
	logger.Log("msg", fmt.Sprintf(format, args...))
}

// withLogger replaces the ZooKeeper library's default logging service with our
// own Go kit logger.
func withLogger(logger log.Logger) func(c *zk.Conn) {
	return func(c *zk.Conn) {
		c.SetLogger(wrapLogger{logger})
	}
}