Skip to content

Commit 570052e

Browse files
authored
[logs] Introducing the zap logger as logrus is deprecated (#215)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> ### Description logrus being deprecated, the zap logger is introduced to replace it. ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [x] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [ ] Additional tests are not required for this change (e.g. documentation update).
1 parent ad92614 commit 570052e

16 files changed

+154
-21
lines changed

changes/20230227175001.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: `[logs]` Introducing the [zap](https://github.com/uber-go/zap) logger since logrus is being deprecated

changes/202303161517.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:sparkles: `[error]` Added the `CorrespondTo` function to determine if an error corresponds to a specific description

utils/commonerrors/errors.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5+
6+
// Package commonerrors defines typical errors which can happen.
57
package commonerrors
68

79
import (
810
"context"
911
"errors"
12+
"strings"
1013
)
1114

1215
var (
@@ -40,6 +43,7 @@ var (
4043
ErrMalicious = errors.New("suspected malicious intent")
4144
)
4245

46+
// Any determines whether the target error is of the same type as any of the errors `err`
4347
func Any(target error, err ...error) bool {
4448
for i := range err {
4549
e := err[i]
@@ -50,6 +54,7 @@ func Any(target error, err ...error) bool {
5054
return false
5155
}
5256

57+
// None determines whether the target error is of none of the types of the errors `err`
5358
func None(target error, err ...error) bool {
5459
for i := range err {
5560
e := err[i]
@@ -60,6 +65,25 @@ func None(target error, err ...error) bool {
6065
return true
6166
}
6267

68+
// CorrespondTo determines whether a `target` error corresponds to a specific error described by `description`
69+
// It will check whether the error contains the string in its description.
70+
// ```code
71+
//
72+
// CorrespondTo(errors.New("feature a is not supported", "not supported") = True
73+
// ```
74+
func CorrespondTo(target error, description ...string) bool {
75+
if target == nil {
76+
return false
77+
}
78+
desc := target.Error()
79+
for i := range description {
80+
if strings.Contains(desc, description[i]) {
81+
return true
82+
}
83+
}
84+
return false
85+
}
86+
6387
// ConvertContextError converts a context error into common errors.
6488
func ConvertContextError(err error) error {
6589
if err == nil {

utils/commonerrors/errors_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13+
"github.com/bxcodec/faker/v3"
1314
"github.com/stretchr/testify/assert"
1415
"github.com/stretchr/testify/require"
1516
"go.uber.org/goleak"
@@ -37,6 +38,12 @@ func TestNone(t *testing.T) {
3738
assert.True(t, None(fmt.Errorf("an error %w", ErrNotImplemented), ErrInvalid, ErrUnknown))
3839
}
3940

41+
func TestCorrespondTo(t *testing.T) {
42+
assert.False(t, CorrespondTo(ErrNotImplemented, ErrInvalid.Error(), ErrUnknown.Error()))
43+
assert.True(t, CorrespondTo(ErrNotImplemented, ErrInvalid.Error(), ErrNotImplemented.Error()))
44+
assert.True(t, CorrespondTo(fmt.Errorf("%v %w", faker.Sentence(), ErrUndefined), ErrUndefined.Error()))
45+
}
46+
4047
func TestContextErrorConversion(t *testing.T) {
4148
defer goleak.VerifyNone(t)
4249
task := func(ctx context.Context) {

utils/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/go-http-utils/headers v0.0.0-20181008091004-fed159eddc2a
1616
github.com/go-logr/logr v0.4.0 // Staying on this version until kubernetes uses a more recent one
1717
github.com/go-logr/stdr v0.4.0
18+
github.com/go-logr/zapr v0.4.0
1819
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
1920
github.com/gofrs/uuid v4.4.0+incompatible
2021
github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f
@@ -35,6 +36,7 @@ require (
3536
github.com/stretchr/testify v1.8.2
3637
go.uber.org/atomic v1.10.0
3738
go.uber.org/goleak v1.2.1
39+
go.uber.org/zap v1.21.0
3840
golang.org/x/net v0.8.0
3941
golang.org/x/sync v0.1.0
4042
golang.org/x/text v0.8.0
@@ -73,6 +75,7 @@ require (
7375
github.com/tklauser/numcpus v0.6.0 // indirect
7476
github.com/xanzy/ssh-agent v0.3.3 // indirect
7577
github.com/yusufpapurcu/wmi v1.2.2 // indirect
78+
go.uber.org/multierr v1.8.0 // indirect
7679
golang.org/x/crypto v0.3.0 // indirect
7780
golang.org/x/sys v0.6.0 // indirect
7881
gopkg.in/ini.v1 v1.67.0 // indirect

utils/go.sum

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 h1:zV3ejI06
5454
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg=
5555
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
5656
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
57+
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
58+
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
5759
github.com/bmatcuk/doublestar/v3 v3.0.0 h1:TQtVPlDnAYwcrVNB2JiGuMc++H5qzWZd9PhkNo5WyHI=
5860
github.com/bmatcuk/doublestar/v3 v3.0.0/go.mod h1:6PcTVMw80pCY1RVuoqu3V++99uQB3vsSYKPTd8AWA0k=
5961
github.com/bombsimon/logrusr v1.1.0 h1:Y03FI4Z/Shyrc9jF26vuaUbnPxC5NMJnTtJA/3Lihq8=
@@ -115,6 +117,8 @@ github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc=
115117
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
116118
github.com/go-logr/stdr v0.4.0 h1:ijk9G/xzDRZdMU1QRhLYdHuWvNZWqte+NZMOGsiKWbc=
117119
github.com/go-logr/stdr v0.4.0/go.mod h1:NO1vneyJDqKVgJYnxhwXWWmQPOvNM391IG3H8ql3jiA=
120+
github.com/go-logr/zapr v0.4.0 h1:uc1uML3hRYL9/ZZPdgHS/n8Nzo+eaYL/Efxkkamf7OM=
121+
github.com/go-logr/zapr v0.4.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk=
118122
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
119123
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
120124
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es=
@@ -237,6 +241,7 @@ github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp
237241
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o=
238242
github.com/pjbgf/sha1cd v0.2.3 h1:uKQP/7QOzNtKYH7UTohZLcjF5/55EnTw0jO/Ru4jZwI=
239243
github.com/pjbgf/sha1cd v0.2.3/go.mod h1:HOK9QrgzdHpbc2Kzip0Q1yi3M2MFGPADtR6HjG65m5M=
244+
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
240245
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
241246
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
242247
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
@@ -256,6 +261,8 @@ github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71e
256261
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
257262
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
258263
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
264+
github.com/shirou/gopsutil/v3 v3.23.1 h1:a9KKO+kGLKEvcPIs4W62v0nu3sciVDOOOPUD0Hz7z/4=
265+
github.com/shirou/gopsutil/v3 v3.23.1/go.mod h1:NN6mnm5/0k8jw4cBfCnJtr5L7ErOTg18tMNpgFkn0hA=
259266
github.com/shirou/gopsutil/v3 v3.23.2 h1:PAWSuiAszn7IhPMBtXsbSCafej7PqUOvY6YywlQUExU=
260267
github.com/shirou/gopsutil/v3 v3.23.2/go.mod h1:gv0aQw33GLo3pG8SiWKiQrbDzbRY1K80RyZJ7V4Th1M=
261268
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
@@ -311,10 +318,16 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
311318
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
312319
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
313320
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
321+
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
314322
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
315323
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
316324
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
317325
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
326+
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
327+
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
328+
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
329+
go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8=
330+
go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw=
318331
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
319332
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
320333
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -399,6 +412,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
399412
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
400413
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
401414
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
415+
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
416+
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
402417
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
403418
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
404419
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -486,6 +501,7 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
486501
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
487502
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
488503
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
504+
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
489505
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
490506
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
491507
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -496,6 +512,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
496512
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
497513
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
498514
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
515+
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
516+
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
499517
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
500518
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
501519
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -549,6 +567,7 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
549567
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
550568
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
551569
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
570+
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
552571
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
553572
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
554573
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -655,6 +674,7 @@ gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
655674
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
656675
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
657676
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
677+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
658678
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
659679
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
660680
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

utils/logs/file_logger.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5+
56
package logs
67

78
import "github.com/sirupsen/logrus"

utils/logs/interfaces.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5+
6+
// Package logs defines loggers for use in projects.
57
package logs
68

79
import (
@@ -12,7 +14,9 @@ import (
1214

1315
//go:generate mockgen -destination=../mocks/mock_$GOPACKAGE.go -package=mocks github.com/ARM-software/golang-utils/utils/$GOPACKAGE Loggers,IMultipleLoggers,WriterWithSource,StdLogger
1416

15-
// Loggers define generic loggers.
17+
// Loggers defines generic loggers which separate common logging messages from errors.
18+
// This is to use in cases where it is necessary to separate the two streams e.g. remote procedure call (RPC)
19+
// In most cases however, if only a standard logger is needed, it is advised to use logr.Logger.
1620
type Loggers interface {
1721
io.Closer
1822
// Check returns whether the loggers are correctly defined or not.
@@ -21,9 +25,9 @@ type Loggers interface {
2125
SetLogSource(source string) error
2226
// SetLoggerSource sets the source of the logger e.g. APIs, Build worker, CMSIS tools.
2327
SetLoggerSource(source string) error
24-
// Log logs to the output logger.
28+
// Log logs to the output stream/logger.
2529
Log(output ...interface{})
26-
// LogError logs to the Error logger.
30+
// LogError logs to the Error stream/logger.
2731
LogError(err ...interface{})
2832
}
2933

utils/logs/message_logger.go renamed to utils/logs/json_logger.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
"github.com/ARM-software/golang-utils/utils/commonerrors"
1515
)
1616

17-
// Definition of JSON message loggers
17+
// JSONLoggers defines a JSON logger
1818
type JSONLoggers struct {
1919
Loggers
2020
mu sync.RWMutex
2121
source string
2222
loggerSource string
2323
writer WriterWithSource
24-
Zerologger zerolog.Logger
24+
zerologger zerolog.Logger
2525
}
2626

2727
func (l *JSONLoggers) SetLogSource(source string) error {
@@ -49,7 +49,7 @@ func (l *JSONLoggers) GetLoggerSource() string {
4949
return l.loggerSource
5050
}
5151

52-
// Checks whether the loggers are correctly defined or not.
52+
// Check checks whether the logger is correctly defined or not.
5353
func (l *JSONLoggers) Check() error {
5454
if l.GetSource() == "" {
5555
return commonerrors.ErrNoLogSource
@@ -64,39 +64,40 @@ func (l *JSONLoggers) Configure() error {
6464
zerolog.TimestampFieldName = "ctime"
6565
zerolog.MessageFieldName = "message"
6666
zerolog.LevelFieldName = "severity"
67-
l.Zerologger = l.Zerologger.With().Timestamp().Logger()
67+
l.zerologger = l.zerologger.With().Timestamp().Logger()
6868
return nil
6969
}
7070

71-
// Logs to the output logger.
71+
// Log logs to the output stream.
7272
func (l *JSONLoggers) Log(output ...interface{}) {
7373
if len(output) == 1 && output[0] == "\n" {
7474
return
7575
}
76-
l.Zerologger.Info().Str("source", l.GetLoggerSource()).Msg(fmt.Sprint(output...))
76+
l.zerologger.Info().Str("source", l.GetLoggerSource()).Msg(fmt.Sprint(output...))
7777
}
7878

79-
// Logs to the Error logger.
79+
// LogError logs to the error stream.
8080
func (l *JSONLoggers) LogError(err ...interface{}) {
8181
if len(err) == 1 && err[0] == "\n" {
8282
return
8383
}
84-
l.Zerologger.Error().Str("source", l.GetLoggerSource()).Msg(fmt.Sprint(err...))
84+
l.zerologger.Error().Str("source", l.GetLoggerSource()).Msg(fmt.Sprint(err...))
8585
}
8686

87-
// Closes the logger
87+
// Close closes the logger
8888
func (l *JSONLoggers) Close() error {
8989
l.mu.Lock()
9090
defer l.mu.Unlock()
9191
return l.writer.Close()
9292
}
9393

94+
// NewJSONLogger creates a Json logger.
9495
func NewJSONLogger(writer WriterWithSource, loggerSource string, source string) (loggers Loggers, err error) {
9596
zerroLogger := JSONLoggers{
9697
source: source,
9798
loggerSource: loggerSource,
9899
writer: writer,
99-
Zerologger: zerolog.New(writer),
100+
zerologger: zerolog.New(writer),
100101
}
101102
err = zerroLogger.Check()
102103
if err != nil {
@@ -121,7 +122,6 @@ func NewJSONLogger(writer WriterWithSource, loggerSource string, source string)
121122
// loggerSource : logger application name
122123
// source : source string
123124
// droppedMessagesLogger : logger for dropped messages
124-
125125
// If pollInterval is greater than 0, a poller is used otherwise a waiter is used.
126126
func NewJSONLoggerForSlowWriter(slowWriter WriterWithSource, ringBufferSize int, pollInterval time.Duration, loggerSource string, source string, droppedMessagesLogger Loggers) (loggers Loggers, err error) {
127127
return NewJSONLogger(NewDiodeWriterForSlowWriter(slowWriter, ringBufferSize, pollInterval, droppedMessagesLogger), loggerSource, source)
File renamed without changes.

0 commit comments

Comments
 (0)