From 3d01e6a350df8078baf1ad4c5a1dcdf3ca0738bc Mon Sep 17 00:00:00 2001 From: Maxim Vladimirskiy Date: Thu, 6 Sep 2018 10:02:20 +0300 Subject: [PATCH] Allow using any logger --- options.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/options.go b/options.go index d534964..06bde3e 100644 --- a/options.go +++ b/options.go @@ -25,7 +25,6 @@ SOFTWARE. */ import ( - "log" "time" ) @@ -43,6 +42,12 @@ const ( DefaultSendLoopCount = 1 ) +// SomeLogger defines logging interface that allows using 3rd party loggers +// (e.g. github.com/sirupsen/logrus) with this Statsd client. +type SomeLogger interface { + Printf(fmt string, args ...interface{}) +} + // ClientOptions are statsd client settings type ClientOptions struct { // Addr is statsd server address in "host:port" format @@ -90,7 +95,7 @@ type ClientOptions struct { // Logger is used by statsd client to report errors and lost packets // // If not set, default logger to stderr with prefix `[STATSD] ` is being used - Logger *log.Logger + Logger SomeLogger // BufPoolCapacity controls size of pre-allocated buffer cache // @@ -200,7 +205,7 @@ func ReportInterval(interval time.Duration) Option { // Logger is used by statsd client to report errors and lost packets // // If not set, default logger to stderr with prefix `[STATSD] ` is being used -func Logger(logger *log.Logger) Option { +func Logger(logger SomeLogger) Option { return func(c *ClientOptions) { c.Logger = logger }