-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and update util to use new log formatter setting
- Loading branch information
1 parent
8819543
commit 50b29b8
Showing
23 changed files
with
1,849 additions
and
826 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,91 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime/debug" | ||
|
||
"github.com/asaskevich/govalidator" | ||
"github.com/urfave/cli" | ||
|
||
"github.com/free5gc/udr/internal/logger" | ||
"github.com/free5gc/udr/internal/util" | ||
udr_service "github.com/free5gc/udr/pkg/service" | ||
"github.com/free5gc/udr/pkg/factory" | ||
"github.com/free5gc/udr/pkg/service" | ||
logger_util "github.com/free5gc/util/logger" | ||
"github.com/free5gc/util/version" | ||
) | ||
|
||
var UDR = &udr_service.UDR{} | ||
var UDR *service.UdrApp | ||
|
||
func main() { | ||
defer func() { | ||
if p := recover(); p != nil { | ||
// Print stack for panic to log. Fatalf() will let program exit. | ||
logger.AppLog.Fatalf("panic: %v\n%s", p, string(debug.Stack())) | ||
logger.MainLog.Fatalf("panic: %v\n%s", p, string(debug.Stack())) | ||
} | ||
}() | ||
|
||
app := cli.NewApp() | ||
app.Name = "udr" | ||
app.Usage = "5G Unified Data Repository (UDR)" | ||
app.Action = action | ||
app.Flags = UDR.GetCliCmd() | ||
app.Flags = []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "config, c", | ||
Usage: "Load configuration from `FILE`", | ||
}, | ||
cli.StringSliceFlag{ | ||
Name: "log, l", | ||
Usage: "Output NF log to `FILE`", | ||
}, | ||
} | ||
if err := app.Run(os.Args); err != nil { | ||
fmt.Printf("UDR Run error: %v\n", err) | ||
logger.MainLog.Errorf("UDR Run error: %v\n", err) | ||
} | ||
} | ||
|
||
func action(c *cli.Context) error { | ||
if err := initLogFile(c.String("log"), c.String("log5gc")); err != nil { | ||
logger.AppLog.Errorf("%+v", err) | ||
func action(cliCtx *cli.Context) error { | ||
tlsKeyLogPath, err := initLogFile(cliCtx.StringSlice("log")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := UDR.Initialize(c); err != nil { | ||
switch errType := err.(type) { | ||
case govalidator.Errors: | ||
validErrs := err.(govalidator.Errors).Errors() | ||
for _, validErr := range validErrs { | ||
logger.CfgLog.Errorf("%+v", validErr) | ||
} | ||
default: | ||
logger.CfgLog.Errorf("%+v", errType) | ||
} | ||
logger.CfgLog.Errorf("[-- PLEASE REFER TO SAMPLE CONFIG FILE COMMENTS --]") | ||
return fmt.Errorf("Failed to initialize !!") | ||
logger.MainLog.Infoln("UDR version: ", version.GetVersion()) | ||
cfg, err := factory.ReadConfig(cliCtx.String("config")) | ||
if err != nil { | ||
return err | ||
} | ||
factory.UdrConfig = cfg | ||
udr, err := service.NewApp(cfg) | ||
if err != nil { | ||
return err | ||
} | ||
UDR = udr | ||
|
||
logger.AppLog.Infoln(c.App.Name) | ||
logger.AppLog.Infoln("UDR version: ", version.GetVersion()) | ||
|
||
UDR.Start() | ||
udr.Start(tlsKeyLogPath) | ||
|
||
return nil | ||
} | ||
|
||
func initLogFile(logNfPath, log5gcPath string) error { | ||
UDR.KeyLogPath = util.UdrDefaultKeyLogPath | ||
func initLogFile(logNfPath []string) (string, error) { | ||
logTlsKeyPath := "" | ||
|
||
if err := logger.LogFileHook(logNfPath, log5gcPath); err != nil { | ||
return err | ||
} | ||
for _, path := range logNfPath { | ||
if err := logger_util.LogFileHook(logger.Log, path); err != nil { | ||
return "", err | ||
} | ||
if logTlsKeyPath != "" { | ||
continue | ||
} | ||
|
||
if logNfPath != "" { | ||
nfDir, _ := filepath.Split(logNfPath) | ||
nfDir, _ := filepath.Split(path) | ||
tmpDir := filepath.Join(nfDir, "key") | ||
if err := os.MkdirAll(tmpDir, 0o775); err != nil { | ||
logger.InitLog.Errorf("Make directory %s failed: %+v", tmpDir, err) | ||
return err | ||
return "", err | ||
} | ||
_, name := filepath.Split(util.UdrDefaultKeyLogPath) | ||
UDR.KeyLogPath = filepath.Join(tmpDir, name) | ||
_, name := filepath.Split(factory.UdrDefaultTLSKeyLogPath) | ||
logTlsKeyPath = filepath.Join(tmpDir, name) | ||
} | ||
|
||
return nil | ||
return logTlsKeyPath, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,61 @@ | ||
module github.com/free5gc/udr | ||
|
||
go 1.14 | ||
go 1.17 | ||
|
||
require ( | ||
github.com/antonfisher/nested-logrus-formatter v1.3.1 | ||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d | ||
github.com/evanphx/json-patch v0.5.2 | ||
github.com/free5gc/openapi v1.0.4 | ||
github.com/free5gc/util v1.0.3 | ||
github.com/free5gc/openapi v1.0.6 | ||
github.com/free5gc/util v1.0.5-0.20230306071612-a52909216bd2 | ||
github.com/gin-gonic/gin v1.7.7 | ||
github.com/google/uuid v1.3.0 | ||
github.com/mitchellh/mapstructure v1.4.1 | ||
github.com/mitchellh/mapstructure v1.4.3 | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/stretchr/testify v1.8.0 | ||
github.com/urfave/cli v1.22.5 | ||
go.mongodb.org/mongo-driver v1.8.4 | ||
gopkg.in/yaml.v2 v2.4.0 | ||
) | ||
|
||
require ( | ||
github.com/antihax/optional v1.0.0 // indirect | ||
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.13.0 // indirect | ||
github.com/go-playground/universal-translator v0.17.0 // indirect | ||
github.com/go-playground/validator/v10 v10.4.1 // indirect | ||
github.com/go-stack/stack v1.8.0 // indirect | ||
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/golang/snappy v0.0.1 // indirect | ||
github.com/google/go-cmp v0.5.6 // indirect | ||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/klauspost/compress v1.13.6 // indirect | ||
github.com/kr/pretty v0.2.0 // indirect | ||
github.com/leodido/go-urn v1.2.0 // indirect | ||
github.com/mattn/go-isatty v0.0.14 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect | ||
github.com/ugorji/go/codec v1.1.7 // indirect | ||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect | ||
github.com/xdg-go/scram v1.0.2 // indirect | ||
github.com/xdg-go/stringprep v1.0.2 // indirect | ||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect | ||
golang.org/x/crypto v0.1.0 // indirect | ||
golang.org/x/net v0.7.0 // indirect | ||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect | ||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect | ||
golang.org/x/sys v0.5.0 // indirect | ||
golang.org/x/text v0.7.0 // indirect | ||
google.golang.org/appengine v1.6.7 // indirect | ||
google.golang.org/protobuf v1.27.1 // indirect | ||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | ||
gopkg.in/h2non/gock.v1 v1.1.2 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.