From f8f3f64c54d527bf0e52365e2108900f3d1e8156 Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Mon, 31 Jan 2022 12:09:45 +0800 Subject: [PATCH] [refactor] all demo LogoutStartInfo --- app/demo/analyseflv/analyseflv.go | 1 + app/demo/benchrtmpconnect/benchrtmpconnect.go | 1 + app/demo/calcrtmpdelay/calcrtmpdelay.go | 1 + app/demo/dispatch/dispatch.go | 1 + app/demo/flvfile2es/flvfile2es.go | 1 + app/demo/modflvfile/modflvfile.go | 1 + app/demo/pullhttpflv/pullhttpflv.go | 1 + app/demo/pullrtmp/pullrtmp.go | 1 + app/demo/pullrtmp2hls/pullrtmp2hls.go | 1 + app/demo/pullrtmp2pushrtmp/main.go | 3 ++ .../pullrtmp2pushrtsp/pullrtmp2pushrtsp.go | 1 + app/demo/pullrtsp/pullrtsp.go | 1 + .../pullrtsp2pushrtmp/pullrtsp2pushrtmp.go | 1 + .../pullrtsp2pushrtsp/pullrtsp2pushrtsp.go | 1 + app/demo/pushrtmp/pushrtmp.go | 2 ++ pkg/base/base.go | 34 +++++++++++++++++++ pkg/logic/server_manager.go | 16 ++------- 17 files changed, 54 insertions(+), 14 deletions(-) diff --git a/app/demo/analyseflv/analyseflv.go b/app/demo/analyseflv/analyseflv.go index 6055771..0694956 100644 --- a/app/demo/analyseflv/analyseflv.go +++ b/app/demo/analyseflv/analyseflv.go @@ -77,6 +77,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() url := parseFlag() session := httpflv.NewPullSession() diff --git a/app/demo/benchrtmpconnect/benchrtmpconnect.go b/app/demo/benchrtmpconnect/benchrtmpconnect.go index 6048f12..2318b95 100644 --- a/app/demo/benchrtmpconnect/benchrtmpconnect.go +++ b/app/demo/benchrtmpconnect/benchrtmpconnect.go @@ -28,6 +28,7 @@ func main() { option.Level = nazalog.LevelLogNothing }) defer nazalog.Sync() + base.LogoutStartInfo() urlTmpl, num := parseFlag() urls := collect(urlTmpl, num) diff --git a/app/demo/calcrtmpdelay/calcrtmpdelay.go b/app/demo/calcrtmpdelay/calcrtmpdelay.go index 145da8b..fa51b3a 100644 --- a/app/demo/calcrtmpdelay/calcrtmpdelay.go +++ b/app/demo/calcrtmpdelay/calcrtmpdelay.go @@ -53,6 +53,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() var mu sync.Mutex tagKey2writeTime := make(map[string]time.Time) diff --git a/app/demo/dispatch/dispatch.go b/app/demo/dispatch/dispatch.go index 0cf704b..5a4bcf8 100644 --- a/app/demo/dispatch/dispatch.go +++ b/app/demo/dispatch/dispatch.go @@ -202,6 +202,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() dataManager = datamanager.NewDataManager(datamanager.DmtMemory, config.ServerTimeoutSec) diff --git a/app/demo/flvfile2es/flvfile2es.go b/app/demo/flvfile2es/flvfile2es.go index 74f2ea4..6e40a05 100644 --- a/app/demo/flvfile2es/flvfile2es.go +++ b/app/demo/flvfile2es/flvfile2es.go @@ -31,6 +31,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() var err error flvFileName, aacFileName, avcFileName := parseFlag() diff --git a/app/demo/modflvfile/modflvfile.go b/app/demo/modflvfile/modflvfile.go index 16af23e..59a8bcf 100644 --- a/app/demo/modflvfile/modflvfile.go +++ b/app/demo/modflvfile/modflvfile.go @@ -40,6 +40,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() var err error inFileName, outFileName := parseFlag() diff --git a/app/demo/pullhttpflv/pullhttpflv.go b/app/demo/pullhttpflv/pullhttpflv.go index 7b73f4a..fe6f51b 100644 --- a/app/demo/pullhttpflv/pullhttpflv.go +++ b/app/demo/pullhttpflv/pullhttpflv.go @@ -28,6 +28,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() url := parseFlag() session := httpflv.NewPullSession() diff --git a/app/demo/pullrtmp/pullrtmp.go b/app/demo/pullrtmp/pullrtmp.go index de579bb..bc9b80b 100644 --- a/app/demo/pullrtmp/pullrtmp.go +++ b/app/demo/pullrtmp/pullrtmp.go @@ -52,6 +52,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() urlTmpl, fileNameTmpl, num := parseFlag() nazalog.Infof("parse flag succ. urlTmpl=%s, fileNameTmpl=%s, num=%d", urlTmpl, fileNameTmpl, num) diff --git a/app/demo/pullrtmp2hls/pullrtmp2hls.go b/app/demo/pullrtmp2hls/pullrtmp2hls.go index 45ff419..edf8282 100644 --- a/app/demo/pullrtmp2hls/pullrtmp2hls.go +++ b/app/demo/pullrtmp2hls/pullrtmp2hls.go @@ -25,6 +25,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() url, hlsOutPath, fragmentDurationMs, fragmentNum := parseFlag() nazalog.Infof("parse flag succ. url=%s, hlsOutPath=%s, fragmentDurationMs=%d, fragmentNum=%d", diff --git a/app/demo/pullrtmp2pushrtmp/main.go b/app/demo/pullrtmp2pushrtmp/main.go index 31ff722..b507f98 100644 --- a/app/demo/pullrtmp2pushrtmp/main.go +++ b/app/demo/pullrtmp2pushrtmp/main.go @@ -15,6 +15,8 @@ import ( "strings" "time" + "github.com/q191201771/lal/pkg/base" + "github.com/q191201771/naza/pkg/nazalog" ) @@ -23,6 +25,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() i := flag.String("i", "", "specify pull rtmp url") o := flag.String("o", "", "specify push rtmp url list, separated by a comma") diff --git a/app/demo/pullrtmp2pushrtsp/pullrtmp2pushrtsp.go b/app/demo/pullrtmp2pushrtsp/pullrtmp2pushrtsp.go index 07275c9..567129e 100644 --- a/app/demo/pullrtmp2pushrtsp/pullrtmp2pushrtsp.go +++ b/app/demo/pullrtmp2pushrtsp/pullrtmp2pushrtsp.go @@ -27,6 +27,7 @@ func main() { _ = nazalog.Init(func(option *nazalog.Option) { option.AssertBehavior = nazalog.AssertFatal }) + base.LogoutStartInfo() inRtmpUrl, outRtspUrl, overTcp := parseFlag() diff --git a/app/demo/pullrtsp/pullrtsp.go b/app/demo/pullrtsp/pullrtsp.go index 9269005..2f43071 100644 --- a/app/demo/pullrtsp/pullrtsp.go +++ b/app/demo/pullrtsp/pullrtsp.go @@ -26,6 +26,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() inUrl, outFilename, overTcp := parseFlag() diff --git a/app/demo/pullrtsp2pushrtmp/pullrtsp2pushrtmp.go b/app/demo/pullrtsp2pushrtmp/pullrtsp2pushrtmp.go index c95637b..4f8b191 100644 --- a/app/demo/pullrtsp2pushrtmp/pullrtsp2pushrtmp.go +++ b/app/demo/pullrtsp2pushrtmp/pullrtsp2pushrtmp.go @@ -27,6 +27,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() inUrl, outUrl, overTcp := parseFlag() diff --git a/app/demo/pullrtsp2pushrtsp/pullrtsp2pushrtsp.go b/app/demo/pullrtsp2pushrtsp/pullrtsp2pushrtsp.go index ddb384f..3687e28 100644 --- a/app/demo/pullrtsp2pushrtsp/pullrtsp2pushrtsp.go +++ b/app/demo/pullrtsp2pushrtsp/pullrtsp2pushrtsp.go @@ -163,6 +163,7 @@ func main() { option.AssertBehavior = nazalog.AssertFatal }) defer nazalog.Sync() + base.LogoutStartInfo() inUrl, outUrl, pullOverTcp, pushOverTcp := parseFlag() diff --git a/app/demo/pushrtmp/pushrtmp.go b/app/demo/pushrtmp/pushrtmp.go index 0d8ced3..ef083f8 100644 --- a/app/demo/pushrtmp/pushrtmp.go +++ b/app/demo/pushrtmp/pushrtmp.go @@ -53,6 +53,8 @@ var aliveSessionCount int32 func main() { defer nazalog.Sync() + base.LogoutStartInfo() + filename, urlTmpl, num, isRecursive, logfile := parseFlag() initLog(logfile) diff --git a/pkg/base/base.go b/pkg/base/base.go index 2edc741..9107df9 100644 --- a/pkg/base/base.go +++ b/pkg/base/base.go @@ -8,6 +8,40 @@ package base +import ( + "os" + "strings" + "time" + + "github.com/q191201771/naza/pkg/bininfo" + "github.com/q191201771/naza/pkg/nazalog" +) + // base包提供被其他多个package依赖的基础内容,自身不依赖任何package // // TODO chef: 考虑部分内容放入关联的协议package的子package中 + +var startTime string + +// ReadableNowTime +// +// TODO(chef): refactor 使用ReadableNowTime +// +func ReadableNowTime() string { + return time.Now().Format("2006-01-02 15:04:05.999") +} + +func LogoutStartInfo() { + dir, _ := os.Getwd() + nazalog.Infof(" start: %s", startTime) + nazalog.Infof(" wd: %s", dir) + nazalog.Infof(" args: %s", strings.Join(os.Args, " ")) + nazalog.Infof(" bininfo: %s", bininfo.StringifySingleLine()) + nazalog.Infof(" version: %s", LalFullInfo) + nazalog.Infof(" github: %s", LalGithubSite) + nazalog.Infof(" doc: %s", LalDocSite) +} + +func init() { + startTime = ReadableNowTime() +} diff --git a/pkg/logic/server_manager.go b/pkg/logic/server_manager.go index 2558735..a509162 100644 --- a/pkg/logic/server_manager.go +++ b/pkg/logic/server_manager.go @@ -13,7 +13,6 @@ import ( "math" "net/http" "os" - "strings" "sync" "time" @@ -59,21 +58,12 @@ type ServerManager struct { func NewServerManager(confFile string, modOption ...ModOption) *ServerManager { sm := &ServerManager{ serverStartTime: time.Now().Format("2006-01-02 15:04:05.999"), - exitChan: make(chan struct{}), + exitChan: make(chan struct{}, 1), } sm.groupManager = NewSimpleGroupManager(sm) sm.config = LoadConfAndInitLog(confFile) - - // TODO(chef): refactor 启动信息可以考虑放入package base中,所有的app都打印 - dir, _ := os.Getwd() - nazalog.Infof("wd: %s", dir) - nazalog.Infof("args: %s", strings.Join(os.Args, " ")) - nazalog.Infof("bininfo: %s", bininfo.StringifySingleLine()) - nazalog.Infof("version: %s", base.LalFullInfo) - nazalog.Infof("github: %s", base.LalGithubSite) - nazalog.Infof("doc: %s", base.LalDocSite) - nazalog.Infof("serverStartTime: %s", sm.serverStartTime) + base.LogoutStartInfo() if sm.config.HlsConfig.Enable && sm.config.HlsConfig.UseMemoryAsDiskFlag { nazalog.Infof("hls use memory as disk.") @@ -808,8 +798,6 @@ func (sm *ServerManager) serveHls(writer http.ResponseWriter, req *http.Request) sm.hlsServerHandler.ServeHTTP(writer, req) } -// --------------------------------------------------------------------------------------------------------------------- - func runWebPprof(addr string) { nazalog.Infof("start web pprof listen. addr=%s", addr)