Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace logrus with zap logger #123

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.2-dev
1.5.0
11 changes: 5 additions & 6 deletions consumer/nf_managemant.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ var SendRegisterNFInstance = func(nrfUri, nfInstanceId string, profile models.Nf
for {
prof, res, err := client.NFInstanceIDDocumentApi.RegisterNFInstance(context.TODO(), nfInstanceId, profile)
if err != nil || res == nil {
// TODO : add log
fmt.Println(fmt.Errorf("UDR register to NRF Error[%s]", err.Error()))
logger.ConsumerLog.Errorf("UDR register to NRF Error[%s]", err.Error())
time.Sleep(2 * time.Second)
continue
}
Expand All @@ -107,14 +106,14 @@ var SendRegisterNFInstance = func(nrfUri, nfInstanceId string, profile models.Nf
retrieveNfInstanceId = resourceUri[strings.LastIndex(resourceUri, "/")+1:]
return prof, resouceNrfUri, retrieveNfInstanceId, err
} else {
fmt.Println("handler returned wrong status code", status)
fmt.Println("NRF return wrong status code", status)
logger.ConsumerLog.Errorln("handler returned wrong status code", status)
logger.ConsumerLog.Errorln("NRF return wrong status code", status)
}
}
}

func SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) {
logger.ConsumerLog.Infof("Send Deregister NFInstance")
logger.ConsumerLog.Infoln("send Deregister NFInstance")

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

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

udrSelf := udr_context.UDR_Self()
configuration := Nnrf_NFManagement.NewConfiguration()
Expand Down
4 changes: 2 additions & 2 deletions datarepository/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

"github.com/gin-gonic/gin"
"github.com/omec-project/udr/logger"
logger_util "github.com/omec-project/util/logger"
utilLogger "github.com/omec-project/util/logger"
)

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

// NewRouter returns a new router.
func NewRouter() *gin.Engine {
router := logger_util.NewGinWithLogrus(logger.GinLog)
router := utilLogger.NewGinWithZap(logger.GinLog)
AddService(router)
return router
}
Expand Down
8 changes: 4 additions & 4 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ import (
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/omec-project/openapi/models"
"github.com/omec-project/udr/logger"
logger_util "github.com/omec-project/util/logger"
utilLogger "github.com/omec-project/util/logger"
)

const (
UDR_EXPECTED_CONFIG_VERSION = "1.0.0"
)

type Config struct {
Info *Info `yaml:"info"`
Configuration *Configuration `yaml:"configuration"`
Logger *logger_util.Logger `yaml:"logger"`
Info *Info `yaml:"info"`
Configuration *Configuration `yaml:"configuration"`
Logger *utilLogger.Logger `yaml:"logger"`
}

type Info struct {
Expand Down
4 changes: 2 additions & 2 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/omec-project/config5g/proto/client"
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/omec-project/udr/logger"
"github.com/sirupsen/logrus"
"go.uber.org/zap"
"gopkg.in/yaml.v2"
)

Expand All @@ -33,7 +33,7 @@ type SmPolicyUpdateEntry struct {
Dnn string
}

var initLog *logrus.Entry
var initLog *zap.SugaredLogger

func init() {
initLog = logger.InitLog
Expand Down
6 changes: 3 additions & 3 deletions factory/udr_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
package factory

import (
"fmt"
"testing"

"github.com/omec-project/udr/logger"
"github.com/stretchr/testify/assert"
)

// Webui URL is not set then default Webui URL value is returned
func TestGetDefaultWebuiUrl(t *testing.T) {
if err := InitConfigFactory("config.example.yaml"); err != nil {
fmt.Printf("Error in InitConfigFactory: %v\n", err)
logger.CfgLog.Errorf("error in InitConfigFactory: %v", err)
}
got := UdrConfig.Configuration.WebuiUri
want := "webui:9876"
Expand All @@ -26,7 +26,7 @@ func TestGetDefaultWebuiUrl(t *testing.T) {
// Webui URL is set to a custom value then custom Webui URL is returned
func TestGetCustomWebuiUrl(t *testing.T) {
if err := InitConfigFactory("udr_config_with_custom_webui_url.yaml"); err != nil {
fmt.Printf("Error in InitConfigFactory: %v\n", err)
logger.CfgLog.Errorf("error in InitConfigFactory: %v", err)
}
got := UdrConfig.Configuration.WebuiUri
want := "myspecialwebui:9872"
Expand Down
16 changes: 7 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ module github.com/omec-project/udr
go 1.21

require (
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/evanphx/json-patch v5.9.0+incompatible
github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0
github.com/mitchellh/mapstructure v1.5.0
github.com/omec-project/config5g v1.5.0
github.com/omec-project/openapi v1.3.1
github.com/omec-project/util v1.1.0
github.com/omec-project/util v1.2.1
github.com/prometheus/client_golang v1.20.4
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/urfave/cli v1.22.15
go.mongodb.org/mongo-driver v1.10.1
go.mongodb.org/mongo-driver v1.17.0
go.uber.org/zap v1.27.0
gopkg.in/yaml.v2 v2.4.0
)

Expand Down Expand Up @@ -46,7 +45,7 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.6.6 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -58,11 +57,10 @@ require (
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
Expand Down
Loading