-
Notifications
You must be signed in to change notification settings - Fork 111
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 (#95)
- Loading branch information
1 parent
60e861e
commit 7907d3c
Showing
66 changed files
with
4,483 additions
and
2,244 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,87 +1,95 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"runtime/debug" | ||
|
||
"github.com/asaskevich/govalidator" | ||
"github.com/urfave/cli" | ||
|
||
"github.com/free5gc/amf/internal/logger" | ||
"github.com/free5gc/amf/internal/util" | ||
"github.com/free5gc/amf/pkg/factory" | ||
"github.com/free5gc/amf/pkg/service" | ||
logger_util "github.com/free5gc/util/logger" | ||
"github.com/free5gc/util/version" | ||
) | ||
|
||
var AMF = &service.AMF{} | ||
var AMF *service.AmfApp | ||
|
||
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 = "amf" | ||
app.Usage = "5G Access and Mobility Management Function (AMF)" | ||
app.Action = action | ||
app.Flags = AMF.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 { | ||
logger.AppLog.Errorf("AMF Run error: %v\n", err) | ||
logger.MainLog.Errorf("AMF Run error: %v\n", err) | ||
return | ||
} | ||
} | ||
|
||
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 := AMF.Initialize(c); err != nil { | ||
switch err1 := err.(type) { | ||
case govalidator.Errors: | ||
errs := err1.Errors() | ||
for _, e := range errs { | ||
logger.CfgLog.Errorf("%+v", e) | ||
} | ||
default: | ||
logger.CfgLog.Errorf("%+v", err) | ||
} | ||
logger.MainLog.Infoln("AMF version: ", version.GetVersion()) | ||
|
||
logger.CfgLog.Errorf("[-- PLEASE REFER TO SAMPLE CONFIG FILE COMMENTS --]") | ||
return fmt.Errorf("Failed to initialize !!") | ||
cfg, err := factory.ReadConfig(cliCtx.String("config")) | ||
if err != nil { | ||
return err | ||
} | ||
factory.AmfConfig = cfg | ||
|
||
logger.AppLog.Infoln(c.App.Name) | ||
logger.AppLog.Infoln("AMF version: ", version.GetVersion()) | ||
amf, err := service.NewApp(cfg) | ||
if err != nil { | ||
return err | ||
} | ||
AMF = amf | ||
|
||
AMF.Start() | ||
amf.Start(tlsKeyLogPath) | ||
|
||
return nil | ||
} | ||
|
||
func initLogFile(logNfPath, log5gcPath string) error { | ||
AMF.KeyLogPath = util.AmfDefaultKeyLogPath | ||
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.AmfDefaultKeyLogPath) | ||
AMF.KeyLogPath = filepath.Join(tmpDir, name) | ||
_, name := filepath.Split(factory.AmfDefaultTLSKeyLogPath) | ||
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,24 +1,68 @@ | ||
module github.com/free5gc/amf | ||
|
||
go 1.14 | ||
go 1.17 | ||
|
||
require ( | ||
git.cs.nctu.edu.tw/calee/sctp v1.1.0 | ||
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.1.1 | ||
github.com/free5gc/ngap v1.0.6 | ||
github.com/free5gc/openapi v1.0.6 | ||
github.com/free5gc/util v1.0.3 | ||
github.com/free5gc/util v1.0.5-0.20230306071612-a52909216bd2 | ||
github.com/gin-contrib/cors v1.3.1 | ||
github.com/gin-gonic/gin v1.9.0 | ||
github.com/google/uuid v1.3.0 | ||
github.com/mitchellh/mapstructure v1.4.1 | ||
github.com/mitchellh/mapstructure v1.4.2 | ||
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.8.1 | ||
github.com/urfave/cli v1.22.5 | ||
gopkg.in/yaml.v2 v2.4.0 | ||
) | ||
|
||
require ( | ||
github.com/aead/cmac v0.0.0-20160719120800-7af84192f0b1 // indirect | ||
github.com/antonfisher/nested-logrus-formatter v1.3.1 // indirect | ||
github.com/bytedance/sonic v1.8.0 // indirect | ||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect | ||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect | ||
github.com/gin-contrib/sse v0.1.0 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.11.2 // indirect | ||
github.com/goccy/go-json v0.10.0 // indirect | ||
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect | ||
github.com/golang/protobuf v1.5.0 // 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.12 // indirect | ||
github.com/jtolds/gls v4.20.0+incompatible // indirect | ||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect | ||
github.com/leodido/go-urn v1.2.1 // indirect | ||
github.com/mattn/go-isatty v0.0.17 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.6 // 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/twitchyliquid64/golang-asm v0.15.1 // indirect | ||
github.com/ugorji/go/codec v1.2.9 // indirect | ||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect | ||
golang.org/x/crypto v0.5.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.28.1 // indirect | ||
gopkg.in/h2non/gock.v1 v1.1.2 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
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
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
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
Oops, something went wrong.