Skip to content

Commit 02822f6

Browse files
committed
(MAINT) Allow consumer to bring their own logging.
1 parent 5dc5c6d commit 02822f6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/service/service.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/tls"
77
"errors"
88
"fmt"
9+
ginlogrus "github.com/toorop/gin-logrus"
910
"net/http"
1011
"os"
1112
"os/signal"
@@ -18,7 +19,6 @@ import (
1819
"github.com/prometheus/client_golang/prometheus/promhttp"
1920
"github.com/puppetlabs/go-libs/internal/log"
2021
"github.com/sirupsen/logrus"
21-
ginlogrus "github.com/toorop/gin-logrus"
2222
)
2323

2424
const (
@@ -31,6 +31,7 @@ const (
3131
// Config will hold the configuration of the service.
3232
type Config struct {
3333
ListenAddress string // Address in the format [host/ip]:port. Mandatory.
34+
DisableLog bool // Turn off service logging. Default is false.
3435
LogLevel string // INFO,FATAL,ERROR,WARN, DEBUG, TRACE.
3536
Cors *CorsConfig // Optional cors config.
3637
ReadinessCheck bool // Set to true to add a readiness handler at /readiness.
@@ -251,8 +252,11 @@ func NewService(cfg *Config) (*Service, error) {
251252

252253
gin.SetMode(gin.ReleaseMode)
253254
router := gin.New()
254-
logger := log.CreateLogger(cfg.LogLevel)
255-
router.Use(ginlogrus.Logger(logger, cfg.LogIgnorePaths...))
255+
256+
if !cfg.DisableLog {
257+
logger := log.CreateLogger(cfg.LogLevel)
258+
router.Use(ginlogrus.Logger(logger, cfg.LogIgnorePaths...))
259+
}
256260

257261
// Set CORS to the default if it's enabled and no override passed in.
258262
setupCors(router, cfg.Cors)

0 commit comments

Comments
 (0)