Skip to content

Commit

Permalink
refactor(writer): revamp warn log level
Browse files Browse the repository at this point in the history
Signed-off-by: Dwi Siswanto <[email protected]>
  • Loading branch information
dwisiswant0 committed Mar 27, 2024
1 parent 150b8a3 commit 3b9a8a2
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions internal/writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,10 @@ func (w *logWriter) write(d data) error {
switch level := d["level"].(string); level {
case "debug":
w.writeDebug(d)
case "info":
w.writeInfo(d)
// case "info":
// w.writeInfo(d)
case "warn":
r, err := json.Marshal(d["request"])
if err != nil {
return err
}

w.writeWarn(d, r)
w.writeWarn(d)
case "error":
w.writeError(d)
case "fatal":
Expand All @@ -66,19 +61,33 @@ func (w *logWriter) writeDebug(d data) {
}

func (w *logWriter) writeInfo(d data) {
if opt, ok := d["options"].(data); ok {
w.Info(d["msg"],
"options", opt,
)
}
// if opt, ok := d["options"].(data); ok {
// o, err := json.Marshal(opt)
// if err != nil {
// return
// }

// w.Info(d["msg"], "options", string(o))
// } else {
w.Info(d["msg"])
// }
}

func (w *logWriter) writeWarn(d data, r []byte) {
w.Warn(d["msg"],
"id", d["id"],
"threat", d["category"],
"request", string(r),
)
func (w *logWriter) writeWarn(d data) {
if req, ok := d["request"].(data); ok {
r, err := json.Marshal(req)
if err != nil {
return
}

w.Warn(d["msg"],
"id", d["id"],
"threat", d["category"],
"request", string(r),
)
} else {
w.Warn(d["msg"])
}
}

func (w *logWriter) writeError(d data) {
Expand Down

0 comments on commit 3b9a8a2

Please sign in to comment.