Skip to content

Commit

Permalink
Replace logrus with zap (#131)
Browse files Browse the repository at this point in the history
Signed-off-by: Arrobo, Gabriel <[email protected]>
  • Loading branch information
gab-arrobo authored Oct 3, 2024
1 parent 3df6b3c commit 0e3d283
Show file tree
Hide file tree
Showing 20 changed files with 187 additions and 222 deletions.
20 changes: 0 additions & 20 deletions .fossa.yml

This file was deleted.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.3-dev
1.5.0
4 changes: 2 additions & 2 deletions accesstoken/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/nrf/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
6 changes: 4 additions & 2 deletions context/dataconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import (
"strconv"
"strings"
"unicode"

"github.com/omec-project/nrf/logger"
)

// Ipv6ToInt - Convert Ipv6 string to *bigInt
func Ipv6ToInt(ipv6 string) *big.Int {
ipv6 = ipv6 + "/32"
ip, _, err := net.ParseCIDR(ipv6)
if err != nil {
fmt.Println("Error", ip, err)
logger.UtilLog.Errorln("error", ip, err)
}
IPv6Int := big.NewInt(0)
IPv6Int.SetBytes(ip)
Expand All @@ -31,7 +33,7 @@ func Ipv4ToInt(ipv4 string) int64 {
ipv4 = ipv4 + "/24"
ip, _, err := net.ParseCIDR(ipv4)
if err != nil {
fmt.Println("Error", ip, err)
logger.UtilLog.Errorln("error", ip, err)
}
IPv4Int := big.NewInt(0)
IPv4Int.SetBytes(ip)
Expand Down
18 changes: 9 additions & 9 deletions dbadapter/dbadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package dbadapter

import (
"context"
"log"

"github.com/omec-project/nrf/logger"
"github.com/omec-project/util/mongoapi"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
Expand Down Expand Up @@ -35,32 +35,32 @@ type MongoDBClient struct {
}

func iterateChangeStream(routineCtx context.Context, stream *mongo.ChangeStream) {
log.Println("iterate change stream for timeout")
logger.AppLog.Infoln("iterate change stream for timeout")
defer stream.Close(routineCtx)
for stream.Next(routineCtx) {
var data bson.M
if err := stream.Decode(&data); err != nil {
panic(err)
}
log.Println("iterate stream : ", data)
logger.AppLog.Infoln("iterate stream:", data)
}
}

func ConnectToDBClient(dbName string, url string, enableStream bool, nfProfileExpiryEnable bool) DBInterface {
for {
MongoClient, _ := mongoapi.NewMongoClient(url, dbName)
if MongoClient != nil {
log.Println("MongoDB Connection Successful")
logger.AppLog.Infoln("MongoDB Connection Successful")
DBClient = MongoClient
break
} else {
log.Println("MongoDB Connection Failed")
logger.AppLog.Infoln("MongoDB Connection Failed")
}
}

db := DBClient.(*mongoapi.MongoClient)
if enableStream {
log.Println("MongoDB Change stream Enabled")
logger.AppLog.Infoln("MongoDB Change stream Enabled")
database := db.Client.Database(dbName)
NfProfileColl := database.Collection("NfProfile")
//create stream to monitor actions on the collection
Expand All @@ -75,12 +75,12 @@ func ConnectToDBClient(dbName string, url string, enableStream bool, nfProfileEx
}

if nfProfileExpiryEnable {
log.Println("NfProfile document expiry enabled")
logger.AppLog.Infoln("NfProfile document expiry enabled")
ret := db.RestfulAPICreateTTLIndex("NfProfile", 0, "expireAt")
if ret {
log.Println("TTL Index created for Field : expireAt in Collection : NfProfile")
logger.AppLog.Infoln("ttl Index created for Field : expireAt in Collection: NfProfile")
} else {
log.Println("TTL Index exists for Field : expireAt in Collection : NfProfile")
logger.AppLog.Infoln("ttl Index exists for Field : expireAt in Collection: NfProfile")
}
}
return DBClient
Expand Down
4 changes: 2 additions & 2 deletions discovery/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/omec-project/nrf/factory"
"github.com/omec-project/nrf/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 @@ -42,7 +42,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 @@ -16,7 +16,7 @@ import (
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/omec-project/nrf/logger"
"github.com/omec-project/openapi/models"
logger_util "github.com/omec-project/util/logger"
utilLogger "github.com/omec-project/util/logger"
)

const (
Expand All @@ -30,9 +30,9 @@ const (
)

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 @@ -13,18 +13,18 @@ import (
"fmt"
"os"

"go.uber.org/zap"
"gopkg.in/yaml.v2"

"github.com/omec-project/config5g/proto/client"
"github.com/omec-project/nrf/logger"
"github.com/sirupsen/logrus"
)

var ManagedByConfigPod bool

var NrfConfig Config

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

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

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -16,7 +15,7 @@ import (
// Webui URL is not set then default Webui URL value is returned
func TestGetDefaultWebuiUrl(t *testing.T) {
if err := InitConfigFactory("../nrfTest/nrfcfg.yaml"); err != nil {
fmt.Printf("Error in InitConfigFactory: %v\n", err)
t.Logf("error in InitConfigFactory: %v", err)
}
got := NrfConfig.Configuration.WebuiUri
want := "webui:9876"
Expand All @@ -26,7 +25,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("../nrfTest/nrfcfg_with_custom_webui_url.yaml"); err != nil {
fmt.Printf("Error in InitConfigFactory: %v\n", err)
t.Logf("error in InitConfigFactory: %v", err)
}
got := NrfConfig.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 @@ -4,19 +4,18 @@ go 1.21

require (
github.com/antihax/optional v1.0.0
github.com/antonfisher/nested-logrus-formatter v1.3.1
github.com/gin-gonic/gin v1.10.0
github.com/golang-jwt/jwt v3.2.2+incompatible
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

0 comments on commit 0e3d283

Please sign in to comment.