Skip to content
Snippets Groups Projects
Commit d77d6bc1 authored by Semyon Krestyaninov's avatar Semyon Krestyaninov
Browse files

Revert "refactor"

This reverts commit 29d881cf.
parent 29d881cf
No related branches found
No related tags found
No related merge requests found
...@@ -57,6 +57,11 @@ func (core *Core) getEntry(entry zapcore.Entry, fields []zapcore.Field) *log.Ent ...@@ -57,6 +57,11 @@ func (core *Core) getEntry(entry zapcore.Entry, fields []zapcore.Field) *log.Ent
fields = append(fields, core.fields...) fields = append(fields, core.fields...)
} }
enc := zapcore.NewMapObjectEncoder()
for _, field := range fields {
field.AddTo(enc)
}
ent := &log.Entry{ ent := &log.Entry{
ID: id.GenerateNewID(), ID: id.GenerateNewID(),
Timestamp: entry.Time, Timestamp: entry.Time,
...@@ -64,22 +69,18 @@ func (core *Core) getEntry(entry zapcore.Entry, fields []zapcore.Field) *log.Ent ...@@ -64,22 +69,18 @@ func (core *Core) getEntry(entry zapcore.Entry, fields []zapcore.Field) *log.Ent
Message: entry.Message, Message: entry.Message,
} }
for _, field := range fields { ent.Category, _ = enc.Fields["category"].(string)
switch field.Key { ent.Component, _ = enc.Fields["component"].(string)
case "category": ent.Event, _ = enc.Fields["event"].(string)
ent.Category = field.String ent.ObjectID, _ = enc.Fields["object"].(*oid.ObjectId)
case "component": ent.CallerID, _ = enc.Fields["caller"].(*oid.ObjectId)
ent.Component = field.String ent.Attr = enc.Fields["attr"]
case "event":
ent.Event = field.String if tags, ok := enc.Fields["tags"].([]any); ok {
case "object": for _, item := range tags {
ent.ObjectID = field.Interface.(*oid.ObjectId) if tag, ok := item.(string); ok {
case "caller": ent.Tags = append(ent.Tags, tag)
ent.CallerID = field.Interface.(*oid.ObjectId) }
case "attr":
ent.Attr = field.Interface
case "tags":
ent.Tags, _ = field.Interface.([]string)
} }
} }
......
...@@ -62,12 +62,12 @@ func Attr(attr any) zap.Field { ...@@ -62,12 +62,12 @@ func Attr(attr any) zap.Field {
if attr == nil { if attr == nil {
return zap.Skip() return zap.Skip()
} }
return zap.Reflect("attr", attr) return zap.Any("attr", attr)
} }
func Tags(tags ...string) zap.Field { func Tags(tags ...string) zap.Field {
if len(tags) == 0 { if len(tags) == 0 {
return zap.Skip() return zap.Skip()
} }
return zap.Reflect("tags", tags) return zap.Strings("tags", tags)
} }
...@@ -173,7 +173,7 @@ func TestTags(t *testing.T) { ...@@ -173,7 +173,7 @@ func TestTags(t *testing.T) {
field zap.Field field zap.Field
want zap.Field want zap.Field
}{ }{
{name: "ok", field: Tags("a", "b", "c"), want: zap.Reflect("tags", []string{"a", "b", "c"})}, {name: "ok", field: Tags("a", "b", "c"), want: zap.Strings("tags", []string{"a", "b", "c"})},
{name: "invalid", field: Tags(nil...), want: zap.Skip()}, {name: "invalid", field: Tags(nil...), want: zap.Skip()},
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment