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 (#73)
* refactor and update util to use new log formatter setting * remove old files
- Loading branch information
1 parent
73bb01d
commit 3d1c7f1
Showing
66 changed files
with
7,463 additions
and
2,249 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,89 +1,102 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"os" | ||
"path/filepath" | ||
"runtime/debug" | ||
"time" | ||
|
||
"github.com/asaskevich/govalidator" | ||
"github.com/urfave/cli" | ||
|
||
"github.com/free5gc/smf/internal/logger" | ||
"github.com/free5gc/smf/internal/util" | ||
"github.com/free5gc/smf/pkg/factory" | ||
"github.com/free5gc/smf/pkg/service" | ||
logger_util "github.com/free5gc/util/logger" | ||
"github.com/free5gc/util/version" | ||
) | ||
|
||
var SMF = &service.SMF{} | ||
var SMF *service.SmfApp | ||
|
||
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 = "smf" | ||
app.Usage = "5G Session Management Function (SMF)" | ||
app.Action = action | ||
app.Flags = SMF.GetCliCmd() | ||
app.Flags = []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "config, c", | ||
Usage: "Load configuration from `FILE`", | ||
}, | ||
cli.StringFlag{ | ||
Name: "uerouting, u", | ||
Usage: "Load uerouting configuration from `FILE`", | ||
}, | ||
cli.StringSliceFlag{ | ||
Name: "log, l", | ||
Usage: "Output NF log to `FILE`", | ||
}, | ||
} | ||
rand.Seed(time.Now().UnixNano()) | ||
|
||
if err := app.Run(os.Args); err != nil { | ||
logger.AppLog.Errorf("SMF Run error: %v\n", err) | ||
logger.MainLog.Errorf("SMF 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 := SMF.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("SMF version: ", version.GetVersion()) | ||
|
||
cfg, err := factory.ReadConfig(cliCtx.String("config")) | ||
if err != nil { | ||
return err | ||
} | ||
factory.SmfConfig = cfg | ||
|
||
logger.AppLog.Infoln(c.App.Name) | ||
logger.AppLog.Infoln("SMF version: ", version.GetVersion()) | ||
smf, err := service.NewApp(cfg) | ||
if err != nil { | ||
return err | ||
} | ||
SMF = smf | ||
|
||
SMF.Start() | ||
smf.Start(tlsKeyLogPath) | ||
|
||
return nil | ||
} | ||
|
||
func initLogFile(logNfPath, log5gcPath string) error { | ||
SMF.KeyLogPath = util.SmfDefaultKeyLogPath | ||
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.SmfDefaultKeyLogPath) | ||
SMF.KeyLogPath = filepath.Join(tmpDir, name) | ||
_, name := filepath.Split(factory.SmfDefaultTLSKeyLogPath) | ||
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,23 +1,61 @@ | ||
module github.com/free5gc/smf | ||
|
||
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/davecgh/go-spew v1.1.1 | ||
github.com/free5gc/aper v1.0.4 | ||
github.com/free5gc/nas v1.0.7 | ||
github.com/free5gc/nas v1.1.0 | ||
github.com/free5gc/ngap v1.0.6 | ||
github.com/free5gc/openapi v1.0.5 | ||
github.com/free5gc/pfcp v1.0.6-0.20221213042804-fe871d6967c2 | ||
github.com/free5gc/util v1.0.3 | ||
github.com/free5gc/openapi v1.0.6 | ||
github.com/free5gc/pfcp 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/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 | ||
github.com/pkg/errors v0.9.1 | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/smartystreets/goconvey v1.6.4 | ||
github.com/stretchr/testify v1.7.0 | ||
github.com/urfave/cli v1.22.5 | ||
gopkg.in/h2non/gock.v1 v1.1.2 | ||
gopkg.in/yaml.v2 v2.4.0 | ||
) | ||
|
||
require ( | ||
github.com/antonfisher/nested-logrus-formatter v1.3.1 // indirect | ||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect | ||
github.com/free5gc/tlv v1.0.2-0.20230131124215-8b6ebd69bf93 // 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.4.2 // indirect | ||
github.com/google/go-cmp v0.5.2 // indirect | ||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect | ||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect | ||
github.com/json-iterator/go v1.1.9 // indirect | ||
github.com/jtolds/gls v4.20.0+incompatible // indirect | ||
github.com/leodido/go-urn v1.2.0 // indirect | ||
github.com/mattn/go-isatty v0.0.12 // indirect | ||
github.com/mitchellh/mapstructure v1.4.2 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect | ||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/russross/blackfriday/v2 v2.0.1 // indirect | ||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect | ||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect | ||
github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect | ||
github.com/ugorji/go/codec v1.1.7 // indirect | ||
golang.org/x/crypto v0.1.0 // indirect | ||
golang.org/x/net v0.7.0 // indirect | ||
golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5 // indirect | ||
golang.org/x/sys v0.5.0 // indirect | ||
golang.org/x/text v0.7.0 // indirect | ||
google.golang.org/appengine v1.6.6 // indirect | ||
google.golang.org/protobuf v1.25.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect | ||
) |
Oops, something went wrong.
3d1c7f1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has been mentioned on free5GC. There might be relevant details there:
http://forum.free5gc.org/t/qos-enforcement-implemenation-in-upf-gtp/2009/2