Skip to content

Commit 8bb281c

Browse files
committed
增加插件代理
1 parent 5a87442 commit 8bb281c

File tree

3 files changed

+100
-5
lines changed

3 files changed

+100
-5
lines changed

log.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func Error(args ...interface{}) {
6868
// Debugf logs a message at level Debug on the standard _logger.
6969
func Debugf(format string, args ...interface{}) {
7070
if _logger == nil{
71-
printLevelF(format,"[DEBUG]",args...)
71+
printLevelF(format,"[DEBUG] ",args...)
7272
return
7373
}
7474
_logger.Debugf(format, args...)
@@ -77,7 +77,7 @@ func Debugf(format string, args ...interface{}) {
7777
// Infof logs a message at level Info on the standard _logger.
7878
func Infof(format string, args ...interface{}) {
7979
if _logger == nil{
80-
printLevelF(format,"[INFO]",args...)
80+
printLevelF(format,"[INFO] ",args...)
8181
return
8282
}
8383
_logger.Infof(format, args...)
@@ -86,7 +86,7 @@ func Infof(format string, args ...interface{}) {
8686
// Warnf logs a message at level Warn on the standard _logger.
8787
func Warnf(format string, args ...interface{}) {
8888
if _logger == nil{
89-
printLevelF(format,"[WARN]",args...)
89+
printLevelF(format,"[WARN] ",args...)
9090
return
9191
}
9292
_logger.Warnf(format, args...)
@@ -95,7 +95,7 @@ func Warnf(format string, args ...interface{}) {
9595
// Warningf logs a message at level Warn on the standard _logger.
9696
func Warningf(format string, args ...interface{}) {
9797
if _logger == nil{
98-
printLevelF(format,"[WARNING]",args...)
98+
printLevelF(format,"[WARNING] ",args...)
9999
return
100100
}
101101
_logger.Warningf(format, args...)
@@ -104,7 +104,7 @@ func Warningf(format string, args ...interface{}) {
104104
// Errorf logs a message at level Error on the standard _logger.
105105
func Errorf(format string, args ...interface{}) {
106106
if _logger == nil{
107-
printLevelF(format,"[ERROR]",args...)
107+
printLevelF(format,"[ERROR] ",args...)
108108
return
109109
}
110110
_logger.Errorf(format, args...)
@@ -117,5 +117,8 @@ func printLevel(level string,args ...interface{}){
117117
fmt.Println(vs...)
118118
}
119119
func printLevelF(format,level string,args ...interface{}){
120+
if format[len(format)-1] !='\n'{
121+
format = format+"\n"
122+
}
120123
fmt.Printf(level+format,args...)
121124
}

plugin-log.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package goku_plugin
2+
3+
import "fmt"
4+
5+
type PluginLogProxy struct {
6+
pluginName string
7+
}
8+
9+
func GenLogger(pluginName string)Logger {
10+
return &PluginLogProxy{
11+
pluginName:fmt.Sprintf("[plugin:%s]",pluginName),
12+
}
13+
}
14+
15+
func (l *PluginLogProxy) Debugf(format string, args ...interface{}) {
16+
format = fmt.Sprintf("%s %s",l.pluginName,format)
17+
Debugf(format,args...)
18+
}
19+
20+
func (l *PluginLogProxy) Infof(format string, args ...interface{}) {
21+
format = fmt.Sprintf("%s %s",l.pluginName,format)
22+
Infof(format,args...)
23+
}
24+
25+
func (l *PluginLogProxy) Warnf(format string, args ...interface{}) {
26+
format = fmt.Sprintf("%s %s",l.pluginName,format)
27+
Warnf(format,args...)
28+
}
29+
30+
func (l *PluginLogProxy) Warningf(format string, args ...interface{}) {
31+
format = fmt.Sprintf("%s %s",l.pluginName,format)
32+
Warningf(format,args...)
33+
}
34+
35+
func (l *PluginLogProxy) Errorf(format string, args ...interface{}) {
36+
format = fmt.Sprintf("%s %s",l.pluginName,format)
37+
Errorf(format,args...)
38+
}
39+
40+
func (l *PluginLogProxy) Debug(args ...interface{}) {
41+
vs:=make([]interface{},0,len(args)+1)
42+
vs = append(vs,l.pluginName)
43+
vs = append(vs,args...)
44+
Debug(vs...)
45+
}
46+
47+
func (l *PluginLogProxy) Info(args ...interface{}) {
48+
vs:=make([]interface{},0,len(args)+1)
49+
vs = append(vs,l.pluginName)
50+
vs = append(vs,args...)
51+
Info(vs...)
52+
}
53+
54+
func (l *PluginLogProxy) Warn(args ...interface{}) {
55+
vs:=make([]interface{},0,len(args)+1)
56+
vs = append(vs,l.pluginName)
57+
vs = append(vs,args...)
58+
Warn(vs...)
59+
}
60+
61+
func (l *PluginLogProxy) Warning(args ...interface{}) {
62+
vs:=make([]interface{},0,len(args)+1)
63+
vs = append(vs,l.pluginName)
64+
vs = append(vs,args...)
65+
Warning(vs...)
66+
}
67+
68+
func (l *PluginLogProxy) Error(args ...interface{}) {
69+
vs:=make([]interface{},0,len(args)+1)
70+
vs = append(vs,l.pluginName)
71+
vs = append(vs,args...)
72+
Error(vs...)
73+
}
74+

plugin-log_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package goku_plugin
2+
3+
import "testing"
4+
const PluginNameTest = "goku_test"
5+
func TestGenLogger(t *testing.T) {
6+
l:=GenLogger(PluginNameTest)
7+
l.Debug("Debug")
8+
l.Info("info")
9+
l.Warn("warn")
10+
l.Warning("warning")
11+
l.Error("error")
12+
13+
l.Debugf("Debugf")
14+
l.Infof("Infof")
15+
l.Warnf("Warnf")
16+
l.Warningf("warningf")
17+
l.Errorf("errorf")
18+
}

0 commit comments

Comments
 (0)