44 "errors"
55 "fmt"
66 "github.com/skyhackvip/risk_engine/internal/errcode"
7+ "github.com/skyhackvip/risk_engine/internal/log"
78 "github.com/skyhackvip/risk_engine/internal/operator"
8- "log"
99)
1010
1111type NodeInfo struct {
@@ -41,7 +41,7 @@ func (rule *Rule) Parse(ctx *PipelineContext, depends map[string]IFeature) (outp
4141 //rule.Conditions
4242 if len (rule .Conditions ) == 0 {
4343 err = errors .New (fmt .Sprintf ("rule (%s) condition is empty" , rule .Name ))
44- log .Println (err )
44+ log .Error (err )
4545 return
4646 }
4747
@@ -50,13 +50,13 @@ func (rule *Rule) Parse(ctx *PipelineContext, depends map[string]IFeature) (outp
5050 if feature , ok := depends [condition .Feature ]; ok {
5151 rs , err := feature .Compare (condition .Operator , condition .Value )
5252 if err != nil {
53- log .Println (err )
53+ log .Error (err )
5454 return output , nil //value deafult
5555 }
5656 conditionRet [condition .Name ] = rs
5757 } else {
5858 //lack of feature whether ignore
59- log .Printf ("error lack of feature: %s\n " , condition .Feature )
59+ log .Error ("error lack of feature: %s" , condition .Feature )
6060 //continue
6161 }
6262 }
@@ -72,7 +72,7 @@ func (rule *Rule) Parse(ctx *PipelineContext, depends map[string]IFeature) (outp
7272 if err != nil {
7373 return
7474 }
75- log .Printf ("rule %s (%s) decision is : %v, output: %v \n " , rule .Label , rule .Name , logicRet , rule . Decision . Output )
75+ log .Infof ("rule result : %v" , rule .Label , rule .Name , logicRet )
7676 output .SetHit (logicRet )
7777
7878 //assign
@@ -139,9 +139,14 @@ func (block Block) parse(depends map[string]IFeature) (interface{}, bool, error)
139139 }
140140 for _ , condition := range block .Conditions {
141141 if feature , ok := depends [block .Feature ]; ok {
142+ if v , _ := feature .GetValue (); v == nil {
143+ log .Errorf ("feature %s empty" , feature .GetName ())
144+ continue
145+ }
146+
142147 hit , err := feature .Compare (condition .Operator , condition .Value )
143148 if err != nil {
144- log .Println ("parse error" , err )
149+ log .Errorf ("parse error %s " , err )
145150 continue
146151 }
147152 if hit {
@@ -152,7 +157,7 @@ func (block Block) parse(depends map[string]IFeature) (interface{}, bool, error)
152157 }
153158 }
154159 } else {
155- log .Printf ( "error lack of feature: %s\n " , block .Feature )
160+ log .Errorf ( " lack of feature: %s" , block .Feature )
156161 continue
157162 }
158163 }
0 commit comments