You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by so...@apache.org on 2022/12/08 06:32:10 UTC

[apisix-go-plugin-runner] branch master updated: feat: try to reuse the exists logger to adapter some zap hooks (#117)

This is an automated email from the ASF dual-hosted git repository.

soulbird pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-go-plugin-runner.git


The following commit(s) were added to refs/heads/master by this push:
     new 3ca6af7  feat: try to reuse the exists logger to adapter some zap hooks (#117)
3ca6af7 is described below

commit 3ca6af7c5db165b21497fcf02ff4bd5174ede82c
Author: 刘奕聪 <im...@gmail.com>
AuthorDate: Thu Dec 8 14:32:05 2022 +0800

    feat: try to reuse the exists logger to adapter some zap hooks (#117)
    
    * feat: make GetLogger public
    
    * feat: try to reuse the exists logger to adapter some zap hooks
    
    Co-authored-by: yakovliu <ya...@tencent.com>
---
 pkg/log/log.go       |  4 ++++
 pkg/runner/runner.go | 11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/pkg/log/log.go b/pkg/log/log.go
index 9883fa4..303172d 100644
--- a/pkg/log/log.go
+++ b/pkg/log/log.go
@@ -31,6 +31,10 @@ var (
 	loggerInit sync.Once
 )
 
+func SetLogger(l *zap.SugaredLogger) {
+	logger = l
+}
+
 func NewLogger(level zapcore.Level, out zapcore.WriteSyncer) {
 	var atomicLevel = zap.NewAtomicLevel()
 	atomicLevel.SetLevel(level)
diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go
index 9a8585f..2f5926d 100644
--- a/pkg/runner/runner.go
+++ b/pkg/runner/runner.go
@@ -20,6 +20,7 @@ package runner
 import (
 	"os"
 
+	"go.uber.org/zap"
 	"go.uber.org/zap/zapcore"
 
 	"github.com/apache/apisix-go-plugin-runner/internal/server"
@@ -32,6 +33,8 @@ type RunnerConfig struct {
 	LogLevel zapcore.Level
 	// LogOutput is the output of log, default to `os.Stdout`
 	LogOutput zapcore.WriteSyncer
+	// Logger will be reused by the framework when it is not nil.
+	Logger *zap.SugaredLogger
 }
 
 // Run starts the runner and listen the socket configured by environment variable "APISIX_LISTEN_ADDRESS"
@@ -39,6 +42,12 @@ func Run(cfg RunnerConfig) {
 	if cfg.LogOutput == nil {
 		cfg.LogOutput = os.Stdout
 	}
-	log.NewLogger(cfg.LogLevel, cfg.LogOutput)
+
+	if cfg.Logger == nil {
+		log.NewLogger(cfg.LogLevel, cfg.LogOutput)
+	} else {
+		log.SetLogger(cfg.Logger)
+	}
+
 	server.Run()
 }