Skip to content

Commit d3576c6

Browse files
authored
Replace logrus with zap logger (#123)
* Replace `logrus` with `zap` logger Signed-off-by: Arrobo, Gabriel <[email protected]> * Address `lint` issue Signed-off-by: Arrobo, Gabriel <[email protected]> --------- Signed-off-by: Arrobo, Gabriel <[email protected]>
1 parent d049a4b commit d3576c6

File tree

12 files changed

+227
-244
lines changed

12 files changed

+227
-244
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.2-dev
1+
1.5.0

consumer/nf_managemant.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ var SendRegisterNFInstance = func(nrfUri, nfInstanceId string, profile models.Nf
8585
for {
8686
prof, res, err := client.NFInstanceIDDocumentApi.RegisterNFInstance(context.TODO(), nfInstanceId, profile)
8787
if err != nil || res == nil {
88-
// TODO : add log
89-
fmt.Println(fmt.Errorf("UDR register to NRF Error[%s]", err.Error()))
88+
logger.ConsumerLog.Errorf("UDR register to NRF Error[%s]", err.Error())
9089
time.Sleep(2 * time.Second)
9190
continue
9291
}
@@ -107,14 +106,14 @@ var SendRegisterNFInstance = func(nrfUri, nfInstanceId string, profile models.Nf
107106
retrieveNfInstanceId = resourceUri[strings.LastIndex(resourceUri, "/")+1:]
108107
return prof, resouceNrfUri, retrieveNfInstanceId, err
109108
} else {
110-
fmt.Println("handler returned wrong status code", status)
111-
fmt.Println("NRF return wrong status code", status)
109+
logger.ConsumerLog.Errorln("handler returned wrong status code", status)
110+
logger.ConsumerLog.Errorln("NRF return wrong status code", status)
112111
}
113112
}
114113
}
115114

116115
func SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) {
117-
logger.ConsumerLog.Infof("Send Deregister NFInstance")
116+
logger.ConsumerLog.Infoln("send Deregister NFInstance")
118117

119118
udrSelf := udr_context.UDR_Self()
120119
// Set client and set url
@@ -146,7 +145,7 @@ func SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err erro
146145
}
147146

148147
var SendUpdateNFInstance = func(patchItem []models.PatchItem) (nfProfile models.NfProfile, problemDetails *models.ProblemDetails, err error) {
149-
logger.ConsumerLog.Debugf("Send Update NFInstance")
148+
logger.ConsumerLog.Debugln("send Update NFInstance")
150149

151150
udrSelf := udr_context.UDR_Self()
152151
configuration := Nnrf_NFManagement.NewConfiguration()

datarepository/routers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
"github.com/gin-gonic/gin"
2222
"github.com/omec-project/udr/logger"
23-
logger_util "github.com/omec-project/util/logger"
23+
utilLogger "github.com/omec-project/util/logger"
2424
)
2525

2626
// Route is the information for every URI.
@@ -40,7 +40,7 @@ type Routes []Route
4040

4141
// NewRouter returns a new router.
4242
func NewRouter() *gin.Engine {
43-
router := logger_util.NewGinWithLogrus(logger.GinLog)
43+
router := utilLogger.NewGinWithZap(logger.GinLog)
4444
AddService(router)
4545
return router
4646
}

factory/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ import (
1414
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
1515
"github.com/omec-project/openapi/models"
1616
"github.com/omec-project/udr/logger"
17-
logger_util "github.com/omec-project/util/logger"
17+
utilLogger "github.com/omec-project/util/logger"
1818
)
1919

2020
const (
2121
UDR_EXPECTED_CONFIG_VERSION = "1.0.0"
2222
)
2323

2424
type Config struct {
25-
Info *Info `yaml:"info"`
26-
Configuration *Configuration `yaml:"configuration"`
27-
Logger *logger_util.Logger `yaml:"logger"`
25+
Info *Info `yaml:"info"`
26+
Configuration *Configuration `yaml:"configuration"`
27+
Logger *utilLogger.Logger `yaml:"logger"`
2828
}
2929

