fix
This commit is contained in:
parent
004fc91586
commit
98976bba13
@ -1,7 +1,9 @@
|
|||||||
package framework
|
package framework
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
@ -45,7 +47,38 @@ func CreatePlugin(name string, hook EmailHook) *Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type logFormatter struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format 定义日志输出格式
|
||||||
|
func (l *logFormatter) Format(entry *log.Entry) ([]byte, error) {
|
||||||
|
b := bytes.Buffer{}
|
||||||
|
|
||||||
|
b.WriteString(fmt.Sprintf("[%s]", entry.Level.String()))
|
||||||
|
b.WriteString(fmt.Sprintf("[%s]", entry.Time.Format("2006-01-02 15:04:05")))
|
||||||
|
if entry.Context != nil {
|
||||||
|
ctx := entry.Context.(*context.Context)
|
||||||
|
if ctx != nil {
|
||||||
|
b.WriteString(fmt.Sprintf("[%s]", ctx.GetValue(context.LogID)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.WriteString(fmt.Sprintf("[%s:%d]", entry.Caller.File, entry.Caller.Line))
|
||||||
|
b.WriteString(entry.Message)
|
||||||
|
|
||||||
|
b.WriteString("\n")
|
||||||
|
return b.Bytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Plugin) Run() {
|
func (p *Plugin) Run() {
|
||||||
|
|
||||||
|
// 设置日志格式为json格式
|
||||||
|
log.SetFormatter(&logFormatter{})
|
||||||
|
log.SetReportCaller(true)
|
||||||
|
|
||||||
|
// 设置将日志输出到标准输出(默认的输出为stderr,标准错误)
|
||||||
|
// 日志消息输出可以是任意的io.writer类型
|
||||||
|
log.SetOutput(os.Stdout)
|
||||||
|
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
panic("Command Params Error!")
|
panic("Command Params Error!")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user