diff --git a/examples/echo/tcp-echo/client/app/client.go b/examples/echo/tcp-echo/client/app/client.go index 230b9f2a..04d72c5b 100644 --- a/examples/echo/tcp-echo/client/app/client.go +++ b/examples/echo/tcp-echo/client/app/client.go @@ -25,13 +25,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) var ( reqID uint32 src = rand.NewSource(time.Now().UnixNano()) + log = getty.GetLogger() ) func init() { @@ -63,7 +63,7 @@ func (c *EchoClient) close() { c.gettyClient.Close() c.gettyClient = nil for _, s := range c.sessions { - log.Info("close client session{%s, last active:%s, request number:%d}", + log.Infof("close client session{%s, last active:%s, request number:%d}", s.session.Stat(), s.session.GetActive().String(), s.reqNum) s.session.Close() } @@ -85,7 +85,7 @@ func (c *EchoClient) selectSession() getty.Session { } func (c *EchoClient) addSession(session getty.Session) { - log.Debug("add session{%s}", session.Stat()) + log.Debugf("add session{%s}", session.Stat()) if session == nil { return } @@ -105,11 +105,11 @@ func (c *EchoClient) removeSession(session getty.Session) { for i, s := range c.sessions { if s.session == session { c.sessions = append(c.sessions[:i], c.sessions[i+1:]...) - log.Debug("delete session{%s}, its index{%d}", session.Stat(), i) + log.Debugf("delete session{%s}, its index{%d}", session.Stat(), i) break } } - log.Info("after remove session{%s}, left session number:%d", session.Stat(), len(c.sessions)) + log.Infof("after remove session{%s}, left session number:%d", session.Stat(), len(c.sessions)) c.lock.Unlock() } @@ -164,7 +164,7 @@ func (c *EchoClient) heartbeat(session getty.Session) { pkg.H.Len = (uint16)(len(pkg.B) + 1) if _, _, err := session.WritePkg(&pkg, WritePkgTimeout); err != nil { - log.Warn("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) + log.Warnf("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) session.Close() c.removeSession(session) diff --git a/examples/echo/tcp-echo/client/app/config.go b/examples/echo/tcp-echo/client/app/config.go index e286fdc0..fdf7abfb 100644 --- a/examples/echo/tcp-echo/client/app/config.go +++ b/examples/echo/tcp-echo/client/app/config.go @@ -26,7 +26,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" yaml "gopkg.in/yaml.v2" ) @@ -156,7 +155,6 @@ func initConf() { panic(fmt.Sprintf("time.ParseDuration(WaitTimeout{%#v}) = error{%v}", conf.GettySessionParam.WaitTimeout, err)) return } - // gxlog.CInfo("config{%#v}\n", conf) // log confFile = os.Getenv(APP_LOG_CONF_FILE) @@ -168,7 +166,6 @@ func initConf() { panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) return } - log.LoadConfiguration(confFile) log.Info("config{%#v}", conf) return diff --git a/examples/echo/tcp-echo/client/app/echo.go b/examples/echo/tcp-echo/client/app/echo.go index 013740ec..2be50b64 100644 --- a/examples/echo/tcp-echo/client/app/echo.go +++ b/examples/echo/tcp-echo/client/app/echo.go @@ -25,10 +25,6 @@ import ( "unsafe" ) -import ( - log "github.com/AlexStocks/log4go" -) - //////////////////////////////////////////// // echo command //////////////////////////////////////////// @@ -131,7 +127,7 @@ func (p *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) { return 0, err } if p.H.Magic != echoPkgMagic { - log.Error("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) + log.Errorf("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) return 0, ErrIllegalMagic } if buf.Len() < (int)(p.H.Len) { diff --git a/examples/echo/tcp-echo/client/app/handler.go b/examples/echo/tcp-echo/client/app/handler.go index 1e172bfc..96e50928 100644 --- a/examples/echo/tcp-echo/client/app/handler.go +++ b/examples/echo/tcp-echo/client/app/handler.go @@ -23,7 +23,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -54,34 +53,34 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { } func (h *EchoMessageHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + log.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) client.removeSession(session) } func (h *EchoMessageHandler) OnClose(session getty.Session) { - log.Info("session{%s} is closing......", session.Stat()) + log.Infof("session{%s} is closing......", session.Stat()) client.removeSession(session) } func (h *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) { p, ok := pkg.(*EchoPackage) if !ok { - log.Error("illegal packge{%#v}", pkg) + log.Errorf("illegal packge{%#v}", pkg) return } - log.Debug("get echo package{%s}", p) + log.Debugf("get echo package{%s}", p) client.updateSession(session) } func (h *EchoMessageHandler) OnCron(session getty.Session) { clientEchoSession, err := client.getClientEchoSession(session) if err != nil { - log.Error("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err) + log.Errorf("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err) return } if conf.sessionTimeout.Nanoseconds() < time.Since(session.GetActive()).Nanoseconds() { - log.Warn("session{%s} timeout{%s}, reqNum{%d}", + log.Warnf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(session.GetActive()).String(), clientEchoSession.reqNum) client.removeSession(session) return diff --git a/examples/echo/tcp-echo/client/app/main.go b/examples/echo/tcp-echo/client/app/main.go index 7ba47ea6..f898260c 100644 --- a/examples/echo/tcp-echo/client/app/main.go +++ b/examples/echo/tcp-echo/client/app/main.go @@ -33,10 +33,8 @@ import ( ) import ( - gxlog "github.com/AlexStocks/goext/log" gxnet "github.com/AlexStocks/goext/net" gxtime "github.com/AlexStocks/goext/time" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" "github.com/dubbogo/gost/sync" ) @@ -65,8 +63,7 @@ func main() { taskPool = gxsync.NewTaskPoolSimple(0) initClient() - gxlog.CInfo("%s starts successfull!", conf.AppName) - log.Info("%s starts successfull!\n", conf.AppName) + log.Infof("%s starts successfull!", conf.AppName) go test() @@ -77,7 +74,7 @@ func initProfiling() { var addr string addr = gxnet.HostAddress(conf.LocalHost, conf.ProfilePort) - log.Info("App Profiling startup on address{%v}", addr+pprofPath) + log.Infof("App Profiling startup on address{%v}", addr+pprofPath) go func() { log.Info(http.ListenAndServe(addr, nil)) }() @@ -113,7 +110,7 @@ func newSession(session getty.Session) error { session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout) session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6)) session.SetWaitTime(conf.GettySessionParam.waitTimeout) - log.Debug("client new session:%s\n", session.Stat()) + log.Debugf("client new session:%s", session.Stat()) return nil } @@ -144,7 +141,7 @@ func initSignal() { signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals - log.Info("get signal %s", sig.String()) + log.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() @@ -152,15 +149,11 @@ func initSignal() { go time.AfterFunc(conf.failFastTimeout, func() { // log.Warn("app exit now by force...") // os.Exit(1) - log.Exit("app exit now by force...") - log.Close() }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 uninitClient() // fmt.Println("app exit now...") - log.Exit("app exit now...") - log.Close() return } } @@ -203,6 +196,5 @@ func test() { echo() } cost = counter.Count() - log.Info("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) - gxlog.CInfo("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) + log.Infof("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) } diff --git a/examples/echo/tcp-echo/client/app/readwriter.go b/examples/echo/tcp-echo/client/app/readwriter.go index 3f2772e1..bbba5fd5 100644 --- a/examples/echo/tcp-echo/client/app/readwriter.go +++ b/examples/echo/tcp-echo/client/app/readwriter.go @@ -24,7 +24,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -68,15 +67,15 @@ func (h *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, e startTime = time.Now() if echoPkg, ok = pkg.(*EchoPackage); !ok { - log.Error("illegal pkg:%+v\n", pkg) + log.Errorf("illegal pkg:%+v", pkg) return nil, errors.New("invalid echo package!") } buf, err = echoPkg.Marshal() if err != nil { - log.Warn("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) + log.Warnf("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) return nil, err } - log.Debug("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) + log.Debugf("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) return buf.Bytes(), nil } diff --git a/examples/echo/tcp-echo/server/app/config.go b/examples/echo/tcp-echo/server/app/config.go index 23ab4656..853c734a 100644 --- a/examples/echo/tcp-echo/server/app/config.go +++ b/examples/echo/tcp-echo/server/app/config.go @@ -26,7 +26,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" yaml "gopkg.in/yaml.v2" ) @@ -138,7 +137,6 @@ func initConf() { panic(fmt.Sprintf("time.ParseDuration(WaitTimeout{%#v}) = error{%v}", conf.GettySessionParam.WaitTimeout, err)) return } - // gxlog.CInfo("config{%#v}\n", conf) // log confFile = os.Getenv(APP_LOG_CONF_FILE) @@ -150,8 +148,7 @@ func initConf() { panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) return } - log.LoadConfiguration(confFile) - log.Info("config{%#v}", conf) + log.Infof("config{%#v}", conf) return } diff --git a/examples/echo/tcp-echo/server/app/echo.go b/examples/echo/tcp-echo/server/app/echo.go index b7df0c85..a6966492 100644 --- a/examples/echo/tcp-echo/server/app/echo.go +++ b/examples/echo/tcp-echo/server/app/echo.go @@ -25,10 +25,6 @@ import ( "unsafe" ) -import ( - log "github.com/AlexStocks/log4go" -) - //////////////////////////////////////////// // echo command //////////////////////////////////////////// @@ -131,7 +127,7 @@ func (p *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) { return 0, err } if p.H.Magic != echoPkgMagic { - log.Error("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) + log.Errorf("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) return 0, ErrIllegalMagic } if buf.Len() < (int)(p.H.Len) { diff --git a/examples/echo/tcp-echo/server/app/handler.go b/examples/echo/tcp-echo/server/app/handler.go index 7498ba3f..ac11cda3 100644 --- a/examples/echo/tcp-echo/server/app/handler.go +++ b/examples/echo/tcp-echo/server/app/handler.go @@ -24,7 +24,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -50,7 +49,7 @@ type PackageHandler interface { type HeartbeatHandler struct{} func (h *HeartbeatHandler) Handle(session getty.Session, pkg *EchoPackage) error { - log.Debug("get echo heartbeat package{%s}", pkg) + log.Debugf("get echo heartbeat package{%s}", pkg) var rspPkg EchoPackage rspPkg.H = pkg.H @@ -67,11 +66,11 @@ func (h *HeartbeatHandler) Handle(session getty.Session, pkg *EchoPackage) error type MessageHandler struct{} func (h *MessageHandler) Handle(session getty.Session, pkg *EchoPackage) error { - log.Debug("get echo package{%s}", pkg) + log.Debugf("get echo package{%s}", pkg) // write echo message handle logic here. _, _, err := session.WritePkg(pkg, WritePkgTimeout) if err != nil { - log.Warn("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) + log.Warnf("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) session.Close() } return err @@ -113,7 +112,7 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { return err } - log.Info("got session:%s", session.Stat()) + log.Infof("got session:%s", session.Stat()) h.rwlock.Lock() h.sessionMap[session] = &clientEchoSession{session: session} h.rwlock.Unlock() @@ -121,14 +120,14 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { } func (h *EchoMessageHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + log.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) h.rwlock.Lock() delete(h.sessionMap, session) h.rwlock.Unlock() } func (h *EchoMessageHandler) OnClose(session getty.Session) { - log.Info("session{%s} is closing......", session.Stat()) + log.Infof("session{%s} is closing......", session.Stat()) h.rwlock.Lock() delete(h.sessionMap, session) h.rwlock.Unlock() @@ -137,13 +136,13 @@ func (h *EchoMessageHandler) OnClose(session getty.Session) { func (h *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) { p, ok := pkg.(*EchoPackage) if !ok { - log.Error("illegal packge{%#v}", pkg) + log.Errorf("illegal packge{%#v}", pkg) return } handler, ok := h.handlers[p.H.Command] if !ok { - log.Error("illegal command{%d}", p.H.Command) + log.Errorf("illegal command{%d}", p.H.Command) return } err := handler.Handle(session, p) @@ -166,7 +165,7 @@ func (h *EchoMessageHandler) OnCron(session getty.Session) { active = session.GetActive() if conf.sessionTimeout.Nanoseconds() < time.Since(active).Nanoseconds() { flag = true - log.Warn("session{%s} timeout{%s}, reqNum{%d}", + log.Warnf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(active).String(), h.sessionMap[session].reqNum) } } diff --git a/examples/echo/tcp-echo/server/app/readwriter.go b/examples/echo/tcp-echo/server/app/readwriter.go index 8782757b..b8e7de07 100644 --- a/examples/echo/tcp-echo/server/app/readwriter.go +++ b/examples/echo/tcp-echo/server/app/readwriter.go @@ -24,7 +24,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -68,17 +67,17 @@ func (h *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, e startTime = time.Now() if echoPkg, ok = pkg.(*EchoPackage); !ok { - log.Error("illegal pkg:%+v\n", pkg) + log.Errorf("illegal pkg:%+v", pkg) return nil, errors.New("invalid echo package!") } buf, err = echoPkg.Marshal() if err != nil { - log.Warn("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) + log.Warnf("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) return nil, err } - log.Debug("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) + log.Debugf("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) return buf.Bytes(), nil } diff --git a/examples/echo/tcp-echo/server/app/server.go b/examples/echo/tcp-echo/server/app/server.go index 1fcaf8ea..9b53f9e0 100644 --- a/examples/echo/tcp-echo/server/app/server.go +++ b/examples/echo/tcp-echo/server/app/server.go @@ -32,9 +32,7 @@ import ( ) import ( - gxlog "github.com/AlexStocks/goext/log" gxnet "github.com/AlexStocks/goext/net" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" "github.com/dubbogo/gost/sync" ) @@ -51,6 +49,7 @@ var ( var ( serverList []getty.Server taskPool gxsync.GenericTaskPool + log = getty.GetLogger() ) func main() { @@ -65,9 +64,7 @@ func main() { taskPool = gxsync.NewTaskPoolSimple(0) initServer() - gxlog.CInfo("%s starts successfull! its listen ends=%s:%s\n", - conf.AppName, conf.Host, conf.Ports) - log.Info("%s starts successfull! its listen ends=%s:%s\n", + log.Infof("%s starts successfull! its listen ends=%s:%s", conf.AppName, conf.Host, conf.Ports) initSignal() @@ -78,7 +75,7 @@ func initProfiling() { // addr = *host + ":" + "10000" addr = gxnet.HostAddress(conf.Host, conf.ProfilePort) - log.Info("App Profiling startup on address{%v}", addr+pprofPath) + log.Infof("App Profiling startup on address{%v}", addr+pprofPath) go func() { log.Info(http.ListenAndServe(addr, nil)) }() @@ -115,7 +112,7 @@ func newSession(session getty.Session) error { session.SetCronPeriod((int)(conf.sessionTimeout.Nanoseconds() / 1e6)) session.SetWaitTime(conf.GettySessionParam.waitTimeout) // session.SetTaskPool(taskPool) - log.Debug("app accepts new session:%s\n", session.Stat()) + log.Debugf("app accepts new session:%s", session.Stat()) return nil } @@ -147,7 +144,7 @@ func initServer() { server = getty.NewTCPServer(serverOpts...) // run server server.RunEventLoop(newSession) - log.Debug("server bind addr{%s} ok!", addr) + log.Debugf("server bind addr{%s} ok!", addr) serverList = append(serverList, server) } } @@ -168,7 +165,7 @@ func initSignal() { signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals - log.Info("get signal %s", sig.String()) + log.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() @@ -176,15 +173,13 @@ func initSignal() { go time.AfterFunc(conf.failFastTimeout, func() { // log.Warn("app exit now by force...") // os.Exit(1) - log.Exit("app exit now by force...") - log.Close() + log.Info("app exit now by force...") }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 uninitServer() // fmt.Println("app exit now...") - log.Exit("app exit now...") - log.Close() + log.Info("app exit now...") return } } diff --git a/examples/echo/udp-echo/client/app/client.go b/examples/echo/udp-echo/client/app/client.go index 28609342..89583b64 100644 --- a/examples/echo/udp-echo/client/app/client.go +++ b/examples/echo/udp-echo/client/app/client.go @@ -26,13 +26,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) var ( reqID uint32 src = rand.NewSource(time.Now().UnixNano()) + log = getty.GetLogger() ) func init() { @@ -65,7 +65,7 @@ func (c *EchoClient) close() { c.gettyClient.Close() c.gettyClient = nil for _, s := range c.sessions { - log.Info("close client session{%s, last active:%s, request number:%d}", + log.Infof("close client session{%s, last active:%s, request number:%d}", s.session.Stat(), s.session.GetActive().String(), s.reqNum) s.session.Close() } @@ -87,14 +87,14 @@ func (c *EchoClient) selectSession() getty.Session { } func (c *EchoClient) addSession(session getty.Session) { - log.Debug("add session{%s}", session.Stat()) + log.Debugf("add session{%s}", session.Stat()) if session == nil { return } c.lock.Lock() c.sessions = append(c.sessions, &clientEchoSession{session: session}) - log.Debug("after add session{%s}, session number:%d", session.Stat(), len(c.sessions)) + log.Debugf("after add session{%s}, session number:%d", session.Stat(), len(c.sessions)) c.lock.Unlock() } @@ -108,11 +108,11 @@ func (c *EchoClient) removeSession(session getty.Session) { for i, s := range c.sessions { if s.session == session { c.sessions = append(c.sessions[:i], c.sessions[i+1:]...) - log.Debug("delete session{%s}, its index{%d}", session.Stat(), i) + log.Debugf("delete session{%s}, its index{%d}", session.Stat(), i) break } } - log.Info("after remove session{%s}, left session number:%d", session.Stat(), len(c.sessions)) + log.Infof("after remove session{%s}, left session number:%d", session.Stat(), len(c.sessions)) c.lock.Unlock() } @@ -176,10 +176,10 @@ func (c *EchoClient) heartbeat(session getty.Session) { // if err := session.WritePkg(ctx, WritePkgTimeout); err != nil { if _, _, err = session.WritePkg(ctx, WritePkgASAP); err != nil { - log.Warn("session.WritePkg(session{%s}, context{%#v}) = error{%v}", session.Stat(), ctx, err) + log.Warnf("session.WritePkg(session{%s}, context{%#v}) = error{%v}", session.Stat(), ctx, err) session.Close() c.removeSession(session) } - log.Debug("session.WritePkg(session{%s}, context{%#v})", session.Stat(), ctx) + log.Debugf("session.WritePkg(session{%s}, context{%#v})", session.Stat(), ctx) } diff --git a/examples/echo/udp-echo/client/app/config.go b/examples/echo/udp-echo/client/app/config.go index 40fab211..78c1c829 100644 --- a/examples/echo/udp-echo/client/app/config.go +++ b/examples/echo/udp-echo/client/app/config.go @@ -25,7 +25,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" config "github.com/koding/multiconfig" ) @@ -148,8 +147,7 @@ func initConf() { panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) return } - log.LoadConfiguration(confFile) - log.Info("config{%#v}", conf) + log.Infof("config{%#v}", conf) return } diff --git a/examples/echo/udp-echo/client/app/echo.go b/examples/echo/udp-echo/client/app/echo.go index bec9213c..116e40cd 100644 --- a/examples/echo/udp-echo/client/app/echo.go +++ b/examples/echo/udp-echo/client/app/echo.go @@ -25,10 +25,6 @@ import ( "unsafe" ) -import ( - log "github.com/AlexStocks/log4go" -) - //////////////////////////////////////////// // echo command //////////////////////////////////////////// @@ -131,7 +127,7 @@ func (p *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) { return 0, err } if p.H.Magic != echoPkgMagic { - log.Error("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) + log.Errorf("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) return 0, ErrIllegalMagic } if buf.Len() < (int)(p.H.Len) { diff --git a/examples/echo/udp-echo/client/app/handler.go b/examples/echo/udp-echo/client/app/handler.go index 9082374a..11d0d5cf 100644 --- a/examples/echo/udp-echo/client/app/handler.go +++ b/examples/echo/udp-echo/client/app/handler.go @@ -23,7 +23,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -53,28 +52,28 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { } func (h *EchoMessageHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + log.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) h.client.removeSession(session) } func (h *EchoMessageHandler) OnClose(session getty.Session) { - log.Info("session{%s} is closing......", session.Stat()) + log.Infof("session{%s} is closing......", session.Stat()) h.client.removeSession(session) } func (h *EchoMessageHandler) OnMessage(session getty.Session, udpCtx interface{}) { ctx, ok := udpCtx.(getty.UDPContext) if !ok { - log.Error("illegal UDPContext{%#v}", udpCtx) + log.Errorf("illegal UDPContext{%#v}", udpCtx) return } p, ok := ctx.Pkg.(*EchoPackage) if !ok { - log.Error("illegal packge{%#v}", ctx.Pkg) + log.Errorf("illegal packge{%#v}", ctx.Pkg) return } - log.Debug("get echo package{%s}", p) + log.Debugf("get echo package{%s}", p) h.client.updateSession(session) } @@ -82,11 +81,11 @@ func (h *EchoMessageHandler) OnMessage(session getty.Session, udpCtx interface{} func (h *EchoMessageHandler) OnCron(session getty.Session) { clientEchoSession, err := h.client.getClientEchoSession(session) if err != nil { - log.Error("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err) + log.Errorf("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err) return } if conf.sessionTimeout.Nanoseconds() < time.Since(session.GetActive()).Nanoseconds() { - log.Warn("session{%s} timeout{%s}, reqNum{%d}", + log.Warnf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(session.GetActive()).String(), clientEchoSession.reqNum) // UDP_ENDPOINT session should be long live. if h.client != &unconnectedClient { diff --git a/examples/echo/udp-echo/client/app/main.go b/examples/echo/udp-echo/client/app/main.go index d58a47b4..c4891932 100644 --- a/examples/echo/udp-echo/client/app/main.go +++ b/examples/echo/udp-echo/client/app/main.go @@ -31,10 +31,8 @@ import ( ) import ( - gxlog "github.com/AlexStocks/goext/log" gxnet "github.com/AlexStocks/goext/net" gxtime "github.com/AlexStocks/goext/time" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -62,8 +60,7 @@ func main() { initProfiling() initClient() - log.Info("%s starts successfull!\n", conf.AppName) - gxlog.CInfo("%s starts successfull!", conf.AppName) + log.Infof("%s starts successfull!", conf.AppName) go test() @@ -74,7 +71,7 @@ func initProfiling() { var addr string addr = gxnet.HostAddress(conf.LocalHost, conf.ProfilePort) - log.Info("App Profiling startup on address{%v}", addr+pprofPath) + log.Infof("App Profiling startup on address{%v}", addr+pprofPath) go func() { log.Info(http.ListenAndServe(addr, nil)) }() @@ -125,8 +122,7 @@ func newSession(session getty.Session) error { session.SetWriteTimeout(conf.GettySessionParam.udpWriteTimeout) session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6)) session.SetWaitTime(conf.GettySessionParam.waitTimeout) - log.Debug("client new session:%s\n", session.Stat()) - gxlog.CDebug("client new session:%s\n", session.Stat()) + log.Debugf("client new session:%s", session.Stat()) return nil } @@ -165,15 +161,13 @@ func initSignal() { go time.AfterFunc(conf.failFastTimeout, func() { // log.Warn("app exit now by force...") // os.Exit(1) - log.Exit("app exit now by force...") - log.Close() + log.Info("app exit now by force...") }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 uninitClient() // fmt.Println("app exit now...") - log.Exit("app exit now...") - log.Close() + log.Info("app exit now...") return } } @@ -201,7 +195,7 @@ func echo(client *EchoClient) { // err := session.WritePkg(ctx, WritePkgTimeout) _, _, err = session.WritePkg(ctx, WritePkgASAP) if err != nil { - log.Warn("session.WritePkg(session{%s}, UDPContext{%#v}) = error{%v}", session.Stat(), ctx, err) + log.Warnf("session.WritePkg(session{%s}, UDPContext{%#v}) = error{%v}", session.Stat(), ctx, err) session.Close() client.removeSession(session) } @@ -226,7 +220,7 @@ func testEchoClient(client *EchoClient) { echo(client) } cost = counter.Count() - log.Info("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) + log.Infof("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) } func test() { diff --git a/examples/echo/udp-echo/client/app/readwriter.go b/examples/echo/udp-echo/client/app/readwriter.go index 6774d684..6823eef7 100644 --- a/examples/echo/udp-echo/client/app/readwriter.go +++ b/examples/echo/udp-echo/client/app/readwriter.go @@ -25,7 +25,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -70,23 +69,23 @@ func (h *EchoPackageHandler) Write(ss getty.Session, udpCtx interface{}) ([]byte ctx, ok = udpCtx.(getty.UDPContext) if !ok { - log.Error("illegal UDPContext{%#v}", udpCtx) + log.Errorf("illegal UDPContext{%#v}", udpCtx) return nil, fmt.Errorf("illegal @udpCtx{%#v}", udpCtx) } startTime = time.Now() if echoPkg, ok = ctx.Pkg.(*EchoPackage); !ok { - log.Error("illegal pkg:%+v, its type:%T\n", ctx.Pkg, ctx.Pkg) + log.Errorf("illegal pkg:%+v, its type:%T\n", ctx.Pkg, ctx.Pkg) return nil, errors.New("invalid echo package!") } buf, err = echoPkg.Marshal() if err != nil { - log.Warn("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) + log.Warnf("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) return nil, err } - log.Debug("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) + log.Debugf("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) return buf.Bytes(), nil } diff --git a/examples/echo/udp-echo/server/app/config.go b/examples/echo/udp-echo/server/app/config.go index 8f2098d3..6a0099cc 100644 --- a/examples/echo/udp-echo/server/app/config.go +++ b/examples/echo/udp-echo/server/app/config.go @@ -25,7 +25,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" config "github.com/koding/multiconfig" ) @@ -131,8 +130,7 @@ func initConf() { panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) return } - log.LoadConfiguration(confFile) - log.Info("config{%#v}", conf) + log.Infof("config{%#v}", conf) return } diff --git a/examples/echo/udp-echo/server/app/echo.go b/examples/echo/udp-echo/server/app/echo.go index b7df0c85..a6966492 100644 --- a/examples/echo/udp-echo/server/app/echo.go +++ b/examples/echo/udp-echo/server/app/echo.go @@ -25,10 +25,6 @@ import ( "unsafe" ) -import ( - log "github.com/AlexStocks/log4go" -) - //////////////////////////////////////////// // echo command //////////////////////////////////////////// @@ -131,7 +127,7 @@ func (p *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) { return 0, err } if p.H.Magic != echoPkgMagic { - log.Error("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) + log.Errorf("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) return 0, ErrIllegalMagic } if buf.Len() < (int)(p.H.Len) { diff --git a/examples/echo/udp-echo/server/app/handler.go b/examples/echo/udp-echo/server/app/handler.go index 04847e34..45a80320 100644 --- a/examples/echo/udp-echo/server/app/handler.go +++ b/examples/echo/udp-echo/server/app/handler.go @@ -25,7 +25,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -58,7 +57,7 @@ func (h *HeartbeatHandler) Handle(session getty.Session, ctx getty.UDPContext) e rspPkg EchoPackage ) - log.Debug("get echo heartbeat udp context{%#v}", ctx) + log.Debugf("get echo heartbeat udp context{%#v}", ctx) if pkg, ok = ctx.Pkg.(*EchoPackage); !ok { return fmt.Errorf("illegal @ctx.Pkg:%#v", ctx.Pkg) } @@ -70,7 +69,7 @@ func (h *HeartbeatHandler) Handle(session getty.Session, ctx getty.UDPContext) e // return session.WritePkg(getty.UDPContext{Pkg: &rspPkg, PeerAddr: ctx.PeerAddr}, WritePkgTimeout) _, _, err := session.WritePkg(getty.UDPContext{Pkg: &rspPkg, PeerAddr: ctx.PeerAddr}, WritePkgASAP) if err != nil { - log.Warn("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) + log.Warnf("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) session.Close() } return err @@ -83,7 +82,7 @@ func (h *HeartbeatHandler) Handle(session getty.Session, ctx getty.UDPContext) e type MessageHandler struct{} func (h *MessageHandler) Handle(session getty.Session, ctx getty.UDPContext) error { - log.Debug("get echo ctx{%#v}", ctx) + log.Debugf("get echo ctx{%#v}", ctx) // write echo message handle logic here. // return session.WritePkg(ctx, WritePkgTimeout) _, _, err := session.WritePkg(ctx, WritePkgASAP) @@ -126,7 +125,7 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { return err } - log.Info("got session:%s", session.Stat()) + log.Infof("got session:%s", session.Stat()) h.rwlock.Lock() h.sessionMap[session] = &clientEchoSession{session: session} h.rwlock.Unlock() @@ -134,14 +133,14 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { } func (h *EchoMessageHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + log.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) h.rwlock.Lock() delete(h.sessionMap, session) h.rwlock.Unlock() } func (h *EchoMessageHandler) OnClose(session getty.Session) { - log.Info("session{%s} is closing......", session.Stat()) + log.Infof("session{%s} is closing......", session.Stat()) h.rwlock.Lock() delete(h.sessionMap, session) h.rwlock.Unlock() @@ -156,13 +155,13 @@ func (h *EchoMessageHandler) OnMessage(session getty.Session, udpCtx interface{} p, ok := ctx.Pkg.(*EchoPackage) if !ok { - log.Error("illegal pkg{%#v}", ctx.Pkg) + log.Errorf("illegal pkg{%#v}", ctx.Pkg) return } handler, ok := h.handlers[p.H.Command] if !ok { - log.Error("illegal command{%d}", p.H.Command) + log.Errorf("illegal command{%d}", p.H.Command) return } err := handler.Handle(session, ctx) @@ -176,7 +175,6 @@ func (h *EchoMessageHandler) OnMessage(session getty.Session, udpCtx interface{} } func (h *EchoMessageHandler) OnCron(session getty.Session) { - // flag bool var active time.Time h.rwlock.RLock() @@ -184,7 +182,7 @@ func (h *EchoMessageHandler) OnCron(session getty.Session) { active = session.GetActive() if conf.sessionTimeout.Nanoseconds() < time.Since(active).Nanoseconds() { // flag = true - log.Error("session{%s} timeout{%s}, reqNum{%d}", + log.Errorf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(active).String(), h.sessionMap[session].reqNum) } } diff --git a/examples/echo/udp-echo/server/app/readwriter.go b/examples/echo/udp-echo/server/app/readwriter.go index 18c05e8a..c848b585 100644 --- a/examples/echo/udp-echo/server/app/readwriter.go +++ b/examples/echo/udp-echo/server/app/readwriter.go @@ -25,7 +25,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -70,23 +69,23 @@ func (h *EchoPackageHandler) Write(ss getty.Session, udpCtx interface{}) ([]byte ctx, ok = udpCtx.(getty.UDPContext) if !ok { - log.Error("illegal UDPContext{%#v}", udpCtx) + log.Errorf("illegal UDPContext{%#v}", udpCtx) return nil, fmt.Errorf("illegal @udpCtx{%#v}", udpCtx) } startTime = time.Now() if echoPkg, ok = ctx.Pkg.(*EchoPackage); !ok { - log.Error("illegal pkg:%+v, addr:%s\n", ctx.Pkg, ctx.PeerAddr) + log.Errorf("illegal pkg:%+v, addr:%s", ctx.Pkg, ctx.PeerAddr) return nil, errors.New("invalid echo package!") } buf, err = echoPkg.Marshal() if err != nil { - log.Warn("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) + log.Warnf("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) return nil, err } - log.Debug("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) + log.Debugf("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) return buf.Bytes(), nil } diff --git a/examples/echo/udp-echo/server/app/server.go b/examples/echo/udp-echo/server/app/server.go index b7632900..9e1b6800 100644 --- a/examples/echo/udp-echo/server/app/server.go +++ b/examples/echo/udp-echo/server/app/server.go @@ -32,9 +32,7 @@ import ( ) import ( - gxlog "github.com/AlexStocks/goext/log" gxnet "github.com/AlexStocks/goext/net" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -47,7 +45,10 @@ var ( // ports = flag.String("ports", "12345,12346,12347", "local host port list that the server app will bind") ) -var serverList []getty.Server +var ( + serverList []getty.Server + log = getty.GetLogger() +) func main() { // flag.Parse() @@ -60,9 +61,7 @@ func main() { initProfiling() initServer() - gxlog.CInfo("%s starts successfull! its listen ends=%s:%s\n", - conf.AppName, conf.Host, conf.Ports) - log.Info("%s starts successfull! its listen ends=%s:%s\n", + log.Infof("%s starts successfull! its listen ends=%s:%s", conf.AppName, conf.Host, conf.Ports) initSignal() @@ -73,7 +72,7 @@ func initProfiling() { // addr = *host + ":" + "10000" addr = gxnet.HostAddress(conf.Host, conf.ProfilePort) - log.Info("App Profiling startup on address{%v}", addr+pprofPath) + log.Infof("App Profiling startup on address{%v}", addr+pprofPath) go func() { log.Info(http.ListenAndServe(addr, nil)) }() @@ -89,7 +88,7 @@ func newSession(session getty.Session) error { session.SetCompressType(getty.CompressZip) } - gxlog.CInfo("session:%#v", session) + log.Infof("session:%#v", session) if udpConn, ok = session.Conn().(*net.UDPConn); !ok { panic(fmt.Sprintf("%s, session.conn{%#v} is not udp connection\n", session.Stat(), session.Conn())) } @@ -105,7 +104,7 @@ func newSession(session getty.Session) error { session.SetWriteTimeout(conf.GettySessionParam.udpWriteTimeout) session.SetCronPeriod((int)(conf.sessionTimeout.Nanoseconds() / 1e6)) session.SetWaitTime(conf.GettySessionParam.waitTimeout) - log.Debug("app accepts new session:%s\n", session.Stat()) + log.Debugf("app accepts new session:%s", session.Stat()) return nil } @@ -137,7 +136,7 @@ func initServer() { ) // run server server.RunEventLoop(newSession) - log.Debug("server bind addr{%s} ok!", addr) + log.Debugf("server bind addr{%s} ok!", addr) serverList = append(serverList, server) } } @@ -155,7 +154,7 @@ func initSignal() { signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals - log.Info("get signal %s", sig.String()) + log.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() @@ -163,15 +162,13 @@ func initSignal() { go time.AfterFunc(conf.failFastTimeout, func() { // log.Warn("app exit now by force...") // os.Exit(1) - log.Exit("app exit now by force...") - log.Close() + log.Info("app exit now by force...") }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 uninitServer() // fmt.Println("app exit now...") - log.Exit("app exit now...") - log.Close() + log.Info("app exit now...") return } } diff --git a/examples/echo/ws-echo/client/app/client.go b/examples/echo/ws-echo/client/app/client.go index 3a469ec0..1666ae74 100644 --- a/examples/echo/ws-echo/client/app/client.go +++ b/examples/echo/ws-echo/client/app/client.go @@ -24,13 +24,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) var ( reqID uint32 src = rand.NewSource(time.Now().UnixNano()) + log = getty.GetLogger() ) func init() { @@ -62,7 +62,7 @@ func (c *EchoClient) close() { c.gettyClient.Close() c.gettyClient = nil for _, s := range c.sessions { - log.Info("close client session{%s, last active:%s, request number:%d}", + log.Infof("close client session{%s, last active:%s, request number:%d}", s.session.Stat(), s.session.GetActive().String(), s.reqNum) s.session.Close() } @@ -76,7 +76,7 @@ func (c *EchoClient) selectSession() getty.Session { defer c.lock.RUnlock() count := len(c.sessions) if count == 0 { - log.Info("client session array is nil...") + log.Infof("client session array is nil...") return nil } @@ -84,7 +84,7 @@ func (c *EchoClient) selectSession() getty.Session { } func (c *EchoClient) addSession(session getty.Session) { - log.Debug("add session{%s}", session.Stat()) + log.Debugf("add session{%s}", session.Stat()) if session == nil { return } @@ -104,11 +104,11 @@ func (c *EchoClient) removeSession(session getty.Session) { for i, s := range c.sessions { if s.session == session { c.sessions = append(c.sessions[:i], c.sessions[i+1:]...) - log.Debug("delete session{%s}, its index{%d}", session.Stat(), i) + log.Debugf("delete session{%s}, its index{%d}", session.Stat(), i) break } } - log.Info("after remove session{%s}, left session number:%d", session.Stat(), len(c.sessions)) + log.Infof("after remove session{%s}, left session number:%d", session.Stat(), len(c.sessions)) c.lock.Unlock() } diff --git a/examples/echo/ws-echo/client/app/config.go b/examples/echo/ws-echo/client/app/config.go index 905c7c44..5b7c11cd 100644 --- a/examples/echo/ws-echo/client/app/config.go +++ b/examples/echo/ws-echo/client/app/config.go @@ -26,7 +26,6 @@ import ( import ( // "github.com/AlexStocks/goext/log" - log "github.com/AlexStocks/log4go" config "github.com/koding/multiconfig" ) @@ -151,8 +150,7 @@ func initConf() { panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) return } - log.LoadConfiguration(confFile) - log.Info("config{%#v}", conf) + log.Infof("config{%#v}", conf) return } diff --git a/examples/echo/ws-echo/client/app/echo.go b/examples/echo/ws-echo/client/app/echo.go index bdc3e5d3..4dc6441e 100644 --- a/examples/echo/ws-echo/client/app/echo.go +++ b/examples/echo/ws-echo/client/app/echo.go @@ -25,10 +25,6 @@ import ( "unsafe" ) -import ( - log "github.com/AlexStocks/log4go" -) - //////////////////////////////////////////// // echo command //////////////////////////////////////////// @@ -126,7 +122,7 @@ func (p *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) { return 0, err } if p.H.Magic != echoPkgMagic { - log.Error("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) + log.Errorf("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) return 0, ErrIllegalMagic } if buf.Len() < (int)(p.H.Len) { diff --git a/examples/echo/ws-echo/client/app/handler.go b/examples/echo/ws-echo/client/app/handler.go index 7aa4328a..12d65383 100644 --- a/examples/echo/ws-echo/client/app/handler.go +++ b/examples/echo/ws-echo/client/app/handler.go @@ -23,7 +23,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -54,34 +53,34 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { } func (h *EchoMessageHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + log.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) client.removeSession(session) } func (h *EchoMessageHandler) OnClose(session getty.Session) { - log.Info("session{%s} is closing......", session.Stat()) + log.Infof("session{%s} is closing......", session.Stat()) client.removeSession(session) } func (h *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) { p, ok := pkg.(*EchoPackage) if !ok { - log.Error("illegal packge{%#v}", pkg) + log.Errorf("illegal packge{%#v}", pkg) return } - log.Debug("get echo package{%s}", p) + log.Debugf("get echo package{%s}", p) client.updateSession(session) } func (h *EchoMessageHandler) OnCron(session getty.Session) { clientEchoSession, err := client.getClientEchoSession(session) if err != nil { - log.Error("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err) + log.Errorf("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err) return } if conf.sessionTimeout.Nanoseconds() < time.Since(session.GetActive()).Nanoseconds() { - log.Warn("session{%s} timeout{%s}, reqNum{%d}", + log.Warnf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(session.GetActive()).String(), clientEchoSession.reqNum) client.removeSession(session) return diff --git a/examples/echo/ws-echo/client/app/main.go b/examples/echo/ws-echo/client/app/main.go index 819c296d..bc0c904a 100644 --- a/examples/echo/ws-echo/client/app/main.go +++ b/examples/echo/ws-echo/client/app/main.go @@ -34,10 +34,8 @@ import ( ) import ( - gxlog "github.com/AlexStocks/goext/log" gxnet "github.com/AlexStocks/goext/net" gxtime "github.com/AlexStocks/goext/time" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -57,8 +55,7 @@ func main() { initProfiling() initClient() - gxlog.CInfo("%s starts successfull!", conf.AppName) - log.Info("%s starts successfull!\n", conf.AppName) + log.Infof("%s starts successfull!", conf.AppName) go test() @@ -69,7 +66,7 @@ func initProfiling() { var addr string addr = gxnet.HostAddress(conf.LocalHost, conf.ProfilePort) - log.Info("App Profiling startup on address{%v}", addr+pprofPath) + log.Infof("App Profiling startup on address{%v}", addr+pprofPath) go func() { log.Info(http.ListenAndServe(addr, nil)) }() @@ -109,7 +106,7 @@ func newSession(session getty.Session) error { session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout) session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6)) session.SetWaitTime(conf.GettySessionParam.waitTimeout) - log.Debug("client new session:%s\n", session.Stat()) + log.Debugf("client new session:%s", session.Stat()) return nil } @@ -134,7 +131,7 @@ func initSignal() { signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals - log.Info("get signal %s", sig.String()) + log.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() @@ -142,15 +139,13 @@ func initSignal() { go time.AfterFunc(conf.failFastTimeout, func() { // log.Warn("app exit now by force...") // os.Exit(1) - log.Exit("app exit now by force...") - log.Close() + log.Info("app exit now by force...") }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 uninitClient() // fmt.Println("app exit now...") - log.Exit("app exit now...") - log.Close() + log.Info("app exit now...") return } } @@ -194,6 +189,5 @@ func test() { echo() } cost = counter.Count() - log.Info("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) - gxlog.CInfo("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) + log.Infof("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) } diff --git a/examples/echo/ws-echo/client/app/readwriter.go b/examples/echo/ws-echo/client/app/readwriter.go index 8782757b..b8e7de07 100644 --- a/examples/echo/ws-echo/client/app/readwriter.go +++ b/examples/echo/ws-echo/client/app/readwriter.go @@ -24,7 +24,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -68,17 +67,17 @@ func (h *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, e startTime = time.Now() if echoPkg, ok = pkg.(*EchoPackage); !ok { - log.Error("illegal pkg:%+v\n", pkg) + log.Errorf("illegal pkg:%+v", pkg) return nil, errors.New("invalid echo package!") } buf, err = echoPkg.Marshal() if err != nil { - log.Warn("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) + log.Warnf("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) return nil, err } - log.Debug("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) + log.Debugf("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) return buf.Bytes(), nil } diff --git a/examples/echo/ws-echo/server/app/config.go b/examples/echo/ws-echo/server/app/config.go index cdd58191..4da0421d 100644 --- a/examples/echo/ws-echo/server/app/config.go +++ b/examples/echo/ws-echo/server/app/config.go @@ -26,7 +26,6 @@ import ( import ( // "github.com/AlexStocks/goext/log" - log "github.com/AlexStocks/log4go" config "github.com/koding/multiconfig" ) @@ -144,8 +143,7 @@ func initConf() { panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) return } - log.LoadConfiguration(confFile) - log.Info("config{%#v}", conf) + log.Infof("config{%#v}", conf) return } diff --git a/examples/echo/ws-echo/server/app/echo.go b/examples/echo/ws-echo/server/app/echo.go index 254fb0ce..e52d5879 100644 --- a/examples/echo/ws-echo/server/app/echo.go +++ b/examples/echo/ws-echo/server/app/echo.go @@ -25,10 +25,6 @@ import ( "unsafe" ) -import ( - log "github.com/AlexStocks/log4go" -) - //////////////////////////////////////////// // echo command //////////////////////////////////////////// @@ -126,7 +122,7 @@ func (p *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) { return 0, err } if p.H.Magic != echoPkgMagic { - log.Error("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) + log.Errorf("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) return 0, ErrIllegalMagic } if buf.Len() < (int)(p.H.Len) { diff --git a/examples/echo/ws-echo/server/app/handler.go b/examples/echo/ws-echo/server/app/handler.go index 9378699b..6c696dbf 100644 --- a/examples/echo/ws-echo/server/app/handler.go +++ b/examples/echo/ws-echo/server/app/handler.go @@ -24,7 +24,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -45,11 +44,11 @@ type PackageHandler interface { type MessageHandler struct{} func (h *MessageHandler) Handle(session getty.Session, pkg *EchoPackage) error { - log.Debug("get echo package{%s}", pkg) + log.Debugf("get echo package{%s}", pkg) // write echo message handle logic here. _, _, err := session.WritePkg(pkg, conf.GettySessionParam.waitTimeout) if err != nil { - log.Warn("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) + log.Warnf("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) session.Close() } return err @@ -90,7 +89,7 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { return err } - log.Info("got session:%s", session.Stat()) + log.Infof("got session:%s", session.Stat()) h.rwlock.Lock() h.sessionMap[session] = &clientEchoSession{session: session} h.rwlock.Unlock() @@ -98,14 +97,14 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { } func (h *EchoMessageHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + log.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) h.rwlock.Lock() delete(h.sessionMap, session) h.rwlock.Unlock() } func (h *EchoMessageHandler) OnClose(session getty.Session) { - log.Info("session{%s} is closing......", session.Stat()) + log.Infof("session{%s} is closing......", session.Stat()) h.rwlock.Lock() delete(h.sessionMap, session) h.rwlock.Unlock() @@ -114,13 +113,13 @@ func (h *EchoMessageHandler) OnClose(session getty.Session) { func (h *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) { p, ok := pkg.(*EchoPackage) if !ok { - log.Error("illegal packge{%#v}, %s", pkg, string(pkg.([]byte))) + log.Errorf("illegal packge{%#v}, %s", pkg, string(pkg.([]byte))) return } handler, ok := h.handlers[p.H.Command] if !ok { - log.Error("illegal command{%d}", p.H.Command) + log.Errorf("illegal command{%d}", p.H.Command) return } err := handler.Handle(session, p) @@ -144,7 +143,7 @@ func (h *EchoMessageHandler) OnCron(session getty.Session) { active = session.GetActive() if conf.sessionTimeout.Nanoseconds() < time.Since(active).Nanoseconds() { flag = true - log.Warn("session{%s} timeout{%s}, reqNum{%d}", + log.Warnf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(active).String(), h.sessionMap[session].reqNum) } } diff --git a/examples/echo/ws-echo/server/app/readwriter.go b/examples/echo/ws-echo/server/app/readwriter.go index 7cfb79c4..cd855984 100644 --- a/examples/echo/ws-echo/server/app/readwriter.go +++ b/examples/echo/ws-echo/server/app/readwriter.go @@ -25,7 +25,6 @@ import ( import ( // "github.com/AlexStocks/goext/strings" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -48,7 +47,7 @@ func (h *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}, i buf = bytes.NewBuffer(data) len, err = pkg.Unmarshal(buf) - log.Debug("pkg.Read:%#v", pkg) + log.Debugf("pkg.Read:%#v", pkg) if err != nil { if err == ErrNotEnoughStream { return nil, 0, nil @@ -72,17 +71,17 @@ func (h *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, e startTime = time.Now() if echoPkg, ok = pkg.(*EchoPackage); !ok { - log.Error("illegal pkg:%+v\n", pkg) + log.Errorf("illegal pkg:%+v", pkg) return nil, errors.New("invalid echo package!") } buf, err = echoPkg.Marshal() if err != nil { - log.Warn("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) + log.Warnf("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) return nil, err } - log.Debug("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) + log.Debugf("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) return buf.Bytes(), nil } diff --git a/examples/echo/ws-echo/server/app/server.go b/examples/echo/ws-echo/server/app/server.go index 3270b5ad..6f94802f 100644 --- a/examples/echo/ws-echo/server/app/server.go +++ b/examples/echo/ws-echo/server/app/server.go @@ -33,9 +33,7 @@ import ( ) import ( - gxlog "github.com/AlexStocks/goext/log" gxnet "github.com/AlexStocks/goext/net" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -48,7 +46,10 @@ var ( // ports = flag.String("ports", "12345,12346,12347", "local host port list that the server app will bind") ) -var serverList []getty.Server +var ( + serverList []getty.Server + log = getty.GetLogger() +) func main() { // flag.Parse() @@ -61,9 +62,7 @@ func main() { initProfiling() initServer() - gxlog.CInfo("%s starts successfull! its listen ends=%s:%s:%s\n", - conf.AppName, conf.Host, conf.Ports, conf.Paths) - log.Info("%s starts successfull! its listen ends=%s:%s:%s\n", + log.Infof("%s starts successfull! its listen ends=%s:%s:%s", conf.AppName, conf.Host, conf.Ports, conf.Paths) initSignal() @@ -74,7 +73,7 @@ func initProfiling() { // addr = *host + ":" + "10000" addr = gxnet.HostAddress(conf.Host, conf.ProfilePort) - log.Info("App Profiling startup on address{%v}", addr+pprofPath) + log.Infof("App Profiling startup on address{%v}", addr+pprofPath) go func() { log.Info(http.ListenAndServe(addr, nil)) }() @@ -114,7 +113,7 @@ func newSession(session getty.Session) error { session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout) session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6)) session.SetWaitTime(conf.GettySessionParam.waitTimeout) - log.Debug("app accepts new session:%s\n", session.Stat()) + log.Debugf("app accepts new session:%s", session.Stat()) return nil } @@ -156,7 +155,7 @@ func initServer() { getty.WithWebsocketServerPath(pathList[idx]), ) server.RunEventLoop(newSession) - log.Debug("server bind addr{ws://%s/%s} ok!", addr, pathList[idx]) + log.Debugf("server bind addr{ws://%s/%s} ok!", addr, pathList[idx]) serverList = append(serverList, server) } } @@ -174,7 +173,7 @@ func initSignal() { signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals - log.Info("get signal %s", sig.String()) + log.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() @@ -182,15 +181,13 @@ func initSignal() { go time.AfterFunc(conf.failFastTimeout, func() { // log.Warn("app exit now by force...") // os.Exit(1) - log.Exit("app exit now by force...") - log.Close() + log.Info("app exit now by force...") }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 uninitServer() // fmt.Println("app exit now...") - log.Exit("app exit now...") - log.Close() + log.Info("app exit now...") return } } diff --git a/examples/echo/wss-echo/client/app/client.go b/examples/echo/wss-echo/client/app/client.go index 3a469ec0..25bcdaea 100644 --- a/examples/echo/wss-echo/client/app/client.go +++ b/examples/echo/wss-echo/client/app/client.go @@ -24,13 +24,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) var ( reqID uint32 src = rand.NewSource(time.Now().UnixNano()) + log = getty.GetLogger() ) func init() { @@ -62,7 +62,7 @@ func (c *EchoClient) close() { c.gettyClient.Close() c.gettyClient = nil for _, s := range c.sessions { - log.Info("close client session{%s, last active:%s, request number:%d}", + log.Infof("close client session{%s, last active:%s, request number:%d}", s.session.Stat(), s.session.GetActive().String(), s.reqNum) s.session.Close() } @@ -84,7 +84,7 @@ func (c *EchoClient) selectSession() getty.Session { } func (c *EchoClient) addSession(session getty.Session) { - log.Debug("add session{%s}", session.Stat()) + log.Debugf("add session{%s}", session.Stat()) if session == nil { return } @@ -104,11 +104,11 @@ func (c *EchoClient) removeSession(session getty.Session) { for i, s := range c.sessions { if s.session == session { c.sessions = append(c.sessions[:i], c.sessions[i+1:]...) - log.Debug("delete session{%s}, its index{%d}", session.Stat(), i) + log.Debugf("delete session{%s}, its index{%d}", session.Stat(), i) break } } - log.Info("after remove session{%s}, left session number:%d", session.Stat(), len(c.sessions)) + log.Infof("after remove session{%s}, left session number:%d", session.Stat(), len(c.sessions)) c.lock.Unlock() } diff --git a/examples/echo/wss-echo/client/app/config.go b/examples/echo/wss-echo/client/app/config.go index aac22659..cda7b6ef 100644 --- a/examples/echo/wss-echo/client/app/config.go +++ b/examples/echo/wss-echo/client/app/config.go @@ -26,7 +26,6 @@ import ( import ( // "github.com/AlexStocks/goext/log" - log "github.com/AlexStocks/log4go" config "github.com/koding/multiconfig" ) @@ -155,8 +154,7 @@ func initConf() { panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) return } - log.LoadConfiguration(confFile) - log.Info("config{%#v}", conf) + log.Infof("config{%#v}", conf) return } diff --git a/examples/echo/wss-echo/client/app/echo.go b/examples/echo/wss-echo/client/app/echo.go index bdc3e5d3..4dc6441e 100644 --- a/examples/echo/wss-echo/client/app/echo.go +++ b/examples/echo/wss-echo/client/app/echo.go @@ -25,10 +25,6 @@ import ( "unsafe" ) -import ( - log "github.com/AlexStocks/log4go" -) - //////////////////////////////////////////// // echo command //////////////////////////////////////////// @@ -126,7 +122,7 @@ func (p *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) { return 0, err } if p.H.Magic != echoPkgMagic { - log.Error("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) + log.Errorf("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) return 0, ErrIllegalMagic } if buf.Len() < (int)(p.H.Len) { diff --git a/examples/echo/wss-echo/client/app/handler.go b/examples/echo/wss-echo/client/app/handler.go index 7aa4328a..12d65383 100644 --- a/examples/echo/wss-echo/client/app/handler.go +++ b/examples/echo/wss-echo/client/app/handler.go @@ -23,7 +23,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -54,34 +53,34 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { } func (h *EchoMessageHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + log.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) client.removeSession(session) } func (h *EchoMessageHandler) OnClose(session getty.Session) { - log.Info("session{%s} is closing......", session.Stat()) + log.Infof("session{%s} is closing......", session.Stat()) client.removeSession(session) } func (h *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) { p, ok := pkg.(*EchoPackage) if !ok { - log.Error("illegal packge{%#v}", pkg) + log.Errorf("illegal packge{%#v}", pkg) return } - log.Debug("get echo package{%s}", p) + log.Debugf("get echo package{%s}", p) client.updateSession(session) } func (h *EchoMessageHandler) OnCron(session getty.Session) { clientEchoSession, err := client.getClientEchoSession(session) if err != nil { - log.Error("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err) + log.Errorf("client.getClientSession(session{%s}) = error{%#v}", session.Stat(), err) return } if conf.sessionTimeout.Nanoseconds() < time.Since(session.GetActive()).Nanoseconds() { - log.Warn("session{%s} timeout{%s}, reqNum{%d}", + log.Warnf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(session.GetActive()).String(), clientEchoSession.reqNum) client.removeSession(session) return diff --git a/examples/echo/wss-echo/client/app/main.go b/examples/echo/wss-echo/client/app/main.go index 87eba44f..a408b5c5 100644 --- a/examples/echo/wss-echo/client/app/main.go +++ b/examples/echo/wss-echo/client/app/main.go @@ -33,10 +33,8 @@ import ( ) import ( - "github.com/AlexStocks/goext/log" "github.com/AlexStocks/goext/net" "github.com/AlexStocks/goext/time" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -56,8 +54,7 @@ func main() { initProfiling() initClient() - gxlog.CInfo("%s starts successfull!", conf.AppName) - log.Info("%s starts successfull!\n", conf.AppName) + log.Infof("%s starts successfull!", conf.AppName) go test() @@ -68,7 +65,7 @@ func initProfiling() { var addr string addr = gxnet.HostAddress(conf.LocalHost, conf.ProfilePort) - log.Info("App Profiling startup on address{%v}", addr+pprofPath) + log.Infof("App Profiling startup on address{%v}", addr+pprofPath) go func() { log.Info(http.ListenAndServe(addr, nil)) }() @@ -108,7 +105,7 @@ func newSession(session getty.Session) error { session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout) session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6)) session.SetWaitTime(conf.GettySessionParam.waitTimeout) - log.Debug("client new session:%s\n", session.Stat()) + log.Debugf("client new session:%s", session.Stat()) return nil } @@ -141,7 +138,7 @@ func initSignal() { signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals - log.Info("get signal %s", sig.String()) + log.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() @@ -149,15 +146,13 @@ func initSignal() { go time.AfterFunc(conf.failFastTimeout, func() { // log.Warn("app exit now by force...") // os.Exit(1) - log.Exit("app exit now by force...") - log.Close() + log.Info("app exit now by force...") }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 uninitClient() // fmt.Println("app exit now...") - log.Exit("app exit now...") - log.Close() + log.Info("app exit now...") return } } @@ -201,6 +196,5 @@ func test() { echo() } cost = counter.Count() - log.Info("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) - gxlog.CInfo("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) + log.Infof("after loop %d times, echo cost %d ms", conf.EchoTimes, cost/1e6) } diff --git a/examples/echo/wss-echo/client/app/readwriter.go b/examples/echo/wss-echo/client/app/readwriter.go index 8782757b..b8e7de07 100644 --- a/examples/echo/wss-echo/client/app/readwriter.go +++ b/examples/echo/wss-echo/client/app/readwriter.go @@ -24,7 +24,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -68,17 +67,17 @@ func (h *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, e startTime = time.Now() if echoPkg, ok = pkg.(*EchoPackage); !ok { - log.Error("illegal pkg:%+v\n", pkg) + log.Errorf("illegal pkg:%+v", pkg) return nil, errors.New("invalid echo package!") } buf, err = echoPkg.Marshal() if err != nil { - log.Warn("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) + log.Warnf("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) return nil, err } - log.Debug("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) + log.Debugf("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) return buf.Bytes(), nil } diff --git a/examples/echo/wss-echo/server/app/config.go b/examples/echo/wss-echo/server/app/config.go index ff87b364..ff838c93 100644 --- a/examples/echo/wss-echo/server/app/config.go +++ b/examples/echo/wss-echo/server/app/config.go @@ -26,7 +26,6 @@ import ( import ( // "github.com/AlexStocks/goext/log" - log "github.com/AlexStocks/log4go" config "github.com/koding/multiconfig" ) @@ -150,8 +149,7 @@ func initConf() { panic(fmt.Sprintf("log configure file name{%v} suffix must be .xml", confFile)) return } - log.LoadConfiguration(confFile) - log.Info("config{%#v}", conf) + log.Infof("config{%#v}", conf) return } diff --git a/examples/echo/wss-echo/server/app/echo.go b/examples/echo/wss-echo/server/app/echo.go index 254fb0ce..e52d5879 100644 --- a/examples/echo/wss-echo/server/app/echo.go +++ b/examples/echo/wss-echo/server/app/echo.go @@ -25,10 +25,6 @@ import ( "unsafe" ) -import ( - log "github.com/AlexStocks/log4go" -) - //////////////////////////////////////////// // echo command //////////////////////////////////////////// @@ -126,7 +122,7 @@ func (p *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) { return 0, err } if p.H.Magic != echoPkgMagic { - log.Error("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) + log.Errorf("@p.H.Magic{%x}, right magic{%x}", p.H.Magic, echoPkgMagic) return 0, ErrIllegalMagic } if buf.Len() < (int)(p.H.Len) { diff --git a/examples/echo/wss-echo/server/app/handler.go b/examples/echo/wss-echo/server/app/handler.go index 9378699b..ecdf5206 100644 --- a/examples/echo/wss-echo/server/app/handler.go +++ b/examples/echo/wss-echo/server/app/handler.go @@ -24,7 +24,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -45,11 +44,11 @@ type PackageHandler interface { type MessageHandler struct{} func (h *MessageHandler) Handle(session getty.Session, pkg *EchoPackage) error { - log.Debug("get echo package{%s}", pkg) + log.Debugf("get echo package{%s}", pkg) // write echo message handle logic here. _, _, err := session.WritePkg(pkg, conf.GettySessionParam.waitTimeout) if err != nil { - log.Warn("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) + log.Warnf("session.WritePkg(session{%s}, pkg{%s}) = error{%v}", session.Stat(), pkg, err) session.Close() } return err @@ -90,7 +89,7 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { return err } - log.Info("got session:%s", session.Stat()) + log.Infof("got session:%s", session.Stat()) h.rwlock.Lock() h.sessionMap[session] = &clientEchoSession{session: session} h.rwlock.Unlock() @@ -98,7 +97,7 @@ func (h *EchoMessageHandler) OnOpen(session getty.Session) error { } func (h *EchoMessageHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + log.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) h.rwlock.Lock() delete(h.sessionMap, session) h.rwlock.Unlock() @@ -114,13 +113,13 @@ func (h *EchoMessageHandler) OnClose(session getty.Session) { func (h *EchoMessageHandler) OnMessage(session getty.Session, pkg interface{}) { p, ok := pkg.(*EchoPackage) if !ok { - log.Error("illegal packge{%#v}, %s", pkg, string(pkg.([]byte))) + log.Errorf("illegal packge{%#v}, %s", pkg, string(pkg.([]byte))) return } handler, ok := h.handlers[p.H.Command] if !ok { - log.Error("illegal command{%d}", p.H.Command) + log.Errorf("illegal command{%d}", p.H.Command) return } err := handler.Handle(session, p) @@ -144,7 +143,7 @@ func (h *EchoMessageHandler) OnCron(session getty.Session) { active = session.GetActive() if conf.sessionTimeout.Nanoseconds() < time.Since(active).Nanoseconds() { flag = true - log.Warn("session{%s} timeout{%s}, reqNum{%d}", + log.Warnf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(active).String(), h.sessionMap[session].reqNum) } } diff --git a/examples/echo/wss-echo/server/app/readwriter.go b/examples/echo/wss-echo/server/app/readwriter.go index 7cfb79c4..cd855984 100644 --- a/examples/echo/wss-echo/server/app/readwriter.go +++ b/examples/echo/wss-echo/server/app/readwriter.go @@ -25,7 +25,6 @@ import ( import ( // "github.com/AlexStocks/goext/strings" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -48,7 +47,7 @@ func (h *EchoPackageHandler) Read(ss getty.Session, data []byte) (interface{}, i buf = bytes.NewBuffer(data) len, err = pkg.Unmarshal(buf) - log.Debug("pkg.Read:%#v", pkg) + log.Debugf("pkg.Read:%#v", pkg) if err != nil { if err == ErrNotEnoughStream { return nil, 0, nil @@ -72,17 +71,17 @@ func (h *EchoPackageHandler) Write(ss getty.Session, pkg interface{}) ([]byte, e startTime = time.Now() if echoPkg, ok = pkg.(*EchoPackage); !ok { - log.Error("illegal pkg:%+v\n", pkg) + log.Errorf("illegal pkg:%+v", pkg) return nil, errors.New("invalid echo package!") } buf, err = echoPkg.Marshal() if err != nil { - log.Warn("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) + log.Warnf("binary.Write(echoPkg{%#v}) = err{%#v}", echoPkg, err) return nil, err } - log.Debug("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) + log.Debugf("WriteEchoPkgTimeMs = %s", time.Since(startTime).String()) return buf.Bytes(), nil } diff --git a/examples/echo/wss-echo/server/app/server.go b/examples/echo/wss-echo/server/app/server.go index a88a41fe..9f93a02b 100644 --- a/examples/echo/wss-echo/server/app/server.go +++ b/examples/echo/wss-echo/server/app/server.go @@ -32,9 +32,7 @@ import ( ) import ( - "github.com/AlexStocks/goext/log" "github.com/AlexStocks/goext/net" - log "github.com/AlexStocks/log4go" getty "github.com/apache/dubbo-getty" ) @@ -47,7 +45,10 @@ var ( // ports = flag.String("ports", "12345,12346,12347", "local host port list that the server app will bind") ) -var serverList []getty.Server +var ( + serverList []getty.Server + log = getty.GetLogger() +) func main() { // flag.Parse() @@ -60,9 +61,7 @@ func main() { initProfiling() initServer() - gxlog.CInfo("%s starts successfull! its listen ends=%s:%s:%s\n", - conf.AppName, conf.Host, conf.Ports, conf.Paths) - log.Info("%s starts successfull! its listen ends=%s:%s:%s\n", + log.Infof("%s starts successfull! its listen ends=%s:%s:%s", conf.AppName, conf.Host, conf.Ports, conf.Paths) initSignal() @@ -73,7 +72,7 @@ func initProfiling() { // addr = *host + ":" + "10000" addr = gxnet.HostAddress(conf.Host, conf.ProfilePort) - log.Info("App Profiling startup on address{%v}", addr+pprofPath) + log.Infof("App Profiling startup on address{%v}", addr+pprofPath) go func() { log.Info(http.ListenAndServe(addr, nil)) }() @@ -113,7 +112,7 @@ func newSession(session getty.Session) error { session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout) session.SetCronPeriod((int)(conf.heartbeatPeriod.Nanoseconds() / 1e6)) session.SetWaitTime(conf.GettySessionParam.waitTimeout) - log.Debug("app accepts new session:%s\n", session.Stat()) + log.Debugf("app accepts new session:%s", session.Stat()) return nil } @@ -157,13 +156,13 @@ func initServer() { getty.WithWebsocketServerPrivateKey(conf.KeyFile), getty.WithWebsocketServerRootCert(conf.CACert), ) - log.Debug("server bind addr{wss://%s/%s} ok!", addr, pathList[idx]) + log.Debugf("server bind addr{wss://%s/%s} ok!", addr, pathList[idx]) } else { server = getty.NewWSServer( getty.WithLocalAddress(addr), getty.WithWebsocketServerPath(pathList[idx]), ) - log.Debug("server bind addr{ws://%s/%s} ok!", addr, pathList[idx]) + log.Debugf("server bind addr{ws://%s/%s} ok!", addr, pathList[idx]) } server.RunEventLoop(newSession) // run server @@ -184,7 +183,7 @@ func initSignal() { signal.Notify(signals, os.Interrupt, os.Kill, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals - log.Info("get signal %s", sig.String()) + log.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() @@ -192,15 +191,13 @@ func initSignal() { go time.AfterFunc(conf.failFastTimeout, func() { // log.Warn("app exit now by force...") // os.Exit(1) - log.Exit("app exit now by force...") - log.Close() + log.Info("app exit now by force...") }) // 要么fastFailTimeout时间内执行完毕下面的逻辑然后程序退出,要么执行上面的超时函数程序强行退出 uninitServer() // fmt.Println("app exit now...") - log.Exit("app exit now...") - log.Close() + log.Info("app exit now...") return } } diff --git a/go.mod b/go.mod index 4d5333fd..599372e5 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,14 @@ module github.com/apache/dubbo-getty go 1.14 require ( - github.com/AlexStocks/getty v1.3.0 github.com/AlexStocks/goext v0.3.3 - github.com/AlexStocks/log4go v1.0.6 + github.com/AlexStocks/log4go v1.0.7 // indirect github.com/dubbogo/gost v1.11.20 + github.com/fatih/camelcase v1.0.0 // indirect + github.com/fatih/structs v1.1.0 // indirect github.com/golang/snappy v0.0.1 github.com/gorilla/websocket v1.4.2 + github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff // indirect github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7 github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-isatty v0.0.14 // indirect diff --git a/go.sum b/go.sum index 595ec617..c85ca1b2 100644 --- a/go.sum +++ b/go.sum @@ -11,13 +11,10 @@ cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqCl cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/AlexStocks/getty v1.3.0 h1:x6WOo/0CE64KjGic/kp5XOqFa/BUotOwRTuUuMstyYU= -github.com/AlexStocks/getty v1.3.0/go.mod h1:elww+3/05/5L7zDWbbe42L5a9OJA3s9YgWSR85cy02c= -github.com/AlexStocks/goext v0.3.2/go.mod h1:3M5j9Pjge4CdkNg2WIjRLUeoPedJHHKwkkglDGSl3Hc= github.com/AlexStocks/goext v0.3.3 h1:QWPx9gT3os37u+AgY7syGy3EA5JFK+z3VkYTwL+b6ik= github.com/AlexStocks/goext v0.3.3/go.mod h1:3M5j9Pjge4CdkNg2WIjRLUeoPedJHHKwkkglDGSl3Hc= -github.com/AlexStocks/log4go v1.0.6 h1:PcAtF8bQ0ylIN5GNz4YXPhLkahgye0KjM7xw4vIBtJ0= -github.com/AlexStocks/log4go v1.0.6/go.mod h1:6kCCRo/orDo8mh5CEDOeuSSM674wBQ8M6E0K8dVOIz4= +github.com/AlexStocks/log4go v1.0.7 h1:RmxSkiwlCOELmUpiLSD1V7F8C3xlgkqyhgGZVKB2jsc= +github.com/AlexStocks/log4go v1.0.7/go.mod h1:p7vP0/IAoSu7SLjjSvn4NciqYs//Ylyy/FxE0kmqFUg= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= @@ -35,7 +32,6 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDHxfTGEciD+yhvOU/5s1Rfk= -github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6/go.mod h1:V8iCPQYkqmusNa815XgQio277wI47sdRh1dUOLdyC6Q= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= @@ -73,7 +69,6 @@ github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3Ee github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= @@ -88,7 +83,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dubbogo/go-zookeeper v1.0.3/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4DdC2ENwRb6E+c= -github.com/dubbogo/gost v1.10.0/go.mod h1:+mQGS51XQEUWZP2JeGZTxJwipjRKtJO7Tr+FOg+72rI= github.com/dubbogo/gost v1.11.20 h1:WADtik6Zpl8ExJ/5FG9VuGBebZ7yzDgHbgnjX1v158s= github.com/dubbogo/gost v1.11.20/go.mod h1:vIcP9rqz2KsXHPjsAwIUtfJIJjppQLQDcYaZTy/61jI= github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU= @@ -108,7 +102,6 @@ github.com/fastly/go-utils v0.0.0-20180712184237-d95a45783239/go.mod h1:Gdwt2ce0 github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8= github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/set v0.2.1/go.mod h1:+RKtMCH+favT2+3YecHGxcc0b4KyVWA1QWWJUs4E0CI= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= @@ -175,7 +168,6 @@ github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OI github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= @@ -184,17 +176,14 @@ github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51 github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9GbyCZHuPgZsrbyIbyKhSzOpg6s= github.com/grpc-ecosystem/go-grpc-middleware v1.2.2/go.mod h1:EaizFBKfUKtMIF5iaDEhniwNedqGo9FuLFzppDr3uwI= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/grpc-ecosystem/grpc-gateway v1.13.0/go.mod h1:8XEsbTttt/W+VvjtQhLACqCisSPWTxCZ7sBRjU6iH9c= github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= @@ -238,10 +227,12 @@ github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/juju/errors v0.0.0-20190930114154-d42613fe1ab9 h1:hJix6idebFclqlfZCHE7EUX7uqLCyb70nHNHH1XKGBg= -github.com/juju/errors v0.0.0-20190930114154-d42613fe1ab9/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q= -github.com/juju/loggo v0.0.0-20190526231331-6e530bcce5d8/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= -github.com/juju/testing v0.0.0-20191001232224-ce9dec17d28b/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= +github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff h1:WLHwK6yMswDvGUNrkxp4GYnrbQS8WULu1D3qteVdUIg= +github.com/juju/errors v0.0.0-20210818161939-5560c4c073ff/go.mod h1:i1eL7XREII6aHpQ2gApI/v6FkVUDEBremNkcBCKYAcY= +github.com/juju/loggo v0.0.0-20170605014607-8232ab8918d9 h1:Y+lzErDTURqeXqlqYi4YBYbDd7ycU74gW1ADt57/bgY= +github.com/juju/loggo v0.0.0-20170605014607-8232ab8918d9/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U= +github.com/juju/testing v0.0.0-20180517134105-72703b1e95eb h1:oHBF98WnC1lqCv/W7I7gxnLjD6xJieJ8yt/3IrnMthY= +github.com/juju/testing v0.0.0-20180517134105-72703b1e95eb/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= @@ -278,7 +269,6 @@ github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3 github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= @@ -347,7 +337,6 @@ github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= -github.com/prometheus/client_golang v1.4.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.5.1/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU= @@ -381,7 +370,6 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/shirou/gopsutil v3.20.11-0.20201116082039-2fb5da2f2449+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/gopsutil v3.20.11+incompatible h1:LJr4ZQK4mPpIV5gOa4jCOKOGb4ty4DZO54I4FGqIpto= github.com/shirou/gopsutil v3.20.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= @@ -414,14 +402,12 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tebeka/strftime v0.1.3/go.mod h1:7wJm3dZlpr4l/oVK0t1HYIc4rMzQ2XJlOMIUJUJH6XQ= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20201229170055-e5319fda7802/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/toolkits/concurrent v0.0.0-20150624120057-a4371d70e3e3/go.mod h1:QDlpd3qS71vYtakd2hmdpqhJ9nwv6mD6A30bQ1BPBFE= @@ -433,7 +419,6 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= -go.etcd.io/etcd v0.0.0-20190830150955-898bd1351fcf/go.mod h1:zkTjKtRNVCiLpZfDPZhuB3hSBK2PNzSSagFy7qRzsLU= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.etcd.io/etcd/api/v3 v3.5.0-alpha.0/go.mod h1:mPcW6aZJukV6Aa81LSKpBjQXTWlXB5r74ymPoSWa3Sw= go.etcd.io/etcd/client/v2 v2.305.0-alpha.0/go.mod h1:kdV+xzCJ3luEBSIeQyB/OEKkWKd8Zkux4sbDeANrosU= @@ -461,7 +446,6 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEa go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= -go.uber.org/zap v1.14.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM= go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= @@ -570,7 +554,6 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201223074533-0d417f636930 h1:vRgIt+nup/B/BwIS0g2oC0haq0iqbV3ZA+u6+0TlNCo= golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1 h1:kwrAHlwJ0DUBZwQ238v+Uod/3eZ8B2K5rYsUHBQvzmI= @@ -640,7 +623,6 @@ google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dT google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= @@ -655,7 +637,6 @@ google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ij google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= @@ -674,6 +655,7 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20160105164936-4f90aeace3a2/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= @@ -684,10 +666,12 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= +gopkg.in/mgo.v2 v2.0.0-20160818015218-f2b6f6c918c4 h1:hILp2hNrRnYjZpmIbx70psAHbBSEcQ1NIzDcUbJ1b6g= +gopkg.in/mgo.v2 v2.0.0-20160818015218-f2b6f6c918c4/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.0.0-20170712054546-1be3d31502d6/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/logger.go b/logger.go index 9fb8fa56..cfc3e2f0 100644 --- a/logger.go +++ b/logger.go @@ -38,23 +38,23 @@ type Logger interface { type LoggerLevel int8 const ( - // DebugLevel logs are typically voluminous, and are usually disabled in + // LoggerLevelDebug DebugLevel logs are typically voluminous, and are usually disabled in // production. LoggerLevelDebug = LoggerLevel(zapcore.DebugLevel) - // InfoLevel is the default logging priority. + // LoggerLevelInfo InfoLevel is the default logging priority. LoggerLevelInfo = LoggerLevel(zapcore.InfoLevel) - // WarnLevel logs are more important than Infof, but don't need individual + // LoggerLevelWarn WarnLevel logs are more important than Infof, but don't need individual // human review. LoggerLevelWarn = LoggerLevel(zapcore.WarnLevel) - // ErrorLevel logs are high-priority. If an application is running smoothly, + // LoggerLevelError ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-level logs. LoggerLevelError = LoggerLevel(zapcore.ErrorLevel) - // DPanicLevel logs are particularly important errors. In development the + // LoggerLevelDPanic DPanicLevel logs are particularly important errors. In development the // logger panics after writing the message. LoggerLevelDPanic = LoggerLevel(zapcore.DPanicLevel) - // PanicLevel logs a message, then panics. + // LoggerLevelPanic PanicLevel logs a message, then panics. LoggerLevelPanic = LoggerLevel(zapcore.PanicLevel) - // FatalLevel logs a message, then calls os.Exit(1). + // LoggerLevelFatal FatalLevel logs a message, then calls os.Exit(1). LoggerLevelFatal = LoggerLevel(zapcore.FatalLevel) )