-
Notifications
You must be signed in to change notification settings - Fork 56
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 (#21)
Co-authored-by: brianchennn <[email protected]>
- Loading branch information
1 parent
9004d21
commit a63c83d
Showing
21 changed files
with
500 additions
and
455 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,94 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime/debug" | ||
|
||
"github.com/asaskevich/govalidator" | ||
"github.com/urfave/cli" | ||
|
||
"github.com/free5gc/udm/internal/logger" | ||
"github.com/free5gc/udm/internal/util" | ||
"github.com/free5gc/udm/pkg/factory" | ||
"github.com/free5gc/udm/pkg/service" | ||
logger_util "github.com/free5gc/util/logger" | ||
"github.com/free5gc/util/version" | ||
) | ||
|
||
var UDM = &service.UDM{} | ||
var UDM *service.UdmApp | ||
|
||
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 = "udm" | ||
app.Usage = "5G Unified Data Management (UDM)" | ||
app.Action = action | ||
app.Flags = UDM.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("UDM Run error: %v\n", err) | ||
logger.MainLog.Errorf("UDM 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 := UDM.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("UDM version: ", version.GetVersion()) | ||
|
||
logger.AppLog.Infoln(c.App.Name) | ||
logger.AppLog.Infoln("UDM version: ", version.GetVersion()) | ||
cfg, err := factory.ReadConfig(cliCtx.String("config")) | ||
if err != nil { | ||
return err | ||
} | ||
factory.UdmConfig = cfg | ||
udm, err := service.NewApp(cfg) | ||
if err != nil { | ||
return err | ||
} | ||
UDM = udm | ||
|
||
UDM.Start() | ||
udm.Start(tlsKeyLogPath) | ||
|
||
return nil | ||
} | ||
|
||
func initLogFile(logNfPath, log5gcPath string) error { | ||
UDM.KeyLogPath = util.UdmDefaultKeyLogPath | ||
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 logNfPath != "" { | ||
nfDir, _ := filepath.Split(logNfPath) | ||
if logTlsKeyPath != "" { | ||
continue | ||
} | ||
|
||
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.UdmDefaultKeyLogPath) | ||
UDM.KeyLogPath = filepath.Join(tmpDir, name) | ||
_, name := filepath.Split(factory.UdmDefaultTLSKeyLogPath) | ||
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,17 +1,48 @@ | ||
module github.com/free5gc/udm | ||
|
||
go 1.14 | ||
go 1.17 | ||
|
||
require ( | ||
github.com/antihax/optional v1.0.0 | ||
github.com/antonfisher/nested-logrus-formatter v1.3.1 | ||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d | ||
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/sirupsen/logrus v1.8.1 | ||
github.com/urfave/cli v1.22.5 | ||
golang.org/x/crypto v0.1.0 | ||
gopkg.in/yaml.v2 v2.4.0 | ||
) | ||
|
||
require ( | ||
github.com/cpuguy83/go-md2man/v2 v2.0.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/golang-jwt/jwt v3.2.1+incompatible // indirect | ||
github.com/golang/protobuf v1.5.2 // 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/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/mitchellh/mapstructure v1.4.3 // 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/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/stretchr/testify v1.8.0 // indirect | ||
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect | ||
github.com/ugorji/go/codec v1.1.7 // indirect | ||
golang.org/x/net v0.7.0 // indirect | ||
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // 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 | ||
) |
Oops, something went wrong.