|
@@ -1,8 +1,9 @@
|
|
|
package nodes
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
"encoding/json"
|
|
|
- "github.com/Sirupsen/logrus"
|
|
|
+ "github.com/gogf/gf/v2/os/glog"
|
|
|
"sparrow/pkg/protocol"
|
|
|
"sparrow/pkg/ruleEngine"
|
|
|
)
|
|
@@ -14,7 +15,6 @@ type LogNodeConfig struct {
|
|
|
// LogNode 日志打印节点
|
|
|
type LogNode struct {
|
|
|
config *LogNodeConfig
|
|
|
- mLog *logrus.Logger
|
|
|
}
|
|
|
|
|
|
func (l *LogNode) Init(ctx ruleEngine.Context, config string) error {
|
|
@@ -30,13 +30,17 @@ func (l *LogNode) Init(ctx ruleEngine.Context, config string) error {
|
|
|
}
|
|
|
l.config = c
|
|
|
}
|
|
|
- l.mLog = logrus.New()
|
|
|
+ glog.SetPath("./log_nodes/")
|
|
|
+ glog.SetStdoutPrint(false)
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func (l *LogNode) OnMessage(ctx ruleEngine.Context, message *protocol.Message) error {
|
|
|
if l.config.Stdout {
|
|
|
- l.mLog.Infof("日志节点:[设备ID:%s][消息类型:%s][消息内容:%s]", message.MetaData["device_id"], message.Type, message.Data)
|
|
|
+ //l.mLog.Infof("日志节点:[设备ID:%s][消息类型:%s][消息内容:%s]", message.MetaData["device_id"], message.Type, message.Data)
|
|
|
+ if did, ok := message.MetaData["device_id"]; ok {
|
|
|
+ glog.File(did.(string)).Infof(context.Background(), "[消息类型:%s][消息内容:%s]", message.Type, message.Data)
|
|
|
+ }
|
|
|
}
|
|
|
ctx.TellNext(message, protocol.Success)
|
|
|
return nil
|