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