3030
type Info struct {

factory/factory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/omec-project/config5g/proto/client"
1818
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
1919
"github.com/omec-project/udr/logger"
20-
"github.com/sirupsen/logrus"
20+
"go.uber.org/zap"
2121
"gopkg.in/yaml.v2"
2222
)
2323

@@ -33,7 +33,7 @@ type SmPolicyUpdateEntry struct {
3333
Dnn string
3434
}
3535

36-
var initLog *logrus.Entry
36+
var initLog *zap.SugaredLogger
3737

3838
func init() {
3939
initLog = logger.InitLog

factory/udr_config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
package factory
88

99
import (
10-
"fmt"
1110
"testing"
1211

12+
"github.com/omec-project/udr/logger"
1313
"github.com/stretchr/testify/assert"
1414
)
1515

1616
// Webui URL is not set then default Webui URL value is returned
1717
func TestGetDefaultWebuiUrl(t *testing.T) {
1818
if err := InitConfigFactory("config.example.yaml"); err != nil {
19-
fmt.Printf("Error in InitConfigFactory: %v\n", err)
19+
logger.CfgLog.Errorf("error in InitConfigFactory: %v", err)
2020
}
2121
got := UdrConfig.Configuration.WebuiUri
2222
want := "webui:9876"
@@ -26,7 +26,7 @@ func TestGetDefaultWebuiUrl(t *testing.T) {
2626
// Webui URL is set to a custom value then custom Webui URL is returned
2727
func TestGetCustomWebuiUrl(t *testing.T) {
2828
if err := InitConfigFactory("udr_config_with_custom_webui_url.yaml"); err != nil {
29-
fmt.Printf("Error in InitConfigFactory: %v\n", err)
29+
logger.CfgLog.Errorf("error in InitConfigFactory: %v", err)
3030
}
3131
got := UdrConfig.Configuration.WebuiUri
3232
want := "myspecialwebui:9872"

go.mod

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ module github.com/omec-project/udr
33
go 1.21
44

55
require (
6-
github.com/antonfisher/nested-logrus-formatter v1.3.1
76
github.com/evanphx/json-patch v5.9.0+incompatible
87
github.com/gin-gonic/gin v1.10.0
98
github.com/google/uuid v1.6.0
109
github.com/mitchellh/mapstructure v1.5.0
1110
github.com/omec-project/config5g v1.5.0
1211
github.com/omec-project/openapi v1.3.1
13-
github.com/omec-project/util v1.1.0
12+
github.com/omec-project/util v1.2.1
1413
github.com/prometheus/client_golang v1.20.4
15-
github.com/sirupsen/logrus v1.9.3
1614
github.com/stretchr/testify v1.9.0
1715
github.com/urfave/cli v1.22.15
18-
go.mongodb.org/mongo-driver v1.10.1
16+
go.mongodb.org/mongo-driver v1.17.0
17+
go.uber.org/zap v1.27.0
1918
gopkg.in/yaml.v2 v2.4.0
2019
)
2120

@@ -46,7 +45,7 @@ require (
4645
github.com/mattn/go-isatty v0.0.20 // indirect
4746
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4847
github.com/modern-go/reflect2 v1.0.2 // indirect
49-
github.com/montanaflynn/stats v0.6.6 // indirect
48+
github.com/montanaflynn/stats v0.7.1 // indirect
5049
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5150
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
5251
github.com/pkg/errors v0.9.1 // indirect
@@ -58,11 +57,10 @@ require (
5857
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
5958
github.com/ugorji/go/codec v1.2.12 // indirect
6059
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
61-
github.com/xdg-go/scram v1.1.1 // indirect
62-
github.com/xdg-go/stringprep v1.0.3 // indirect
63-
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
60+
github.com/xdg-go/scram v1.1.2 // indirect
61+
github.com/xdg-go/stringprep v1.0.4 // indirect
62+
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
6463
go.uber.org/multierr v1.10.0 // indirect
65-
go.uber.org/zap v1.27.0 // indirect
6664
golang.org/x/arch v0.8.0 // indirect
6765
golang.org/x/crypto v0.27.0 // indirect
6866
golang.org/x/net v0.29.0 // indirect

0 commit comments

Comments
 (0)