Skip to content

Commit 54aeb67

Browse files
committed
feat: init logger with log file path and disableTime
1 parent a74660b commit 54aeb67

8 files changed

Lines changed: 216 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func Init(path string, options ...Option) (plugin IPlugin, err error)
3737
- path: built plugin file path
3838
- options: specify extra plugin options
3939
- WithDebugLogger(debug bool): whether to print debug level logs in plugin process
40+
- WithLogFile(logFile string): specify log file path
41+
- WithDisableTime(disable bool): whether disable log time
4042
- WithPython3(python3 string): specify custom python3 path
4143

4244
2, call plugin API to deal with plugin functions.

docs/go-grpc-plugin.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,8 @@ $ go build -o fungo/examples/xxx.bin fungo/examples/hashicorp.go fungo/examples/
7878

7979
Finally, you can use `Init` to initialize plugin via the `xxx.bin` path, and you can call the plugin API to handle plugin functionality.
8080

81+
The complete log example can be found in the file [hashicorp_grpc_go.log].
82+
8183

8284
[fungo/examples/]: ../fungo/examples/
85+
[hashicorp_grpc_go.log]: ../fungo/examples/logs/hashicorp_grpc_go.log

docs/go-rpc-plugin.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ Or in your golang code:
1616
os.Setenv("HRP_PLUGIN_TYPE", "rpc")
1717
```
1818

19+
The complete log example can be found in the file [hashicorp_rpc_go.log].
1920

2021
[golang plugin over gRPC]: go-grpc-plugin.md
2122
[examples/plugin/]: ../examples/plugin/
2223
[examples/plugin/debugtalk.go]: ../examples/plugin/debugtalk.go
24+
[hashicorp_rpc_go.log]: ../fungo/examples/logs/hashicorp_rpc_go.log
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[INFO] fungo: set plugin log level: level=debug
2+
[INFO] fungo: init plugin: path=fungo/examples/debugtalk.bin
3+
[INFO] hc-grpc-go: launch the plugin process
4+
[DEBUG] hc-grpc-go: starting plugin: path=fungo/examples/debugtalk.bin args=["fungo/examples/debugtalk.bin"]
5+
[DEBUG] hc-grpc-go: plugin started: path=fungo/examples/debugtalk.bin pid=63329
6+
[DEBUG] hc-grpc-go: waiting for RPC address: path=fungo/examples/debugtalk.bin
7+
[DEBUG] hc-grpc-go.debugtalk.bin: 2023/08/06 23:44:26 plugin init function called
8+
[INFO] hc-grpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_ints
9+
[INFO] hc-grpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_two_int
10+
[INFO] hc-grpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum
11+
[INFO] hc-grpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_two_string
12+
[INFO] hc-grpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_strings
13+
[INFO] hc-grpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=concatenate
14+
[INFO] hc-grpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=setup_hook_example
15+
[INFO] hc-grpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=teardown_hook_example
16+
[INFO] hc-grpc-go.debugtalk.bin: [INFO] fungo: start plugin server in gRPC mode
17+
[DEBUG] hc-grpc-go: using plugin: version=1
18+
[DEBUG] hc-grpc-go.debugtalk.bin: plugin address: address=/var/folders/nm/6prc3p4s2tg_27_3fwfv22vh0000gp/T/plugin3126265366 network=unix timestamp="2023-08-06T23:44:26.511+0800"
19+
[INFO] hc-grpc-go: load hashicorp go plugin success: path=fungo/examples/debugtalk.bin
20+
[DEBUG] hc-grpc-go: check if plugin has function: funcName=sum_ints
21+
[DEBUG] fungo: gRPC_client GetNames() start
22+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server GetNames() start
23+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: get registered plugin functions: names=["sum_ints", "sumstrings", "sum_strings", "setup_hook_example", "setuphookexample", "teardown_hook_example", "sumtwoint", "sumtwostring", "teardownhookexample", "sumints", "sum_two_int", "sum", "sum_two_string", "concatenate"]
24+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server GetNames() success
25+
[DEBUG] fungo: gRPC_client GetNames() success
26+
[DEBUG] hc-grpc-go: check if plugin has function: funcName=concatenate
27+
[DEBUG] fungo: gRPC_client GetNames() start
28+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server GetNames() start
29+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: get registered plugin functions: names=["sumtwoint", "sumtwostring", "teardownhookexample", "sumints", "sum_two_int", "sum", "sum_two_string", "concatenate", "sum_ints", "sumstrings", "sum_strings", "setup_hook_example", "setuphookexample", "teardown_hook_example"]
30+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server GetNames() success
31+
[DEBUG] fungo: gRPC_client GetNames() success
32+
[INFO] fungo: gRPC_client Call() start: funcName=sum_ints funcArgs=[1, 2, 3, 4]
33+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() start
34+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum_ints args=[1, 2, 3, 4]
35+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() success
36+
[INFO] fungo: gRPC_client Call() success: result=10
37+
[INFO] fungo: gRPC_client Call() start: funcName=sum_two_int funcArgs=[1, 2]
38+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() start
39+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum_two_int args=[1, 2]
40+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() success
41+
[INFO] fungo: gRPC_client Call() success: result=3
42+
[INFO] fungo: gRPC_client Call() start: funcName=sum funcArgs=[1, 2, 3.4, 5]
43+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() start
44+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum args=[1, 2, 3.4, 5]
45+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() success
46+
[INFO] fungo: gRPC_client Call() success: result=11.4
47+
[INFO] fungo: gRPC_client Call() start: funcName=sum_two_string funcArgs=[a, b]
48+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() start
49+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum_two_string args=[a, b]
50+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() success
51+
[INFO] fungo: gRPC_client Call() success: result=ab
52+
[INFO] fungo: gRPC_client Call() start: funcName=sum_strings funcArgs=[a, b, c]
53+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() start
54+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum_strings args=[a, b, c]
55+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() success
56+
[INFO] fungo: gRPC_client Call() success: result=abc
57+
[INFO] fungo: gRPC_client Call() start: funcName=concatenate funcArgs=[a, 2, c, 3.4]
58+
[INFO] fungo: gRPC_client Call() success: result=a2c3.4
59+
[INFO] hc-grpc-go: quit hashicorp plugin process
60+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() start
61+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=concatenate args=[a, 2, c, 3.4]
62+
[DEBUG] hc-grpc-go.debugtalk.bin: [DEBUG] fungo: gRPC_server Call() success
63+
[DEBUG] hc-grpc-go.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
64+
[INFO] hc-grpc-go: plugin process exited: path=fungo/examples/debugtalk.bin pid=63329
65+
[DEBUG] hc-grpc-go: plugin exited
66+
[INFO] hc-grpc-go: [teardown test] remove hashicorp plugin: path=fungo/examples/debugtalk.bin
67+
O] fungo: gRPC_client Call() success: result=abc
68+
[INFO] fungo: gRPC_client Call() start: funcName=concatenate funcArgs=[a, 2, c, 3.4]
69+
[DEBUG] hc-grpc-go.debugtalk.bin: 2023-08-06T23:42:36.210+0800 [DEBUG] fungo: gRPC_server Call() start
70+
[DEBUG] hc-grpc-go.debugtalk.bin: 2023-08-06T23:42:36.210+0800 [DEBUG] fungo.func_exec: plugin function execution: funcName=concatenate args=[a, 2, c, 3.4]
71+
[DEBUG] hc-grpc-go.debugtalk.bin: 2023-08-06T23:42:36.210+0800 [DEBUG] fungo: gRPC_server Call() success
72+
[INFO] fungo: gRPC_client Call() success: result=a2c3.4
73+
[INFO] hc-grpc-go: quit hashicorp plugin process
74+
[DEBUG] hc-grpc-go.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
75+
[INFO] hc-grpc-go: plugin process exited: path=fungo/examples/debugtalk.bin pid=62304
76+
[DEBUG] hc-grpc-go: plugin exited
77+
[INFO] hc-grpc-go: [teardown test] remove hashicorp plugin: path=fungo/examples/debugtalk.bin
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
[INFO] fungo: set plugin log level: level=debug
2+
[INFO] fungo: init plugin: path=fungo/examples/debugtalk.bin
3+
[INFO] hc-rpc-go: launch the plugin process
4+
[DEBUG] hc-rpc-go: starting plugin: path=fungo/examples/debugtalk.bin args=["fungo/examples/debugtalk.bin"]
5+
[DEBUG] hc-rpc-go: plugin started: path=fungo/examples/debugtalk.bin pid=62848
6+
[DEBUG] hc-rpc-go: waiting for RPC address: path=fungo/examples/debugtalk.bin
7+
[DEBUG] hc-rpc-go.debugtalk.bin: 2023/08/06 23:43:45 plugin init function called
8+
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_ints
9+
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_two_int
10+
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum
11+
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_two_string
12+
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_strings
13+
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=concatenate
14+
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=setup_hook_example
15+
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=teardown_hook_example
16+
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: start plugin server in RPC mode
17+
[DEBUG] hc-rpc-go: using plugin: version=1
18+
[DEBUG] hc-rpc-go.debugtalk.bin: plugin address: address=/var/folders/nm/6prc3p4s2tg_27_3fwfv22vh0000gp/T/plugin1072589984 network=unix timestamp="2023-08-06T23:43:45.785+0800"
19+
[INFO] hc-rpc-go: load hashicorp go plugin success: path=fungo/examples/debugtalk.bin
20+
[DEBUG] hc-rpc-go: check if plugin has function: funcName=sum_ints
21+
[DEBUG] fungo: rpc_client GetNames() start
22+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server GetNames() start
23+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: get registered plugin functions: names=["sum_ints", "sumtwoint", "sum_two_string", "sumtwostring", "teardown_hook_example", "sum_strings", "setuphookexample", "sum_two_int", "sumstrings", "concatenate", "setup_hook_example", "sumints", "sum", "teardownhookexample"]
24+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server GetNames() success
25+
[DEBUG] fungo: rpc_client GetNames() success
26+
[DEBUG] hc-rpc-go: check if plugin has function: funcName=concatenate
27+
[DEBUG] fungo: rpc_client GetNames() start
28+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server GetNames() start
29+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: get registered plugin functions: names=["sumints", "sum", "teardownhookexample", "sum_ints", "sumtwoint", "sum_two_string", "sumtwostring", "teardown_hook_example", "sum_strings", "setuphookexample", "sum_two_int", "sumstrings", "concatenate", "setup_hook_example"]
30+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server GetNames() success
31+
[DEBUG] fungo: rpc_client GetNames() success
32+
[INFO] fungo: rpc_client Call() start: funcName=sum_ints funcArgs=[1, 2, 3, 4]
33+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() start
34+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum_ints args=[1, 2, 3, 4]
35+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() success
36+
[INFO] fungo: rpc_client Call() success: result=10
37+
[INFO] fungo: rpc_client Call() start: funcName=sum_two_int funcArgs=[1, 2]
38+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() start
39+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum_two_int args=[1, 2]
40+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() success
41+
[INFO] fungo: rpc_client Call() success: result=3
42+
[INFO] fungo: rpc_client Call() start: funcName=sum funcArgs=[1, 2, 3.4, 5]
43+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() start
44+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum args=[1, 2, 3.4, 5]
45+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() success
46+
[INFO] fungo: rpc_client Call() success: result=11.4
47+
[INFO] fungo: rpc_client Call() start: funcName=sum_two_string funcArgs=[a, b]
48+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() start
49+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum_two_string args=[a, b]
50+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() success
51+
[INFO] fungo: rpc_client Call() success: result=ab
52+
[INFO] fungo: rpc_client Call() start: funcName=sum_strings funcArgs=[a, b, c]
53+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() start
54+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=sum_strings args=[a, b, c]
55+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() success
56+
[INFO] fungo: rpc_client Call() success: result=abc
57+
[INFO] fungo: rpc_client Call() start: funcName=concatenate funcArgs=[a, 2, c, 3.4]
58+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() start
59+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: plugin function execution: funcName=concatenate args=[a, 2, c, 3.4]
60+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() success
61+
[INFO] fungo: rpc_client Call() success: result=a2c3.4
62+
[INFO] hc-rpc-go: quit hashicorp plugin process
63+
[DEBUG] hc-rpc-go.debugtalk.bin: 2023/08/06 23:43:45 [DEBUG] plugin: plugin server: accept unix /var/folders/nm/6prc3p4s2tg_27_3fwfv22vh0000gp/T/plugin1072589984: use of closed network connection
64+
[INFO] hc-rpc-go: plugin process exited: path=fungo/examples/debugtalk.bin pid=62848
65+
[DEBUG] hc-rpc-go: plugin exited
66+
[INFO] hc-rpc-go: [teardown test] remove hashicorp plugin: path=fungo/examples/debugtalk.bin
67+
INFO] fungo: rpc_client Call() start: funcName=concatenate funcArgs=[a, 2, c, 3.4]
68+
[DEBUG] hc-rpc-go.debugtalk.bin: 2023-08-06T23:43:12.990+0800 [DEBUG] fungo: rpc_server Call() start
69+
[DEBUG] hc-rpc-go.debugtalk.bin: 2023-08-06T23:43:12.990+0800 [DEBUG] fungo.func_exec: plugin function execution: funcName=concatenate args=[a, 2, c, 3.4]
70+
[DEBUG] hc-rpc-go.debugtalk.bin: 2023-08-06T23:43:12.990+0800 [DEBUG] fungo: rpc_server Call() success
71+
[INFO] fungo: rpc_client Call() success: result=a2c3.4
72+
[INFO] hc-rpc-go: quit hashicorp plugin process
73+
[DEBUG] hc-rpc-go.debugtalk.bin: 2023/08/06 23:43:12 [DEBUG] plugin: plugin server: accept unix /var/folders/nm/6prc3p4s2tg_27_3fwfv22vh0000gp/T/plugin2693576263: use of closed network connection
74+
[INFO] hc-rpc-go: plugin process exited: path=fungo/examples/debugtalk.bin pid=62553
75+
[DEBUG] hc-rpc-go: plugin exited
76+
[INFO] hc-rpc-go: [teardown test] remove hashicorp plugin: path=fungo/examples/debugtalk.bin

fungo/init.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package fungo
22

33
import (
4+
"io"
5+
"os"
6+
47
hclog "github.com/hashicorp/go-hclog"
58
"github.com/hashicorp/go-plugin"
69
)
@@ -14,11 +17,33 @@ var (
1417
var Logger = hclog.New(&hclog.LoggerOptions{
1518
Name: "fungo",
1619
Output: hclog.DefaultOutput,
17-
DisableTime: false,
20+
DisableTime: true,
1821
Level: hclog.Debug,
1922
Color: hclog.AutoColor,
2023
})
2124

25+
func InitLogger(logLevel hclog.Level, logFile string, disableTime bool) hclog.Logger {
26+
output := hclog.DefaultOutput
27+
if logFile != "" {
28+
file, err := os.OpenFile(logFile, os.O_CREATE|os.O_RDWR, 0666)
29+
if err != nil {
30+
logger.Error("open log file failed", "error", err)
31+
os.Exit(1)
32+
}
33+
output = io.MultiWriter(hclog.DefaultOutput, file)
34+
}
35+
36+
logger = hclog.New(&hclog.LoggerOptions{
37+
Name: "fungo",
38+
Output: output,
39+
DisableTime: disableTime,
40+
Level: logLevel,
41+
Color: hclog.AutoColor,
42+
})
43+
logger.Info("set plugin log level", "level", logLevel.String())
44+
return logger
45+
}
46+
2247
// PluginTypeEnvName is used to specify hashicorp go plugin type, rpc/grpc
2348
const PluginTypeEnvName = "HRP_PLUGIN_TYPE"
2449

hashicorp_plugin_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ func TestHashicorpGRPCGoPlugin(t *testing.T) {
3434
defer removeHashicorpGoPlugin()
3535

3636
plugin, err := Init("fungo/examples/debugtalk.bin",
37-
WithDebugLogger(true))
37+
WithDebugLogger(true),
38+
WithLogFile("fungo/examples/logs/hashicorp_grpc_go.log"),
39+
WithDisableTime(true))
3840
if err != nil {
3941
t.Fatal(err)
4042
}
@@ -49,7 +51,9 @@ func TestHashicorpRPCGoPlugin(t *testing.T) {
4951

5052
os.Setenv(fungo.PluginTypeEnvName, "rpc")
5153
plugin, err := Init("fungo/examples/debugtalk.bin",
52-
WithDebugLogger(true))
54+
WithDebugLogger(true),
55+
WithLogFile("fungo/examples/logs/hashicorp_rpc_go.log"),
56+
WithDisableTime(true))
5357
if err != nil {
5458
t.Fatal(err)
5559
}

init.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ const (
3030
)
3131

3232
type pluginOption struct {
33-
debugLogger bool
34-
langType langType // go or py
35-
python3 string // python3 path with funppy dependency
33+
debugLogger bool // whether set log level to DEBUG
34+
logFile string // specify log file path
35+
disableLogTime bool // whether disable log time
36+
langType langType // go or py
37+
python3 string // python3 path with funppy dependency
3638
}
3739

3840
type Option func(*pluginOption)
@@ -43,6 +45,18 @@ func WithDebugLogger(debug bool) Option {
4345
}
4446
}
4547

48+
func WithLogFile(logFile string) Option {
49+
return func(o *pluginOption) {
50+
o.logFile = logFile
51+
}
52+
}
53+
54+
func WithDisableTime(disable bool) Option {
55+
return func(o *pluginOption) {
56+
o.disableLogTime = disable
57+
}
58+
}
59+
4660
func WithPython3(python3 string) Option {
4761
return func(o *pluginOption) {
4862
o.python3 = python3
@@ -56,15 +70,15 @@ func Init(path string, options ...Option) (plugin IPlugin, err error) {
5670
o(option)
5771
}
5872

59-
// logger
60-
logger.Info("init plugin", "path", path)
73+
// init logger
74+
logLevel := hclog.Info
6175
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)
76+
logLevel = hclog.Debug
6777
}
78+
logger = fungo.InitLogger(
79+
logLevel, option.logFile, option.disableLogTime)
80+
81+
logger.Info("init plugin", "path", path)
6882

6983
// priority: hashicorp plugin > go plugin
7084
ext := filepath.Ext(path)

0 commit comments

Comments
 (0)