Skip to content

Commit 3f0e973

Browse files
committed
change: update logger name
1 parent 85924c9 commit 3f0e973

7 files changed

Lines changed: 39 additions & 19 deletions

File tree

fungo/init.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ var (
1212
)
1313

1414
var Logger = hclog.New(&hclog.LoggerOptions{
15-
Name: "fungo",
16-
Output: hclog.DefaultOutput,
17-
Level: hclog.Debug,
18-
Color: hclog.AutoColor,
15+
Name: "fungo",
16+
Output: hclog.DefaultOutput,
17+
DisableTime: false,
18+
Level: hclog.Debug,
19+
Color: hclog.AutoColor,
1920
})
2021

2122
// PluginTypeEnvName is used to specify hashicorp go plugin type, rpc/grpc

fungo/plugin.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ func Register(funcName string, fn interface{}) {
5757
func serveRPC() {
5858
rpcPluginName := "rpc"
5959
logger.Info("start plugin server in RPC mode")
60-
logger = logger.Named(rpcPluginName)
6160
funcPlugin := &functionPlugin{
62-
logger: logger,
61+
logger: logger.Named("func_exec"),
6362
functions: functions,
6463
}
6564
var pluginMap = map[string]plugin.Plugin{
@@ -76,9 +75,8 @@ func serveRPC() {
7675
func serveGRPC() {
7776
grpcPluginName := "grpc"
7877
logger.Info("start plugin server in gRPC mode")
79-
logger = logger.Named(grpcPluginName)
8078
funcPlugin := &functionPlugin{
81-
logger: logger,
79+
logger: logger.Named("func_exec"),
8280
functions: functions,
8381
}
8482
var pluginMap = map[string]plugin.Plugin{

go_plugin.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ func newGoPlugin(path string) (*goPlugin, error) {
2222
return nil, fmt.Errorf("go plugin does not support windows")
2323
}
2424

25+
// logger
26+
logger = logger.ResetNamed("go-plugin")
27+
2528
plg, err := plugin.Open(path)
2629
if err != nil {
2730
logger.Error("load go plugin failed", "path", path, "error", err)

go_plugin_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestCallPluginFunction(t *testing.T) {
3333
buildGoPlugin()
3434
defer removeGoPlugin()
3535

36-
plugin, err := Init("debugtalk.so")
36+
plugin, err := Init("debugtalk.so", WithDebugLogger(true))
3737
if err != nil {
3838
t.Fatal(err)
3939
}

hashicorp_plugin.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os/exec"
77
"sync"
88

9-
"github.com/hashicorp/go-hclog"
109
"github.com/hashicorp/go-plugin"
1110
"github.com/pkg/errors"
1211

@@ -47,14 +46,7 @@ func newHashicorpPlugin(path string, option *pluginOption) (*hashicorpPlugin, er
4746
}
4847

4948
// logger
50-
logger = logger.Named(fmt.Sprintf("%v-%v", p.rpcType, p.option.langType))
51-
if p.option.debugLogger {
52-
logger.Info("set plugin log level to DEBUG")
53-
logger.SetLevel(hclog.Debug)
54-
} else {
55-
logger.Info("set plugin log level to INFO")
56-
logger.SetLevel(hclog.Info)
57-
}
49+
logger = logger.ResetNamed(fmt.Sprintf("hc-%v-%v", p.rpcType, p.option.langType))
5850

5951
// cmd
6052
var cmd *exec.Cmd

hashicorp_plugin_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"runtime"
99
"testing"
1010

11+
"github.com/httprunner/funplugin/fungo"
1112
"github.com/stretchr/testify/assert"
1213
)
1314

@@ -28,7 +29,7 @@ func removeHashicorpGoPlugin() {
2829
os.Remove(pluginBinPath)
2930
}
3031

31-
func TestHashicorpGoPlugin(t *testing.T) {
32+
func TestHashicorpGRPCGoPlugin(t *testing.T) {
3233
buildHashicorpGoPlugin()
3334
defer removeHashicorpGoPlugin()
3435

@@ -42,6 +43,21 @@ func TestHashicorpGoPlugin(t *testing.T) {
4243
assertPlugin(t, plugin)
4344
}
4445

46+
func TestHashicorpRPCGoPlugin(t *testing.T) {
47+
buildHashicorpGoPlugin()
48+
defer removeHashicorpGoPlugin()
49+
50+
os.Setenv(fungo.PluginTypeEnvName, "rpc")
51+
plugin, err := Init("fungo/examples/debugtalk.bin",
52+
WithDebugLogger(true))
53+
if err != nil {
54+
t.Fatal(err)
55+
}
56+
defer plugin.Quit()
57+
58+
assertPlugin(t, plugin)
59+
}
60+
4561
func TestHashicorpPythonPluginWithoutVenv(t *testing.T) {
4662
_, err := Init("funppy/examples/debugtalk.py")
4763
assert.EqualError(t, err, "python3 not specified")

init.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"path/filepath"
77

8+
"github.com/hashicorp/go-hclog"
89
"github.com/httprunner/funplugin/fungo"
910
)
1011

@@ -54,7 +55,16 @@ func Init(path string, options ...Option) (plugin IPlugin, err error) {
5455
for _, o := range options {
5556
o(option)
5657
}
58+
59+
// logger
5760
logger.Info("init plugin", "path", path)
61+
if option.debugLogger {
62+
logger.Info("set plugin log level to DEBUG")
63+
logger.SetLevel(hclog.Debug)
64+
} else {
65+
logger.Info("set plugin log level to INFO")
66+
logger.SetLevel(hclog.Info)
67+
}
5868

5969
// priority: hashicorp plugin > go plugin
6070
ext := filepath.Ext(path)

0 commit comments

Comments
 (0)