From fd58df6509fed7653209b698fbfc53fadd120b92 Mon Sep 17 00:00:00 2001 From: gab-arrobo Date: Wed, 2 Oct 2024 17:21:19 -0700 Subject: [PATCH] Replace `logrus` with `zap` logger (#125) Signed-off-by: Arrobo, Gabriel --- VERSION | 2 +- consumer/nf_management.go | 8 ++- factory/config.go | 10 ++-- factory/nssf_config_test.go | 5 +- go.mod | 6 +-- go.sum | 9 +--- logger/logger.go | 99 +++++++++++++++++++++--------------- nssaiavailability/routers.go | 4 +- nsselection/routers.go | 4 +- nssf.go | 6 +-- service/init.go | 77 +++++++++++----------------- 11 files changed, 109 insertions(+), 121 deletions(-) diff --git a/VERSION b/VERSION index f9f73cc..bc80560 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.4.2-dev +1.5.0 diff --git a/consumer/nf_management.go b/consumer/nf_management.go index 1cdd68c..24074c4 100644 --- a/consumer/nf_management.go +++ b/consumer/nf_management.go @@ -13,7 +13,6 @@ package consumer import ( "context" - "fmt" "net/http" "strings" "time" @@ -53,7 +52,6 @@ var SendRegisterNFInstance = func(nrfUri, nfInstanceId string, profile models.Nf for { prof, res, err = apiClient.NFInstanceIDDocumentApi.RegisterNFInstance(context.TODO(), nfInstanceId, profile) if err != nil || res == nil { - // TODO : add log logger.ConsumerLog.Errorf("NSSF register to NRF Error[%s]", err.Error()) time.Sleep(waitTime * time.Second) continue @@ -74,14 +72,14 @@ var SendRegisterNFInstance = func(nrfUri, nfInstanceId string, profile models.Nf retrieveNfInstanceId = resourceUri[strings.LastIndex(resourceUri, "/")+1:] break } else { - fmt.Println("NRF return wrong status code", status) + logger.ConsumerLog.Errorln("NRF return wrong status code", status) } } return prof, resourceNrfUri, retrieveNfInstanceId, err } 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") nssfSelf := nssf_context.NSSF_Self() configuration := Nnrf_NFManagement.NewConfiguration() @@ -111,7 +109,7 @@ var SendUpdateNFInstance = func(patchItem []models.PatchItem) (nfProfile models. } func SendDeregisterNFInstance() (*models.ProblemDetails, error) { - logger.AppLog.Infof("Send Deregister NFInstance") + logger.AppLog.Infoln("send Deregister NFInstance") nssfSelf := nssf_context.NSSF_Self() // Set client and set url diff --git a/factory/config.go b/factory/config.go index b7c9e9d..da7ac8b 100644 --- a/factory/config.go +++ b/factory/config.go @@ -16,7 +16,7 @@ import ( protos "github.com/omec-project/config5g/proto/sdcoreConfig" "github.com/omec-project/nssf/logger" "github.com/omec-project/openapi/models" - logger_util "github.com/omec-project/util/logger" + utilLogger "github.com/omec-project/util/logger" ) const ( @@ -24,10 +24,10 @@ const ( ) type Config struct { - Info *Info `yaml:"info"` - Configuration *Configuration `yaml:"configuration"` - Logger *logger_util.Logger `yaml:"logger"` - Subscriptions []Subscription `yaml:"subscriptions,omitempty"` + Info *Info `yaml:"info"` + Configuration *Configuration `yaml:"configuration"` + Logger *utilLogger.Logger `yaml:"logger"` + Subscriptions []Subscription `yaml:"subscriptions,omitempty"` } type Info struct { diff --git a/factory/nssf_config_test.go b/factory/nssf_config_test.go index 0815258..e45c1a6 100644 --- a/factory/nssf_config_test.go +++ b/factory/nssf_config_test.go @@ -7,7 +7,6 @@ package factory import ( - "fmt" "testing" "github.com/stretchr/testify/assert" @@ -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("../test/conf/test_nssf_config.yaml"); err != nil { - fmt.Printf("Error in InitConfigFactory: %v\n", err) + t.Logf("error in InitConfigFactory: %v", err) } got := NssfConfig.Configuration.WebuiUri want := "webui:9876" @@ -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("../test/conf/test_nssf_config_with_custom_webui_url.yaml"); err != nil { - fmt.Printf("Error in InitConfigFactory: %v\n", err) + t.Logf("error in InitConfigFactory: %v", err) } got := NssfConfig.Configuration.WebuiUri want := "myspecialwebui:9872" diff --git a/go.mod b/go.mod index f3c3c99..6c25e72 100644 --- a/go.mod +++ b/go.mod @@ -3,17 +3,16 @@ module github.com/omec-project/nssf 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/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.uber.org/zap v1.27.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -55,7 +54,6 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // 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 diff --git a/go.sum b/go.sum index d7266da..e71e61c 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,6 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UMEoHck02Q9L0FP13b/xSbQ= -github.com/antonfisher/nested-logrus-formatter v1.3.1/go.mod h1:6WTfyWFkBc9+zyBaKIqRrg/KwMqBbodBjgbHjDz7zjA= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -82,8 +80,8 @@ github.com/omec-project/config5g v1.5.0 h1:VC7uHIdg4S4F5onYvpFfaEAFBttWwWh6OSnNn github.com/omec-project/config5g v1.5.0/go.mod h1:yTjqsOjy8KQ8o4AlnPeZfP32CEvlm0kug3bMwZ3IDOQ= github.com/omec-project/openapi v1.3.1 h1:NCteMRdMtWnMhf1CXYduuLgeu8fEhc/7XO1CiE7fN3Y= github.com/omec-project/openapi v1.3.1/go.mod h1:cR6Iharp2TLOzEmskQ/EdCVFZnpKh0zTvUSSuyXAYLE= -github.com/omec-project/util v1.1.0 h1:TUuLmzqTLChIEXQlK9g5Ihgmw4FUm/UJnjfu0wT8Gz0= -github.com/omec-project/util v1.1.0/go.mod h1:BEv8nCokB4j0fgAQ6VVkKuQ2PSP3DJMEmz25pFMw5X8= +github.com/omec-project/util v1.2.1 h1:+o5kbnZzKBmbqT4oprVGPgL0jH5b8BvRMfLye5srGQ4= +github.com/omec-project/util v1.2.1/go.mod h1:kUF2LXhmtw+m7Bk5IGOMFLj7CA8VKtilLI/9QBJcfxE= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -102,8 +100,6 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -137,7 +133,6 @@ golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= diff --git a/logger/logger.go b/logger/logger.go index 63e5146..6a31ae7 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -1,64 +1,79 @@ +// SPDX-FileCopyrightText: 2024 Intel Corporation // SPDX-FileCopyrightText: 2021 Open Networking Foundation // Copyright 2019 free5GC.org // // SPDX-License-Identifier: Apache-2.0 -// package logger import ( - "time" - - formatter "github.com/antonfisher/nested-logrus-formatter" - "github.com/sirupsen/logrus" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" ) var ( - log *logrus.Logger - AppLog *logrus.Entry - CfgLog *logrus.Entry - ContextLog *logrus.Entry - FactoryLog *logrus.Entry - HandlerLog *logrus.Entry - InitLog *logrus.Entry - Nsselection *logrus.Entry - Nssaiavailability *logrus.Entry - Util *logrus.Entry - ConsumerLog *logrus.Entry - GinLog *logrus.Entry - GrpcLog *logrus.Entry + log *zap.Logger + AppLog *zap.SugaredLogger + CfgLog *zap.SugaredLogger + ContextLog *zap.SugaredLogger + FactoryLog *zap.SugaredLogger + HandlerLog *zap.SugaredLogger + InitLog *zap.SugaredLogger + Nsselection *zap.SugaredLogger + Nssaiavailability *zap.SugaredLogger + Util *zap.SugaredLogger + ConsumerLog *zap.SugaredLogger + GinLog *zap.SugaredLogger + GrpcLog *zap.SugaredLogger + atomicLevel zap.AtomicLevel ) func init() { - log = logrus.New() - log.SetReportCaller(false) + atomicLevel = zap.NewAtomicLevelAt(zap.InfoLevel) + config := zap.Config{ + Level: atomicLevel, + Development: false, + Encoding: "console", + EncoderConfig: zap.NewProductionEncoderConfig(), + OutputPaths: []string{"stdout"}, + ErrorOutputPaths: []string{"stderr"}, + } + + config.EncoderConfig.TimeKey = "timestamp" + config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder + config.EncoderConfig.LevelKey = "level" + config.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder + config.EncoderConfig.CallerKey = "caller" + config.EncoderConfig.EncodeCaller = zapcore.ShortCallerEncoder + config.EncoderConfig.MessageKey = "message" + config.EncoderConfig.StacktraceKey = "" - log.Formatter = &formatter.Formatter{ - TimestampFormat: time.RFC3339, - TrimMessages: true, - NoFieldsSpace: true, - HideKeys: true, - FieldsOrder: []string{"component", "category"}, + var err error + log, err = config.Build() + if err != nil { + panic(err) } - AppLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "App"}) - ContextLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "CTX"}) - FactoryLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "Factory"}) - HandlerLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "HDLR"}) - InitLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "Init"}) - CfgLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "CFG"}) - Nsselection = log.WithFields(logrus.Fields{"component": "NSSF", "category": "NsSelect"}) - Nssaiavailability = log.WithFields(logrus.Fields{"component": "NSSF", "category": "NssaiAvail"}) - Util = log.WithFields(logrus.Fields{"component": "NSSF", "category": "Util"}) - ConsumerLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "Consumer"}) - GinLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "GIN"}) - GrpcLog = log.WithFields(logrus.Fields{"component": "NSSF", "category": "GRPC"}) + AppLog = log.Sugar().With("component", "NSSF", "category", "App") + ContextLog = log.Sugar().With("component", "NSSF", "category", "CTX") + FactoryLog = log.Sugar().With("component", "NSSF", "category", "Factory") + HandlerLog = log.Sugar().With("component", "NSSF", "category", "HDLR") + InitLog = log.Sugar().With("component", "NSSF", "category", "Init") + CfgLog = log.Sugar().With("component", "NSSF", "category", "CFG") + Nsselection = log.Sugar().With("component", "NSSF", "category", "NsSelect") + Nssaiavailability = log.Sugar().With("component", "NSSF", "category", "NssaiAvail") + Util = log.Sugar().With("component", "NSSF", "category", "Util") + ConsumerLog = log.Sugar().With("component", "NSSF", "category", "Consumer") + GinLog = log.Sugar().With("component", "NSSF", "category", "GIN") + GrpcLog = log.Sugar().With("component", "NSSF", "category", "GRPC") } -func SetLogLevel(level logrus.Level) { - log.SetLevel(level) +func GetLogger() *zap.Logger { + return log } -func SetReportCaller(set bool) { - log.SetReportCaller(set) +// SetLogLevel: set the log level (panic|fatal|error|warn|info|debug) +func SetLogLevel(level zapcore.Level) { + InitLog.Infoln("set log level:", level) + atomicLevel.SetLevel(level) } diff --git a/nssaiavailability/routers.go b/nssaiavailability/routers.go index d35f450..24bf833 100644 --- a/nssaiavailability/routers.go +++ b/nssaiavailability/routers.go @@ -20,7 +20,7 @@ import ( "github.com/gin-gonic/gin" - logger_util "github.com/omec-project/util/logger" + utilLogger "github.com/omec-project/util/logger" "github.com/omec-project/nssf/logger" ) @@ -41,7 +41,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 } diff --git a/nsselection/routers.go b/nsselection/routers.go index 51068b9..2227b12 100644 --- a/nsselection/routers.go +++ b/nsselection/routers.go @@ -20,7 +20,7 @@ import ( "github.com/gin-gonic/gin" - logger_util "github.com/omec-project/util/logger" + utilLogger "github.com/omec-project/util/logger" "github.com/omec-project/nssf/logger" ) @@ -41,7 +41,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 } diff --git a/nssf.go b/nssf.go index 2f4f89d..7316abb 100644 --- a/nssf.go +++ b/nssf.go @@ -20,13 +20,13 @@ import ( "github.com/omec-project/nssf/logger" "github.com/omec-project/nssf/service" - "github.com/sirupsen/logrus" "github.com/urfave/cli" + "go.uber.org/zap" ) var NSSF = &service.NSSF{} -var appLog *logrus.Entry +var appLog *zap.SugaredLogger func init() { appLog = logger.AppLog @@ -35,7 +35,7 @@ func init() { func main() { app := cli.NewApp() app.Name = "nssf" - fmt.Print(app.Name, "\n") + appLog.Infoln(app.Name) app.Usage = "-free5gccfg common configuration file -nssfcfg nssf configuration file" app.Action = action app.Flags = NSSF.GetCliCmd() diff --git a/service/init.go b/service/init.go index 2b70fa4..77685cd 100644 --- a/service/init.go +++ b/service/init.go @@ -30,11 +30,11 @@ import ( "github.com/omec-project/nssf/util" "github.com/omec-project/openapi/models" "github.com/omec-project/util/http2_util" - logger_util "github.com/omec-project/util/logger" + utilLogger "github.com/omec-project/util/logger" "github.com/omec-project/util/path_util" - pathUtilLogger "github.com/omec-project/util/path_util/logger" - "github.com/sirupsen/logrus" "github.com/urfave/cli" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" ) type NSSF struct{} @@ -59,7 +59,7 @@ var nssfCLi = []cli.Flag{ }, } -var initLog *logrus.Entry +var initLog *zap.SugaredLogger var ( KeepAliveTimer *time.Timer @@ -103,41 +103,24 @@ func (nssf *NSSF) Initialize(c *cli.Context) error { func (nssf *NSSF) setLogLevel() { if factory.NssfConfig.Logger == nil { - initLog.Warnln("NSSF config without log level setting!!!") + initLog.Warnln("NSSF config without log level setting") return } if factory.NssfConfig.Logger.NSSF != nil { if factory.NssfConfig.Logger.NSSF.DebugLevel != "" { - if level, err := logrus.ParseLevel(factory.NssfConfig.Logger.NSSF.DebugLevel); err != nil { + if level, err := zapcore.ParseLevel(factory.NssfConfig.Logger.NSSF.DebugLevel); err != nil { initLog.Warnf("NSSF Log level [%s] is invalid, set to [info] level", factory.NssfConfig.Logger.NSSF.DebugLevel) - logger.SetLogLevel(logrus.InfoLevel) + logger.SetLogLevel(zap.InfoLevel) } else { initLog.Infof("NSSF Log level is set to [%s] level", level) logger.SetLogLevel(level) } } else { initLog.Infoln("NSSF Log level not set. Default set to [info] level") - logger.SetLogLevel(logrus.InfoLevel) + logger.SetLogLevel(zap.InfoLevel) } - logger.SetReportCaller(factory.NssfConfig.Logger.NSSF.ReportCaller) - } - - if factory.NssfConfig.Logger.PathUtil != nil { - if factory.NssfConfig.Logger.PathUtil.DebugLevel != "" { - if level, err := logrus.ParseLevel(factory.NssfConfig.Logger.PathUtil.DebugLevel); err != nil { - pathUtilLogger.PathLog.Warnf("PathUtil Log level [%s] is invalid, set to [info] level", - factory.NssfConfig.Logger.PathUtil.DebugLevel) - pathUtilLogger.SetLogLevel(logrus.InfoLevel) - } else { - pathUtilLogger.SetLogLevel(level) - } - } else { - pathUtilLogger.PathLog.Warnln("PathUtil Log level not set. Default set to [info] level") - pathUtilLogger.SetLogLevel(logrus.InfoLevel) - } - pathUtilLogger.SetReportCaller(factory.NssfConfig.Logger.PathUtil.ReportCaller) } } @@ -155,9 +138,9 @@ func (nssf *NSSF) FilterCli(c *cli.Context) (args []string) { } func (nssf *NSSF) Start() { - initLog.Infoln("Server started") + initLog.Infoln("server started") - router := logger_util.NewGinWithLogrus(logger.GinLog) + router := utilLogger.NewGinWithZap(logger.GinLog) nssaiavailability.AddService(router) nsselection.AddService(router) @@ -180,12 +163,12 @@ func (nssf *NSSF) Start() { server, err := http2_util.NewServer(addr, util.NSSF_LOG_PATH, router) if server == nil { - initLog.Errorf("Initialize HTTP server failed: %+v", err) + initLog.Errorf("initialize HTTP server failed: %+v", err) return } if err != nil { - initLog.Warnf("Initialize HTTP server: +%v", err) + initLog.Warnf("initialize HTTP server: +%v", err) } serverScheme := factory.NssfConfig.Configuration.Sbi.Scheme @@ -201,9 +184,9 @@ func (nssf *NSSF) Start() { } func (nssf *NSSF) Exec(c *cli.Context) error { - initLog.Traceln("args:", c.String("nssfcfg")) + initLog.Debugln("args:", c.String("nssfcfg")) args := nssf.FilterCli(c) - initLog.Traceln("filter: ", args) + initLog.Debugln("filter:", args) command := exec.Command("./nssf", args...) stdout, err := command.StdoutPipe() @@ -216,7 +199,7 @@ func (nssf *NSSF) Exec(c *cli.Context) error { go func() { in := bufio.NewScanner(stdout) for in.Scan() { - fmt.Println(in.Text()) + initLog.Infoln(in.Text()) } wg.Done() }() @@ -228,14 +211,14 @@ func (nssf *NSSF) Exec(c *cli.Context) error { go func() { in := bufio.NewScanner(stderr) for in.Scan() { - fmt.Println(in.Text()) + initLog.Infoln(in.Text()) } wg.Done() }() go func() { if err = command.Start(); err != nil { - fmt.Printf("NSSF Start error: %v", err) + initLog.Errorf("NSSF Start error: %v", err) } wg.Done() }() @@ -246,18 +229,18 @@ func (nssf *NSSF) Exec(c *cli.Context) error { } func (nssf *NSSF) Terminate() { - logger.InitLog.Infof("Terminating NSSF...") + logger.InitLog.Infoln("terminating NSSF...") // deregister with NRF problemDetails, err := consumer.SendDeregisterNFInstance() if problemDetails != nil { - logger.InitLog.Errorf("Deregister NF instance Failed Problem[%+v]", problemDetails) + logger.InitLog.Errorf("deregister NF instance Failed Problem[%+v]", problemDetails) } else if err != nil { - logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err) + logger.InitLog.Errorf("deregister NF instance Error[%+v]", err) } else { - logger.InitLog.Infof("Deregister from NRF successfully") + logger.InitLog.Infoln("deregister from NRF successfully") } - logger.InitLog.Infof("NSSF terminated") + logger.InitLog.Infoln("NSSF terminated") } func (nssf *NSSF) StartKeepAliveTimer(nfProfile models.NfProfile) { @@ -267,14 +250,14 @@ func (nssf *NSSF) StartKeepAliveTimer(nfProfile models.NfProfile) { if nfProfile.HeartBeatTimer == 0 { nfProfile.HeartBeatTimer = 60 } - logger.InitLog.Infof("Started KeepAlive Timer: %v sec", nfProfile.HeartBeatTimer) + logger.InitLog.Infof("started KeepAlive Timer: %v sec", nfProfile.HeartBeatTimer) // AfterFunc starts timer and waits for KeepAliveTimer to elapse and then calls nssf.UpdateNF function KeepAliveTimer = time.AfterFunc(time.Duration(nfProfile.HeartBeatTimer)*time.Second, nssf.UpdateNF) } func (nssf *NSSF) StopKeepAliveTimer() { if KeepAliveTimer != nil { - logger.InitLog.Infof("Stopped KeepAlive Timer.") + logger.InitLog.Infoln("stopped KeepAlive Timer") KeepAliveTimer.Stop() KeepAliveTimer = nil } @@ -284,7 +267,7 @@ func (nssf *NSSF) BuildAndSendRegisterNFInstance() (models.NfProfile, error) { self := context.NSSF_Self() profile, err := consumer.BuildNFProfile(self) if err != nil { - initLog.Errorf("Build NSSF Profile Error: %v", err) + initLog.Errorf("build NSSF Profile Error: %v", err) return profile, err } initLog.Infof("Pcf Profile Registering to NRF: %v", profile) @@ -298,7 +281,7 @@ func (nssf *NSSF) UpdateNF() { KeepAliveTimerMutex.Lock() defer KeepAliveTimerMutex.Unlock() if KeepAliveTimer == nil { - initLog.Warnf("KeepAlive timer has been stopped.") + initLog.Warnln("keepAlive timer has been stopped") return } // setting default value 60 sec @@ -334,7 +317,7 @@ func (nssf *NSSF) UpdateNF() { // use hearbeattimer value with received timer value from NRF heartBeatTimer = nfProfile.HeartBeatTimer } - logger.InitLog.Debugf("Restarted KeepAlive Timer: %v sec", heartBeatTimer) + logger.InitLog.Debugf("restarted KeepAlive Timer: %v sec", heartBeatTimer) // restart timer with received HeartBeatTimer value KeepAliveTimer = time.AfterFunc(time.Duration(heartBeatTimer)*time.Second, nssf.UpdateNF) } @@ -345,7 +328,7 @@ func (nssf *NSSF) registerNF() { self := context.NSSF_Self() profile, err := consumer.BuildNFProfile(self) if err != nil { - logger.InitLog.Errorf("Build profile failed.") + logger.InitLog.Errorln("build profile failed") } var newNrfUri string @@ -354,10 +337,10 @@ func (nssf *NSSF) registerNF() { prof, newNrfUri, self.NfId, err = consumer.SendRegisterNFInstance(self.NrfUri, profile.NfInstanceId, profile) if err == nil { nssf.StartKeepAliveTimer(prof) - logger.CfgLog.Infof("Sent Register NF Instance with updated profile") + logger.CfgLog.Infoln("sent register NFInstance with updated profile") self.NrfUri = newNrfUri } else { - initLog.Errorf("Send Register NFInstance Error[%s]", err.Error()) + initLog.Errorf("send register NFInstance Error[%s]", err.Error()) } } }