mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
feat: add json log field
This commit is contained in:
parent
dbafcc1fa3
commit
4bc776267e
@ -1,28 +1,44 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// NumKey - generic number attribute
|
||||||
NumKey = "num"
|
NumKey = "num"
|
||||||
|
// NameKey - generic name attribute
|
||||||
NameKey = "name"
|
NameKey = "name"
|
||||||
|
// ValueKey - generic value attribute
|
||||||
// ValueKey represents a generic value attribute.
|
|
||||||
ValueKey = "value"
|
ValueKey = "value"
|
||||||
|
// JSONKey - generic json attribute
|
||||||
|
JSONKey = "json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// FNum - returns zap field
|
||||||
func FNum(num int) zap.Field {
|
func FNum(num int) zap.Field {
|
||||||
return zap.Int(NumKey, num)
|
return zap.Int(NumKey, num)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FName - returns zap field
|
||||||
func FName(name string) zap.Field {
|
func FName(name string) zap.Field {
|
||||||
return zap.String(NameKey, name)
|
return zap.String(NameKey, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FValue - returns zap field
|
||||||
func FValue(value interface{}) zap.Field {
|
func FValue(value interface{}) zap.Field {
|
||||||
return zap.String(ValueKey, fmt.Sprintf("%v", value))
|
return zap.String(ValueKey, fmt.Sprintf("%v", value))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FJSON - returns zap field
|
||||||
|
func FJSON(v interface{}) zap.Field {
|
||||||
|
if out, err := json.Marshal(v); err != nil {
|
||||||
|
return zap.String(JSONKey+"_error", err.Error())
|
||||||
|
} else {
|
||||||
|
raw := json.RawMessage(out)
|
||||||
|
return zap.Any(JSONKey, &raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user