Skip to content

Commit

Permalink
Enable dynamic logging level setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuntao Lu committed Mar 8, 2018
1 parent a3272d1 commit 443457a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion runtime/gateway.go
Expand Up @@ -80,6 +80,7 @@ type Gateway struct {
TChannelRouter *TChannelRouter
Tracer opentracing.Tracer

atomLevel *zap.AtomicLevel
loggerFile *os.File
scopeCloser io.Closer
metricsBackend tally.CachedStatsReporter
Expand Down Expand Up @@ -231,6 +232,8 @@ func (gateway *Gateway) registerPredefined() {
gateway.HTTPRouter.RegisterRaw(
"GET", "/debug/pprof/block", pprof.Handler("block").ServeHTTP,
)
gateway.HTTPRouter.RegisterRaw("GET", "/debug/loglevel", gateway.atomLevel.ServeHTTP)
gateway.HTTPRouter.RegisterRaw("PUT", "/debug/loglevel", gateway.atomLevel.ServeHTTP)

gateway.HTTPRouter.Register("GET", "/health", NewRouterEndpoint(
gateway.Logger, gateway.AllHostScope,
Expand Down Expand Up @@ -420,17 +423,19 @@ func (gateway *Gateway) setupLogger(config *StaticConfig) error {
}
}

atomLevel := zap.NewAtomicLevelAt(logLevel)
prodCore := zapcore.NewCore(
logEncoder,
output,
logLevel,
atomLevel,
)
zapLogger := zap.New(
NewInstrumentedZapCore(
prodCore, gateway.AllHostScope,
),
)

gateway.atomLevel = &atomLevel
gateway.logEncoder = logEncoder
gateway.logWriteSyncer = output

Expand Down

0 comments on commit 443457a

Please sign in to comment.