Skip to content
Snippets Groups Projects
Commit 91301591 authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'feature/PRXS-951-1897-UpdateLogSDK' into 'master'

Изменено название поля LogLevel на Level для объекта записи лога

See merge request perxis/perxis-go!175
parents 46ebe288 76b684e2
No related branches found
No related tags found
No related merge requests found
......@@ -35,13 +35,13 @@ func (id *OrganizationId) FromParts(parts []string) error {
func (id *OrganizationId) Map() map[string]any {
return map[string]any{
"organization_id": id.OrganizationID,
"org_id": id.OrganizationID,
"type": id.Type(),
}
}
func (id *OrganizationId) FromMap(m map[string]any) error {
id.OrganizationID, _ = m["organization_id"].(string)
id.OrganizationID, _ = m["org_id"].(string)
if id.OrganizationID == "" {
return fmt.Errorf("%w: OrganizationId required", ErrInvalidID)
}
......
......@@ -38,7 +38,7 @@ func Test_OrganizationId(t *testing.T) {
},
{
name: "valid map",
in: map[string]any{"type": "organization", "organization_id": "<org_id>"},
in: map[string]any{"type": "organization", "org_id": "<org_id>"},
out: "/orgs/<org_id>",
result: &id.ObjectId{Descriptor: &id.OrganizationId{OrganizationID: "<org_id>"}},
},
......
......@@ -29,7 +29,7 @@ func (l Level) String() string {
type Entry struct {
ID string `json:"id" bson:"id" mapstructure:"id"`
Timestamp time.Time `json:"timestamp,omitempty" bson:"timestamp,omitempty" mapstructure:"timestamp,omitempty"`
LogLevel Level `json:"log_level,omitempty" bson:"log_level,omitempty" mapstructure:"log_level,omitempty"`
Level Level `json:"level,omitempty" bson:"level,omitempty" mapstructure:"level,omitempty"`
Message string `json:"message,omitempty" bson:"message,omitempty" mapstructure:"message,omitempty"`
Category string `json:"category,omitempty" bson:"category,omitempty" mapstructure:"category,omitempty"`
Component string `json:"component,omitempty" bson:"component,omitempty" mapstructure:"component,omitempty"`
......@@ -54,7 +54,7 @@ func EntryToPB(entry *Entry) *pb.LogEntry {
logEntry := &pb.LogEntry{
Id: entry.ID,
Timestamp: timestamppb.New(entry.Timestamp),
Level: pb.LogLevel(entry.LogLevel),
Level: pb.LogLevel(entry.Level),
Message: entry.Message,
Category: entry.Category,
Component: entry.Component,
......@@ -76,7 +76,7 @@ func EntryFromPB(request *pb.LogEntry) *Entry {
logEntry := &Entry{
ID: request.Id,
Timestamp: request.Timestamp.AsTime(),
LogLevel: Level(request.Level),
Level: Level(request.Level),
Message: request.Message,
Category: request.Category,
Component: request.Component,
......@@ -103,7 +103,7 @@ func (e *Entry) ToMap() map[string]any {
res := map[string]any{
"id": e.ID,
"timestamp": e.Timestamp,
"log_level": e.LogLevel,
"level": e.Level,
"message": e.Message,
"category": e.Category,
"component": e.Component,
......
......@@ -42,7 +42,7 @@ func TestEntry_ToMap(t *testing.T) {
nil,
nil,
},
map[string]interface{}{"caller": map[string]interface{}{"type": "user", "user_id": "<user_id>"}, "caller_id": "/users/<user_id>", "category": "", "component": "", "event": "", "id": "1", "log_level": Level(0), "message": "message", "object": map[string]interface{}{"env_id": "<env_id>", "space_id": "<space_id>", "type": "environment"}, "object_id": "/spaces/<space_id>/envs/<env_id>", "timestamp": time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)},
map[string]interface{}{"caller": map[string]interface{}{"type": "user", "user_id": "<user_id>"}, "caller_id": "/users/<user_id>", "category": "", "component": "", "event": "", "id": "1", "level": Level(0), "message": "message", "object": map[string]interface{}{"env_id": "<env_id>", "space_id": "<space_id>", "type": "environment"}, "object_id": "/spaces/<space_id>/envs/<env_id>", "timestamp": time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)},
},
}
for _, tt := range tests {
......@@ -50,7 +50,7 @@ func TestEntry_ToMap(t *testing.T) {
e := &Entry{
ID: tt.fields.ID,
Timestamp: tt.fields.Timestamp,
LogLevel: tt.fields.LogLevel,
Level: tt.fields.LogLevel,
Message: tt.fields.Message,
Category: tt.fields.Category,
Component: tt.fields.Component,
......
......@@ -67,7 +67,7 @@ func (core *Core) getEntry(entry zapcore.Entry, fields []zapcore.Field) *logs.En
ent := &logs.Entry{
ID: id.GenerateNewID(),
Timestamp: entry.Time,
LogLevel: logs.Level(entry.Level),
Level: logs.Level(entry.Level),
Message: entry.Message,
}
......
......@@ -41,7 +41,7 @@ func TestCore_getEntry(t *testing.T) {
},
},
want: &logs.Entry{
LogLevel: logs.Level(zapcore.InfoLevel),
Level: logs.Level(zapcore.InfoLevel),
Message: "создан элемент коллекции",
Category: "create",
Component: "Items.Service",
......
......@@ -26,7 +26,7 @@ func TestExample(t *testing.T) {
wantEntries := []*logs.Entry{
{
LogLevel: logs.Level(zapcore.InfoLevel),
Level: logs.Level(zapcore.InfoLevel),
Message: "Successfully created",
Component: "Items",
Event: items.EventCreateItem,
......@@ -35,7 +35,7 @@ func TestExample(t *testing.T) {
Tags: []string{"tag1", "tag2", "tag3"},
},
{
LogLevel: logs.Level(zapcore.WarnLevel),
Level: logs.Level(zapcore.WarnLevel),
Message: "Successfully updated",
Component: "Items",
Event: items.EventUpdateItem,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment