Skip to content

Commit

Permalink
fix: rename resource to name
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Dec 24, 2024
1 parent 4cd5432 commit 5cd7698
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions pkg/log/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error) { //nolint
if _, ok := entry.Data["owner"]; !ok {
return f.FallbackFormatter.Format(entry)
}
if _, ok := entry.Data["resource"]; !ok {
if _, ok := entry.Data["state"]; !ok {
return f.FallbackFormatter.Format(entry)
}
if _, ok := entry.Data["state"]; !ok {
if _, ok := entry.Data["name"]; !ok {
return f.FallbackFormatter.Format(entry)
}

owner := entry.Data["owner"].(string)
resource := entry.Data["resource"].(string)
resourceName := entry.Data["name"].(string)
state := entry.Data["state"].(int)

var sortedFields = make([]string, 0)
Expand Down Expand Up @@ -74,7 +74,7 @@ func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error) { //nolint
msg := fmt.Sprintf("%s - %s - %s - %s - %s\n",
ColorRegion.Sprint(owner),
ColorResourceType.Sprint(resourceType),
ColorResourceID.Sprint(resource),
ColorResourceID.Sprint(resourceName),
ColorResourceProperties.Sprintf("[%s]", strings.Join(sortedFields, ", ")),
msgColor.Sprint(entry.Message))

Expand Down
22 changes: 11 additions & 11 deletions pkg/log/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func TestCustomFormatter_Format(t *testing.T) {
name: "missing-type",
input: &logrus.Entry{
Data: logrus.Fields{
"owner": "owner",
"resource": "resource",
"owner": "owner",
"name": "resource",
},
},
want: []byte(`time="0001-01-01T00:00:00Z" level=panic owner=owner resource=resource
want: []byte(`time="0001-01-01T00:00:00Z" level=panic name=resource owner=owner
`),
},
{
Expand Down Expand Up @@ -66,12 +66,12 @@ func TestCustomFormatter_Format(t *testing.T) {
name: "missing-state",
input: &logrus.Entry{
Data: logrus.Fields{
"type": "test",
"owner": "owner",
"resource": "resource",
"type": "test",
"owner": "owner",
"name": "resource",
},
},
want: []byte(`time="0001-01-01T00:00:00Z" level=panic owner=owner resource=resource type=test
want: []byte(`time="0001-01-01T00:00:00Z" level=panic name=resource owner=owner type=test
`),
},
{
Expand All @@ -81,7 +81,7 @@ func TestCustomFormatter_Format(t *testing.T) {
Data: logrus.Fields{
"type": "test",
"owner": "owner",
"resource": "resource",
"name": "resource",
"state": 0,
"prop:one": "1",
"prop:two": "2",
Expand All @@ -101,7 +101,7 @@ func TestCustomFormatter_Format(t *testing.T) {
Data: logrus.Fields{
"type": "test",
"owner": "owner",
"resource": "resource",
"name": "resource",
"state": 2,
"prop:one": "1",
"prop:two": "2",
Expand All @@ -122,7 +122,7 @@ func TestCustomFormatter_Format(t *testing.T) {
Data: logrus.Fields{
"type": "test",
"owner": "owner",
"resource": "resource",
"name": "resource",
"state": 3,
"prop:one": "1",
"prop:two": "2",
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestCustomFormatter_FormatReasons(t *testing.T) {
Data: logrus.Fields{
"type": "test",
"owner": "owner",
"resource": "resource",
"name": "resource",
"state": 0,
"prop:one": "1",
"prop:two": "2",
Expand Down
2 changes: 1 addition & 1 deletion pkg/queue/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (i *Item) Print() {

rString, ok := i.Resource.(resource.LegacyStringer)
if ok {
itemLog = itemLog.WithField("resource", rString.String())
itemLog = itemLog.WithField("name", rString.String())
}

rProp, ok := i.Resource.(resource.PropertyGetter)
Expand Down

0 comments on commit 5cd7698

Please sign in to comment.