diff --git a/cluster/cluster_impl/failover_cluster_test.go b/cluster/cluster_impl/failover_cluster_test.go index b7009be20effc8b96e9d914dc5b63ce83836493d..5f0a28f0a679c42b6cd5fd2b9a9052a4722c0737 100644 --- a/cluster/cluster_impl/failover_cluster_test.go +++ b/cluster/cluster_impl/failover_cluster_test.go @@ -21,7 +21,6 @@ import ( "testing" ) import ( - log "github.com/AlexStocks/log4go" perrors "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) @@ -32,6 +31,7 @@ import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" "github.com/dubbo/go-for-apache-dubbo/common/extension" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/protocol/invocation" ) @@ -89,7 +89,7 @@ func (bi *MockInvoker) Invoke(invocation protocol.Invocation) protocol.Result { } func (bi *MockInvoker) Destroy() { - log.Info("Destroy invoker: %v", bi.GetUrl().String()) + logger.Infof("Destroy invoker: %v", bi.GetUrl().String()) bi.destroyed = true bi.available = false } diff --git a/common/logger/log.yml b/common/logger/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..427308d52b028d1740dac56b66b2e54fa76c6fe2 --- /dev/null +++ b/common/logger/log.yml @@ -0,0 +1,28 @@ + +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/common/logger/logger.go b/common/logger/logger.go new file mode 100644 index 0000000000000000000000000000000000000000..22fe7329e7601b9e3701ad51c9da2eaa937a7d27 --- /dev/null +++ b/common/logger/logger.go @@ -0,0 +1,117 @@ +// Copyright 2016-2019 Yincheng Fang +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package logger + +import ( + "io/ioutil" + "log" + "os" + "path" +) + +import ( + "github.com/dubbogo/getty" + perrors "github.com/pkg/errors" + "go.uber.org/zap" + "go.uber.org/zap/zapcore" + "gopkg.in/yaml.v2" +) + +import ( + "github.com/dubbo/go-for-apache-dubbo/common/constant" +) + +var ( + logger Logger +) + +type Logger interface { + Info(args ...interface{}) + Warn(args ...interface{}) + Error(args ...interface{}) + Debug(args ...interface{}) + + Infof(fmt string, args ...interface{}) + Warnf(fmt string, args ...interface{}) + Errorf(fmt string, args ...interface{}) + Debugf(fmt string, args ...interface{}) +} + +func init() { + logConfFile := os.Getenv(constant.APP_LOG_CONF_FILE) + err := InitLog(logConfFile) + if err != nil { + log.Printf("[InitLog] error: %v", err) + } +} + +func InitLog(logConfFile string) error { + if logConfFile == "" { + InitLogger(nil) + return perrors.New("log configure file name is nil") + } + if path.Ext(logConfFile) != ".yml" { + InitLogger(nil) + return perrors.Errorf("log configure file name{%s} suffix must be .yml", logConfFile) + } + + confFileStream, err := ioutil.ReadFile(logConfFile) + if err != nil { + InitLogger(nil) + return perrors.Errorf("ioutil.ReadFile(file:%s) = error:%v", logConfFile, err) + } + + conf := &zap.Config{} + err = yaml.Unmarshal(confFileStream, conf) + if err != nil { + InitLogger(nil) + return perrors.Errorf("[Unmarshal]init logger error: %v", err) + } + + InitLogger(conf) + + // set getty log + getty.SetLogger(logger) + return nil +} + +func InitLogger(conf *zap.Config) { + var zapLoggerConfig zap.Config + if conf == nil { + zapLoggerConfig = zap.NewDevelopmentConfig() + zapLoggerEncoderConfig := zapcore.EncoderConfig{ + TimeKey: "time", + LevelKey: "level", + NameKey: "logger", + CallerKey: "caller", + MessageKey: "message", + StacktraceKey: "stacktrace", + EncodeLevel: zapcore.CapitalColorLevelEncoder, + EncodeTime: zapcore.ISO8601TimeEncoder, + EncodeDuration: zapcore.SecondsDurationEncoder, + EncodeCaller: zapcore.ShortCallerEncoder, + } + zapLoggerConfig.EncoderConfig = zapLoggerEncoderConfig + } else { + zapLoggerConfig = *conf + } + zapLogger, _ := zapLoggerConfig.Build() + logger = zapLogger.Sugar() +} + +func SetLogger(log Logger) { + logger = log + getty.SetLogger(logger) +} diff --git a/common/logger/logger_test.go b/common/logger/logger_test.go new file mode 100644 index 0000000000000000000000000000000000000000..9256aa417ae44d1ccdcc82a90abafebdf3581e79 --- /dev/null +++ b/common/logger/logger_test.go @@ -0,0 +1,39 @@ +package logger + +import ( + "github.com/stretchr/testify/assert" + "path/filepath" + "testing" +) + +func TestInitLog(t *testing.T) { + var ( + err error + path string + ) + + err = InitLog("") + assert.EqualError(t, err, "log configure file name is nil") + + path, err = filepath.Abs("./log.xml") + assert.NoError(t, err) + err = InitLog(path) + assert.EqualError(t, err, "log configure file name{"+path+"} suffix must be .yml") + + path, err = filepath.Abs("./logger.yml") + assert.NoError(t, err) + err = InitLog(path) + assert.EqualError(t, err, "ioutil.ReadFile(file:"+path+") = error:open "+path+": no such file or directory") + + err = InitLog("./log.yml") + assert.NoError(t, err) + + Debug("debug") + Info("info") + Warn("warn") + Error("error") + Debugf("%s", "debug") + Infof("%s", "info") + Warnf("%s", "warn") + Errorf("%s", "error") +} diff --git a/common/logger/logging.go b/common/logger/logging.go new file mode 100644 index 0000000000000000000000000000000000000000..57a0e04e42252d343391cbfe04fd4edef92da3f0 --- /dev/null +++ b/common/logger/logging.go @@ -0,0 +1,40 @@ +// Copyright 2016-2019 Yincheng Fang +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package logger + +func Info(args ...interface{}) { + logger.Info(args...) +} +func Warn(args ...interface{}) { + logger.Warn(args...) +} +func Error(args ...interface{}) { + logger.Error(args...) +} +func Debug(args ...interface{}) { + logger.Debug(args...) +} +func Infof(fmt string, args ...interface{}) { + logger.Infof(fmt, args...) +} +func Warnf(fmt string, args ...interface{}) { + logger.Warnf(fmt, args...) +} +func Errorf(fmt string, args ...interface{}) { + logger.Errorf(fmt, args...) +} +func Debugf(fmt string, args ...interface{}) { + logger.Debugf(fmt, args...) +} diff --git a/common/proxy/proxy.go b/common/proxy/proxy.go index a7c0ab8bed7abeebad824824b402285279d66367..033c8687ee25d4ded826b9a6a1315608b7b8c4ab 100644 --- a/common/proxy/proxy.go +++ b/common/proxy/proxy.go @@ -17,12 +17,10 @@ package proxy import ( "reflect" ) -import ( - log "github.com/AlexStocks/log4go" -) import ( "github.com/dubbo/go-for-apache-dubbo/common" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" invocation_impl "github.com/dubbo/go-for-apache-dubbo/protocol/invocation" ) @@ -54,14 +52,14 @@ func (p *Proxy) Implement(v common.RPCService) { // check parameters, incoming interface must be a elem's pointer. valueOf := reflect.ValueOf(v) - log.Debug("[Implement] reflect.TypeOf: %s", valueOf.String()) + logger.Debugf("[Implement] reflect.TypeOf: %s", valueOf.String()) valueOfElem := valueOf.Elem() typeOf := valueOfElem.Type() // check incoming interface, incoming interface's elem must be a struct. if typeOf.Kind() != reflect.Struct { - log.Error("%s must be a struct ptr", valueOf.String()) + logger.Errorf("%s must be a struct ptr", valueOf.String()) return } @@ -113,7 +111,7 @@ func (p *Proxy) Implement(v common.RPCService) { result := p.invoke.Invoke(inv) err = result.Error() - log.Info("[makeDubboCallProxy] result: %v, err: %v", result.Result(), err) + logger.Infof("[makeDubboCallProxy] result: %v, err: %v", result.Result(), err) if len(outs) == 1 { return []reflect.Value{reflect.ValueOf(&err).Elem()} } @@ -137,20 +135,20 @@ func (p *Proxy) Implement(v common.RPCService) { outNum := t.Type.NumOut() if outNum != 1 && outNum != 2 { - log.Warn("method %s of mtype %v has wrong number of in out parameters %d; needs exactly 1/2", + logger.Warnf("method %s of mtype %v has wrong number of in out parameters %d; needs exactly 1/2", t.Name, t.Type.String(), outNum) continue } // The latest return type of the method must be error. if returnType := t.Type.Out(outNum - 1); returnType != typError { - log.Warn("the latest return type %s of method %q is not error", returnType, t.Name) + logger.Warnf("the latest return type %s of method %q is not error", returnType, t.Name) continue } // reply must be Ptr when outNum == 1 if outNum == 1 && t.Type.In(inNum-1).Kind() != reflect.Ptr { - log.Warn("reply type of method %q is not a pointer", t.Name) + logger.Warnf("reply type of method %q is not a pointer", t.Name) continue } @@ -161,7 +159,7 @@ func (p *Proxy) Implement(v common.RPCService) { // do method proxy here: f.Set(reflect.MakeFunc(f.Type(), makeDubboCallProxy(methodName, funcOuts))) - log.Debug("set method [%s]", methodName) + logger.Debugf("set method [%s]", methodName) } } diff --git a/common/rpc_service.go b/common/rpc_service.go index 60679e00dbff0b15d3242858cd5b2533eec2fa11..3a215ab17a7c156fda7d19be3b86255d8ef06138 100644 --- a/common/rpc_service.go +++ b/common/rpc_service.go @@ -24,10 +24,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" perrors "github.com/pkg/errors" ) +import ( + "github.com/dubbo/go-for-apache-dubbo/common/logger" +) + // rpc service interface type RPCService interface { Service() string // Path InterfaceName @@ -128,12 +131,12 @@ func (sm *serviceMap) Register(protocol string, rcvr RPCService) (string, error) sname := reflect.Indirect(s.rcvr).Type().Name() if sname == "" { s := "no service name for type " + s.rcvrType.String() - log.Error(s) + logger.Errorf(s) return "", perrors.New(s) } if !isExported(sname) { s := "type " + sname + " is not exported" - log.Error(s) + logger.Errorf(s) return "", perrors.New(s) } @@ -150,7 +153,7 @@ func (sm *serviceMap) Register(protocol string, rcvr RPCService) (string, error) if len(s.methods) == 0 { s := "type " + sname + " has no exported methods of suitable type" - log.Error(s) + logger.Errorf(s) return "", perrors.New(s) } sm.mutex.Lock() @@ -205,7 +208,7 @@ func isExportedOrBuiltinType(t reflect.Type) bool { func suitableMethods(typ reflect.Type) (string, map[string]*MethodType) { methods := make(map[string]*MethodType) mts := "" - log.Debug("[%s] NumMethod is %d", typ.String(), typ.NumMethod()) + logger.Debugf("[%s] NumMethod is %d", typ.String(), typ.NumMethod()) for m := 0; m < typ.NumMethod(); m++ { method := typ.Method(m) if mt := suiteMethod(method); mt != nil { @@ -238,27 +241,27 @@ func suiteMethod(method reflect.Method) *MethodType { ) if outNum != 1 && outNum != 2 { - log.Warn("method %s of mtype %v has wrong number of in out parameters %d; needs exactly 1/2", + logger.Warnf("method %s of mtype %v has wrong number of in out parameters %d; needs exactly 1/2", mname, mtype.String(), outNum) return nil } // The latest return type of the method must be error. if returnType := mtype.Out(outNum - 1); returnType != typeOfError { - log.Warn("the latest return type %s of method %q is not error", returnType, mname) + logger.Warnf("the latest return type %s of method %q is not error", returnType, mname) return nil } // replyType if outNum == 1 { if mtype.In(inNum-1).Kind() != reflect.Ptr { - log.Error("reply type of method %q is not a pointer %v", mname, replyType) + logger.Errorf("reply type of method %q is not a pointer %v", mname, replyType) return nil } } else { replyType = mtype.Out(0) if !isExportedOrBuiltinType(replyType) { - log.Error("reply type of method %s not exported{%v}", mname, replyType) + logger.Errorf("reply type of method %s not exported{%v}", mname, replyType) return nil } } @@ -275,7 +278,7 @@ func suiteMethod(method reflect.Method) *MethodType { argsType = append(argsType, mtype.In(index)) // need not be a pointer. if !isExportedOrBuiltinType(mtype.In(index)) { - log.Error("argument type of method %q is not exported %v", mname, mtype.In(index)) + logger.Errorf("argument type of method %q is not exported %v", mname, mtype.In(index)) return nil } } diff --git a/config/config_loader.go b/config/config_loader.go index 8e5cf18cff8c140285be826464c416fda6f50f72..32dde08bd1a867f84b937bc1de83456073e563a8 100644 --- a/config/config_loader.go +++ b/config/config_loader.go @@ -17,6 +17,7 @@ package config import ( "fmt" "io/ioutil" + "log" "os" "path" "strings" @@ -24,13 +25,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" perrors "github.com/pkg/errors" "gopkg.in/yaml.v2" ) import ( "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/version" ) @@ -44,10 +45,6 @@ var ( // Namely: dubbo.comsumer.xml & dubbo.provider.xml in java dubbo func init() { - if err := logInit(); err != nil { // log config - log.Warn("[logInit] %#v", err) - } - var ( confConFile, confProFile string ) @@ -56,32 +53,13 @@ func init() { confProFile = os.Getenv(constant.CONF_PROVIDER_FILE_PATH) if errCon := consumerInit(confConFile); errCon != nil { - log.Warn("[consumerInit] %#v", errCon) + log.Printf("[consumerInit] %#v", errCon) consumerConfig = nil } if errPro := providerInit(confProFile); errPro != nil { - log.Warn("[providerInit] %#v", errPro) + log.Printf("[providerInit] %#v", errPro) providerConfig = nil } - -} - -func logInit() error { - var ( - confFile string - ) - - confFile = os.Getenv(constant.APP_LOG_CONF_FILE) - if confFile == "" { - return perrors.Errorf("log configure file name is nil") - } - if path.Ext(confFile) != ".xml" { - return perrors.Errorf("log configure file name{%v} suffix must be .xml", confFile) - } - - log.LoadConfiguration(confFile) - - return nil } func consumerInit(confConFile string) error { @@ -110,7 +88,7 @@ func consumerInit(confConFile string) error { return perrors.WithMessagef(err, "time.ParseDuration(Connect_Timeout{%#v})", consumerConfig.Connect_Timeout) } - log.Debug("consumer config{%#v}\n", consumerConfig) + logger.Debugf("consumer config{%#v}\n", consumerConfig) return nil } @@ -133,7 +111,7 @@ func providerInit(confProFile string) error { return perrors.Errorf("yaml.Unmarshal() = error:%v", perrors.WithStack(err)) } - log.Debug("provider config{%#v}\n", providerConfig) + logger.Debugf("provider config{%#v}\n", providerConfig) return nil } @@ -170,7 +148,7 @@ func SetConsumerConfig(c ConsumerConfig) { } func GetConsumerConfig() ConsumerConfig { if consumerConfig == nil { - log.Warn("consumerConfig is nil!") + logger.Warnf("consumerConfig is nil!") return ConsumerConfig{} } return *consumerConfig @@ -193,7 +171,7 @@ type ProviderConfig struct { func GetProviderConfig() ProviderConfig { if providerConfig == nil { - log.Warn("providerConfig is nil!") + logger.Warnf("providerConfig is nil!") return ProviderConfig{} } return *providerConfig @@ -226,7 +204,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) { // reference config if consumerConfig == nil { - log.Warn("consumerConfig is nil!") + logger.Warnf("consumerConfig is nil!") } else { refMap = make(map[string]*ReferenceConfig) length := len(consumerConfig.References) @@ -234,7 +212,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) { con := &consumerConfig.References[index] rpcService := GetConsumerService(con.InterfaceName) if rpcService == nil { - log.Warn("%s is not exsist!", con.InterfaceName) + logger.Warnf("%s is not exsist!", con.InterfaceName) continue } con.Refer() @@ -262,7 +240,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) { break } if refconfig.invoker == nil { - log.Warn("The interface %s invoker not exsist , may you should check your interface config.", refconfig.InterfaceName) + logger.Warnf("The interface %s invoker not exsist , may you should check your interface config.", refconfig.InterfaceName) } } } @@ -275,7 +253,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) { // service config if providerConfig == nil { - log.Warn("providerConfig is nil!") + logger.Warnf("providerConfig is nil!") } else { srvMap = make(map[string]*ServiceConfig) length := len(providerConfig.Services) @@ -283,7 +261,7 @@ func Load() (map[string]*ReferenceConfig, map[string]*ServiceConfig) { pro := &providerConfig.Services[index] rpcService := GetProviderService(pro.InterfaceName) if rpcService == nil { - log.Warn("%s is not exsist!", pro.InterfaceName) + logger.Warnf("%s is not exsist!", pro.InterfaceName) continue } pro.Implement(rpcService) diff --git a/config/registry_config.go b/config/registry_config.go index 844c4b3f88b4f79c5cd28be7759b4b179aefa8a1..550b73544fa055b044d5bb4305bdd3624beefd67 100644 --- a/config/registry_config.go +++ b/config/registry_config.go @@ -19,13 +19,11 @@ import ( "net/url" "strconv" ) -import ( - log "github.com/AlexStocks/log4go" -) import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" ) type RegistryConfig struct { @@ -50,7 +48,7 @@ func loadRegistries(registriesIds []ConfigRegistry, registries []RegistryConfig, ) if err != nil { - log.Error("The registry id:%s url is invalid ,and will skip the registry, error: %#v", registryConf.Id, err) + logger.Errorf("The registry id:%s url is invalid ,and will skip the registry, error: %#v", registryConf.Id, err) } else { urls = append(urls, &url) } diff --git a/config/service_config.go b/config/service_config.go index 0dcb1cecc7bbf5f8b93be39f38e66e8516ccfa3c..0391a17dd1ef397870ad2fb8288a9b5cbab35bfd 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -23,7 +23,6 @@ import ( "time" ) import ( - log "github.com/AlexStocks/log4go" perrors "github.com/pkg/errors" "go.uber.org/atomic" ) @@ -31,6 +30,7 @@ import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" "github.com/dubbo/go-for-apache-dubbo/common/extension" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" ) @@ -74,11 +74,11 @@ func (srvconfig *ServiceConfig) Export() error { //TODO:delay export if srvconfig.unexported != nil && srvconfig.unexported.Load() { err := perrors.Errorf("The service %v has already unexported! ", srvconfig.InterfaceName) - log.Error(err.Error()) + logger.Errorf(err.Error()) return err } if srvconfig.unexported != nil && srvconfig.exported.Load() { - log.Warn("The service %v has already exported! ", srvconfig.InterfaceName) + logger.Warnf("The service %v has already exported! ", srvconfig.InterfaceName) return nil } @@ -90,7 +90,7 @@ func (srvconfig *ServiceConfig) Export() error { methods, err := common.ServiceMap.Register(proto.Name, srvconfig.rpcService) if err != nil { err := perrors.Errorf("The service %v export the protocol %v error! Error message is %v .", srvconfig.InterfaceName, proto.Name, err.Error()) - log.Error(err.Error()) + logger.Errorf(err.Error()) return err } //contextPath := proto.ContextPath @@ -109,7 +109,7 @@ func (srvconfig *ServiceConfig) Export() error { srvconfig.cacheMutex.Lock() if srvconfig.cacheProtocol == nil { - log.Info("First load the registry protocol!") + logger.Infof("First load the registry protocol!") srvconfig.cacheProtocol = extension.GetProtocol("registry") } srvconfig.cacheMutex.Unlock() diff --git a/examples/dubbo/go-client/app/client.go b/examples/dubbo/go-client/app/client.go index 6d99695d57182b66fb1b852d7dca0b0e0d50eb7a..5231457f7d21cc62b93a630df24584743832b980 100644 --- a/examples/dubbo/go-client/app/client.go +++ b/examples/dubbo/go-client/app/client.go @@ -24,7 +24,7 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbogo/hessian2" ) @@ -108,13 +108,13 @@ func initSignal() { syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals - log.Info("get signal %s", sig.String()) + logger.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() default: go time.AfterFunc(time.Duration(survivalTimeout)*time.Second, func() { - log.Warn("app exit now by force...") + logger.Warnf("app exit now by force...") os.Exit(1) }) diff --git a/examples/dubbo/go-client/assembly/common/app.properties b/examples/dubbo/go-client/assembly/common/app.properties index a4fe0dc49c83e7c180408b02010ebf4bbefc98a9..6bbd6db850ceeaf5ff873fee01a3578237cbd557 100644 --- a/examples/dubbo/go-client/assembly/common/app.properties +++ b/examples/dubbo/go-client/assembly/common/app.properties @@ -14,4 +14,4 @@ export TARGET_EXEC_NAME="user_info_client" export BUILD_PACKAGE="app" export TARGET_CONF_FILE="conf/client.yml" -export TARGET_LOG_CONF_FILE="conf/log.xml" +export TARGET_LOG_CONF_FILE="conf/log.yml" diff --git a/examples/dubbo/go-client/profiles/dev/log.xml b/examples/dubbo/go-client/profiles/dev/log.xml deleted file mode 100644 index d2a0d89394aa2b5a882924752d9b7bab7f424dc7..0000000000000000000000000000000000000000 --- a/examples/dubbo/go-client/profiles/dev/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="true"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>DEBUG</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="true"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/dubbo/go-client/profiles/dev/log.yml b/examples/dubbo/go-client/profiles/dev/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..427308d52b028d1740dac56b66b2e54fa76c6fe2 --- /dev/null +++ b/examples/dubbo/go-client/profiles/dev/log.yml @@ -0,0 +1,28 @@ + +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/dubbo/go-client/profiles/release/log.xml b/examples/dubbo/go-client/profiles/release/log.xml deleted file mode 100644 index 834bab5b07e72f1c250d500b60fe3af25e74cfc1..0000000000000000000000000000000000000000 --- a/examples/dubbo/go-client/profiles/release/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="false"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>DEBUG</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="false"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="false"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/dubbo/go-client/profiles/release/log.yml b/examples/dubbo/go-client/profiles/release/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..b9139c2e9cb21d5f557eb53e5d6909fca64ac205 --- /dev/null +++ b/examples/dubbo/go-client/profiles/release/log.yml @@ -0,0 +1,28 @@ + +level: "warn" +development: true +disableCaller: true +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/dubbo/go-client/profiles/test/log.xml b/examples/dubbo/go-client/profiles/test/log.xml deleted file mode 100644 index 57d4dee915dbd9c38ce0bab41a5548c729d0a8dd..0000000000000000000000000000000000000000 --- a/examples/dubbo/go-client/profiles/test/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="true"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>INFO</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="false"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/dubbo/go-client/profiles/test/log.yml b/examples/dubbo/go-client/profiles/test/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..d2e1d05f3f46bc4ec6c7b8a16211c13d2189219d --- /dev/null +++ b/examples/dubbo/go-client/profiles/test/log.yml @@ -0,0 +1,28 @@ + +level: "info" +development: false +disableCaller: false +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/dubbo/go-server/app/server.go b/examples/dubbo/go-server/app/server.go index f8de7da0d315b52d750476a44a2cf9d5e13c1985..1c0d2c2c7391a417177332ab7341d80ade7a4faf 100644 --- a/examples/dubbo/go-server/app/server.go +++ b/examples/dubbo/go-server/app/server.go @@ -23,7 +23,7 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbogo/hessian2" ) @@ -69,13 +69,13 @@ 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()) + logger.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() default: go time.AfterFunc(time.Duration(float64(survivalTimeout)*float64(time.Second)), func() { - log.Warn("app exit now by force...") + logger.Warnf("app exit now by force...") os.Exit(1) }) diff --git a/examples/dubbo/go-server/assembly/common/app.properties b/examples/dubbo/go-server/assembly/common/app.properties index d230d5efc4ee84c4a99e1b27e7b49d97046d91a3..dffb755b0811dd140d3f04e232f5f80ff60181df 100644 --- a/examples/dubbo/go-server/assembly/common/app.properties +++ b/examples/dubbo/go-server/assembly/common/app.properties @@ -14,4 +14,4 @@ TARGET_EXEC_NAME="user_info_server" BUILD_PACKAGE="app" TARGET_CONF_FILE="conf/server.yml" -TARGET_LOG_CONF_FILE="conf/log.xml" +TARGET_LOG_CONF_FILE="conf/log.yml" diff --git a/examples/dubbo/go-server/profiles/dev/log.xml b/examples/dubbo/go-server/profiles/dev/log.xml deleted file mode 100644 index d2a0d89394aa2b5a882924752d9b7bab7f424dc7..0000000000000000000000000000000000000000 --- a/examples/dubbo/go-server/profiles/dev/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="true"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>DEBUG</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="true"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/dubbo/go-server/profiles/dev/log.yml b/examples/dubbo/go-server/profiles/dev/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..427308d52b028d1740dac56b66b2e54fa76c6fe2 --- /dev/null +++ b/examples/dubbo/go-server/profiles/dev/log.yml @@ -0,0 +1,28 @@ + +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/dubbo/go-server/profiles/release/log.xml b/examples/dubbo/go-server/profiles/release/log.xml deleted file mode 100644 index 834bab5b07e72f1c250d500b60fe3af25e74cfc1..0000000000000000000000000000000000000000 --- a/examples/dubbo/go-server/profiles/release/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="false"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>DEBUG</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="false"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="false"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/dubbo/go-server/profiles/release/log.yml b/examples/dubbo/go-server/profiles/release/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..b9139c2e9cb21d5f557eb53e5d6909fca64ac205 --- /dev/null +++ b/examples/dubbo/go-server/profiles/release/log.yml @@ -0,0 +1,28 @@ + +level: "warn" +development: true +disableCaller: true +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/dubbo/go-server/profiles/test/log.xml b/examples/dubbo/go-server/profiles/test/log.xml deleted file mode 100644 index 57d4dee915dbd9c38ce0bab41a5548c729d0a8dd..0000000000000000000000000000000000000000 --- a/examples/dubbo/go-server/profiles/test/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="true"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>INFO</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="false"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/dubbo/go-server/profiles/test/log.yml b/examples/dubbo/go-server/profiles/test/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..d2e1d05f3f46bc4ec6c7b8a16211c13d2189219d --- /dev/null +++ b/examples/dubbo/go-server/profiles/test/log.yml @@ -0,0 +1,28 @@ + +level: "info" +development: false +disableCaller: false +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/jsonrpc/go-client/app/client.go b/examples/jsonrpc/go-client/app/client.go index e9e9638895cb41c5e4cb13090436abb9419babd9..b693d05eef7d2db57489d4d382fc265e658ab5e6 100644 --- a/examples/jsonrpc/go-client/app/client.go +++ b/examples/jsonrpc/go-client/app/client.go @@ -24,7 +24,7 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/go-for-apache-dubbo/common/logger" ) import ( @@ -104,13 +104,13 @@ func initSignal() { syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT) for { sig := <-signals - log.Info("get signal %s", sig.String()) + logger.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() default: go time.AfterFunc(time.Duration(survivalTimeout)*time.Second, func() { - log.Warn("app exit now by force...") + logger.Warnf("app exit now by force...") os.Exit(1) }) diff --git a/examples/jsonrpc/go-client/assembly/common/app.properties b/examples/jsonrpc/go-client/assembly/common/app.properties index a4fe0dc49c83e7c180408b02010ebf4bbefc98a9..6bbd6db850ceeaf5ff873fee01a3578237cbd557 100644 --- a/examples/jsonrpc/go-client/assembly/common/app.properties +++ b/examples/jsonrpc/go-client/assembly/common/app.properties @@ -14,4 +14,4 @@ export TARGET_EXEC_NAME="user_info_client" export BUILD_PACKAGE="app" export TARGET_CONF_FILE="conf/client.yml" -export TARGET_LOG_CONF_FILE="conf/log.xml" +export TARGET_LOG_CONF_FILE="conf/log.yml" diff --git a/examples/jsonrpc/go-client/profiles/dev/log.xml b/examples/jsonrpc/go-client/profiles/dev/log.xml deleted file mode 100644 index d2a0d89394aa2b5a882924752d9b7bab7f424dc7..0000000000000000000000000000000000000000 --- a/examples/jsonrpc/go-client/profiles/dev/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="true"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>DEBUG</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="true"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/jsonrpc/go-client/profiles/dev/log.yml b/examples/jsonrpc/go-client/profiles/dev/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..427308d52b028d1740dac56b66b2e54fa76c6fe2 --- /dev/null +++ b/examples/jsonrpc/go-client/profiles/dev/log.yml @@ -0,0 +1,28 @@ + +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/jsonrpc/go-client/profiles/release/log.xml b/examples/jsonrpc/go-client/profiles/release/log.xml deleted file mode 100644 index 834bab5b07e72f1c250d500b60fe3af25e74cfc1..0000000000000000000000000000000000000000 --- a/examples/jsonrpc/go-client/profiles/release/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="false"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>DEBUG</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="false"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="false"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/jsonrpc/go-client/profiles/release/log.yml b/examples/jsonrpc/go-client/profiles/release/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..b9139c2e9cb21d5f557eb53e5d6909fca64ac205 --- /dev/null +++ b/examples/jsonrpc/go-client/profiles/release/log.yml @@ -0,0 +1,28 @@ + +level: "warn" +development: true +disableCaller: true +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/jsonrpc/go-client/profiles/test/log.xml b/examples/jsonrpc/go-client/profiles/test/log.xml deleted file mode 100644 index 57d4dee915dbd9c38ce0bab41a5548c729d0a8dd..0000000000000000000000000000000000000000 --- a/examples/jsonrpc/go-client/profiles/test/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="true"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>INFO</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="false"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/jsonrpc/go-client/profiles/test/log.yml b/examples/jsonrpc/go-client/profiles/test/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..d2e1d05f3f46bc4ec6c7b8a16211c13d2189219d --- /dev/null +++ b/examples/jsonrpc/go-client/profiles/test/log.yml @@ -0,0 +1,28 @@ + +level: "info" +development: false +disableCaller: false +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/jsonrpc/go-server/app/server.go b/examples/jsonrpc/go-server/app/server.go index 2373692d1dda085342e9013ce4054c10fe030137..90c78413c45b54aa883868b140290f22802ebd15 100644 --- a/examples/jsonrpc/go-server/app/server.go +++ b/examples/jsonrpc/go-server/app/server.go @@ -23,10 +23,7 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" -) - -import ( + "github.com/dubbo/go-for-apache-dubbo/common/logger" _ "github.com/dubbo/go-for-apache-dubbo/common/proxy/proxy_factory" "github.com/dubbo/go-for-apache-dubbo/config" _ "github.com/dubbo/go-for-apache-dubbo/protocol/jsonrpc" @@ -62,13 +59,13 @@ 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()) + logger.Infof("get signal %s", sig.String()) switch sig { case syscall.SIGHUP: // reload() default: go time.AfterFunc(time.Duration(float64(survivalTimeout)*float64(time.Second)), func() { - log.Warn("app exit now by force...") + logger.Warnf("app exit now by force...") os.Exit(1) }) diff --git a/examples/jsonrpc/go-server/assembly/common/app.properties b/examples/jsonrpc/go-server/assembly/common/app.properties index d230d5efc4ee84c4a99e1b27e7b49d97046d91a3..dffb755b0811dd140d3f04e232f5f80ff60181df 100644 --- a/examples/jsonrpc/go-server/assembly/common/app.properties +++ b/examples/jsonrpc/go-server/assembly/common/app.properties @@ -14,4 +14,4 @@ TARGET_EXEC_NAME="user_info_server" BUILD_PACKAGE="app" TARGET_CONF_FILE="conf/server.yml" -TARGET_LOG_CONF_FILE="conf/log.xml" +TARGET_LOG_CONF_FILE="conf/log.yml" diff --git a/examples/jsonrpc/go-server/profiles/dev/log.xml b/examples/jsonrpc/go-server/profiles/dev/log.xml deleted file mode 100644 index d2a0d89394aa2b5a882924752d9b7bab7f424dc7..0000000000000000000000000000000000000000 --- a/examples/jsonrpc/go-server/profiles/dev/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="true"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>DEBUG</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="true"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/jsonrpc/go-server/profiles/dev/log.yml b/examples/jsonrpc/go-server/profiles/dev/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..427308d52b028d1740dac56b66b2e54fa76c6fe2 --- /dev/null +++ b/examples/jsonrpc/go-server/profiles/dev/log.yml @@ -0,0 +1,28 @@ + +level: "debug" +development: true +disableCaller: false +disableStacktrace: false +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/jsonrpc/go-server/profiles/release/log.xml b/examples/jsonrpc/go-server/profiles/release/log.xml deleted file mode 100644 index 834bab5b07e72f1c250d500b60fe3af25e74cfc1..0000000000000000000000000000000000000000 --- a/examples/jsonrpc/go-server/profiles/release/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="false"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>DEBUG</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="false"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="false"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/jsonrpc/go-server/profiles/release/log.yml b/examples/jsonrpc/go-server/profiles/release/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..b9139c2e9cb21d5f557eb53e5d6909fca64ac205 --- /dev/null +++ b/examples/jsonrpc/go-server/profiles/release/log.yml @@ -0,0 +1,28 @@ + +level: "warn" +development: true +disableCaller: true +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/examples/jsonrpc/go-server/profiles/test/log.xml b/examples/jsonrpc/go-server/profiles/test/log.xml deleted file mode 100644 index 57d4dee915dbd9c38ce0bab41a5548c729d0a8dd..0000000000000000000000000000000000000000 --- a/examples/jsonrpc/go-server/profiles/test/log.xml +++ /dev/null @@ -1,73 +0,0 @@ -<logging> - <filter enabled="true"> - <tag>stdout</tag> - <type>console</type> - <!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) --> - <level>INFO</level> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] (%S) %M</property> <!-- log format, if json is false this option is enable --> - </filter> - <filter enabled="false"> - <tag>debug_file</tag> - <type>file</type> - <level>DEBUG</level> - <property name="filename">logs/debug.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>info_file</tag> - <type>file</type> - <level>INFO</level> - <property name="filename">logs/info.log</property> - <!-- - %T - Time (15:04:05 MST) - %t - Time (15:04) - %D - Date (2006/01/02) - %d - Date (01/02/06) - %L - Level (FNST, FINE, DEBG, TRAC, WARN, EROR, CRIT) - %S - Source - %M - Message - It ignores unknown format strings (and removes them) - Recommended: "[%D %T] [%L] (%S) %M" - --> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>warn_file</tag> - <type>file</type> - <level>WARNING</level> - <property name="filename">logs/warn.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> - <filter enabled="true"> - <tag>error_file</tag> - <type>file</type> - <level>ERROR</level> - <property name="filename">logs/error.log</property> - <property name="json">false</property> <!-- true enables json log format, its priority is high than format --> - <property name="format">[%D %T] [%L] [%S] %M</property> - <property name="rotate">true</property> <!-- true enables log rotation, otherwise append --> - <property name="maxsize">0M</property> <!-- \d+[KMG]? Suffixes are in terms of 2**10 --> - <property name="maxlines">0K</property> <!-- \d+[KMG]? Suffixes are in terms of thousands --> - <property name="maxbackup">16</property> <!-- \d+ --> - <property name="daily">true</property> <!-- Automatically rotates when a log message is written after midnight --> - </filter> -</logging> diff --git a/examples/jsonrpc/go-server/profiles/test/log.yml b/examples/jsonrpc/go-server/profiles/test/log.yml new file mode 100644 index 0000000000000000000000000000000000000000..d2e1d05f3f46bc4ec6c7b8a16211c13d2189219d --- /dev/null +++ b/examples/jsonrpc/go-server/profiles/test/log.yml @@ -0,0 +1,28 @@ + +level: "info" +development: false +disableCaller: false +disableStacktrace: true +sampling: +encoding: "console" + +# encoder +encoderConfig: + messageKey: "message" + levelKey: "level" + timeKey: "time" + nameKey: "logger" + callerKey: "caller" + stacktraceKey: "stacktrace" + lineEnding: "" + levelEncoder: "capitalColor" + timeEncoder: "iso8601" + durationEncoder: "seconds" + callerEncoder: "short" + nameEncoder: "" + +outputPaths: +- "stderr" +errorOutputPaths: +- "stderr" +initialFields: diff --git a/filter/impl/echo_filter.go b/filter/impl/echo_filter.go index 283d61eb90df1a1a19ce455ddaa770d19803c3ff..22ac6abeef6981c50fcec46ca55a7e6edf47bc08 100644 --- a/filter/impl/echo_filter.go +++ b/filter/impl/echo_filter.go @@ -15,7 +15,7 @@ package impl import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/go-for-apache-dubbo/common/logger" ) import ( @@ -38,8 +38,8 @@ type EchoFilter struct { } func (ef *EchoFilter) Invoke(invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result { - log.Info("invoking echo filter.") - log.Debug("%v,%v", invocation.MethodName(), len(invocation.Arguments())) + logger.Infof("invoking echo filter.") + logger.Debugf("%v,%v", invocation.MethodName(), len(invocation.Arguments())) if invocation.MethodName() == constant.ECHO && len(invocation.Arguments()) == 1 { return &protocol.RPCResult{ Rest: invocation.Arguments()[0], diff --git a/go.mod b/go.mod index 69bdddb4a6f1dc553267d6bc1691298766b4e1f7..e41f9906871337b822fd19ce18b91059420f38de 100644 --- a/go.mod +++ b/go.mod @@ -1,14 +1,12 @@ module github.com/dubbo/go-for-apache-dubbo require ( - github.com/AlexStocks/log4go v1.0.2 github.com/dubbogo/getty v0.0.0-20190523180329-bdf5e640ea53 github.com/dubbogo/hessian2 v0.0.0-20190521184416-2dbe10487e1d - github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 // indirect - github.com/mattn/go-isatty v0.0.8 // indirect github.com/pkg/errors v0.8.1 github.com/samuel/go-zookeeper v0.0.0-20180130194729-c4fab1ac1bec github.com/stretchr/testify v1.3.0 go.uber.org/atomic v1.4.0 + go.uber.org/zap v1.10.0 gopkg.in/yaml.v2 v2.2.2 ) diff --git a/go.sum b/go.sum index c2e7a9587da1ef54b9d09f12a20c4c5c19038ec5..d53a88c491d4d2f8d6d6fe7626d0bb829eb86a6c 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/AlexStocks/log4go v1.0.2 h1:1K5WM8KjSUECaoXUl8FSF05KGeCJDfBrhKUBsxwUvhk= -github.com/AlexStocks/log4go v1.0.2/go.mod h1:6kCCRo/orDo8mh5CEDOeuSSM674wBQ8M6E0K8dVOIz4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -14,10 +12,6 @@ github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983 h1:wL11wNW7dhKIcRCHSm4sHKPWz0tt4mwBsVodG7+Xyqg= -github.com/mailru/easyjson v0.0.0-20190403194419-1ea4449da983/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= -github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -44,10 +38,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53 h1:kcXqo9vE6fsZY5X5Rd7R1l7fTgnWaDCVmln65REefiE= golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/protocol/dubbo/client.go b/protocol/dubbo/client.go index b76e779a8596c0aa8a8698dacad045249bb80549..ff094eb5aaa1af8d2ffa6a6c210574303e9052f2 100644 --- a/protocol/dubbo/client.go +++ b/protocol/dubbo/client.go @@ -21,7 +21,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" "github.com/dubbogo/getty" "github.com/dubbogo/hessian2" perrors "github.com/pkg/errors" @@ -32,6 +31,7 @@ import ( import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/config" ) @@ -50,12 +50,12 @@ func init() { // load clientconfig from consumer_config protocolConf := config.GetConsumerConfig().ProtocolConf if protocolConf == nil { - log.Warn("protocol_conf is nil") + logger.Warnf("protocol_conf is nil") return } dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO] if protocolConf == nil { - log.Warn("dubboConf is nil") + logger.Warnf("dubboConf is nil") return } @@ -70,7 +70,7 @@ func init() { } if err := conf.CheckValidity(); err != nil { - log.Warn(err) + logger.Warnf("[CheckValidity] error: %v", err) return } @@ -240,7 +240,7 @@ func (c *Client) call(ct CallType, addr string, svcUrl common.URL, method string ) conn, session, err = c.selectSession(addr) if err != nil || session == nil { - log.Warn(err) + logger.Warnf("%s, %v", errSessionNotExist.Error(), err) return errSessionNotExist } defer c.pool.release(conn, err) diff --git a/protocol/dubbo/dubbo_exporter.go b/protocol/dubbo/dubbo_exporter.go index 79f7f0c7af660119260a653320b4644708edd027..d76ee812f1f21a29d391e404b2d68517f40bd4bc 100644 --- a/protocol/dubbo/dubbo_exporter.go +++ b/protocol/dubbo/dubbo_exporter.go @@ -18,13 +18,10 @@ import ( "sync" ) -import ( - log "github.com/AlexStocks/log4go" -) - import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" ) @@ -43,6 +40,6 @@ func (de *DubboExporter) Unexport() { de.BaseExporter.Unexport() err := common.ServiceMap.UnRegister(DUBBO, service) if err != nil { - log.Error("[DubboExporter.Unexport] error: %v", err) + logger.Errorf("[DubboExporter.Unexport] error: %v", err) } } diff --git a/protocol/dubbo/dubbo_invoker.go b/protocol/dubbo/dubbo_invoker.go index ada7f78542102869b26f459f82a47bbc847c5ffa..690e4d9b9a476eb832adcedd41f7ddb5ba52939f 100644 --- a/protocol/dubbo/dubbo_invoker.go +++ b/protocol/dubbo/dubbo_invoker.go @@ -20,13 +20,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" perrors "github.com/pkg/errors" ) import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" invocation_impl "github.com/dubbo/go-for-apache-dubbo/protocol/invocation" ) @@ -58,7 +58,7 @@ func (di *DubboInvoker) Invoke(invocation protocol.Invocation) protocol.Result { // async async, err := strconv.ParseBool(inv.AttachmentsByKey(constant.ASYNC_KEY, "false")) if err != nil { - log.Error("ParseBool - error: %v", err) + logger.Errorf("ParseBool - error: %v", err) async = false } if async { @@ -77,7 +77,7 @@ func (di *DubboInvoker) Invoke(invocation protocol.Invocation) protocol.Result { if result.Err == nil { result.Rest = inv.Reply() } - log.Debug("result.Err: %v, result.Rest: %v", result.Err, result.Rest) + logger.Debugf("result.Err: %v, result.Rest: %v", result.Err, result.Rest) return &result } diff --git a/protocol/dubbo/dubbo_protocol.go b/protocol/dubbo/dubbo_protocol.go index 48b77b5b3ab37a6423759542f3579a5f09f186e2..512ca099dd8138261e7b50e5cfc07abec273e2d3 100644 --- a/protocol/dubbo/dubbo_protocol.go +++ b/protocol/dubbo/dubbo_protocol.go @@ -14,13 +14,10 @@ package dubbo -import ( - log "github.com/AlexStocks/log4go" -) - import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/extension" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" ) @@ -49,7 +46,7 @@ func (dp *DubboProtocol) Export(invoker protocol.Invoker) protocol.Exporter { serviceKey := url.Key() exporter := NewDubboExporter(serviceKey, invoker, dp.ExporterMap()) dp.SetExporterMap(serviceKey, exporter) - log.Info("Export service: %s", url.String()) + logger.Infof("Export service: %s", url.String()) // start server dp.openServer(url) @@ -59,12 +56,12 @@ func (dp *DubboProtocol) Export(invoker protocol.Invoker) protocol.Exporter { func (dp *DubboProtocol) Refer(url common.URL) protocol.Invoker { invoker := NewDubboInvoker(url, NewClient()) dp.SetInvokers(invoker) - log.Info("Refer service: %s", url.String()) + logger.Infof("Refer service: %s", url.String()) return invoker } func (dp *DubboProtocol) Destroy() { - log.Info("DubboProtocol destroy.") + logger.Infof("DubboProtocol destroy.") dp.BaseProtocol.Destroy() diff --git a/protocol/dubbo/listener.go b/protocol/dubbo/listener.go index 4e327466ee6e9cebbd3306ecb687c0fd8537da83..fc56050c12a196753aac606dbbc8a801e7e79040 100644 --- a/protocol/dubbo/listener.go +++ b/protocol/dubbo/listener.go @@ -22,7 +22,6 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" "github.com/dubbogo/getty" "github.com/dubbogo/hessian2" perrors "github.com/pkg/errors" @@ -31,6 +30,7 @@ import ( import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/protocol/invocation" ) @@ -65,27 +65,27 @@ func (h *RpcClientHandler) OnOpen(session getty.Session) error { } func (h *RpcClientHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + logger.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) h.conn.removeSession(session) } func (h *RpcClientHandler) OnClose(session getty.Session) { - log.Info("session{%s} is closing......", session.Stat()) + logger.Infof("session{%s} is closing......", session.Stat()) h.conn.removeSession(session) } func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) { p, ok := pkg.(*DubboPackage) if !ok { - log.Error("illegal package") + logger.Errorf("illegal package") return } if p.Header.Type&hessian.PackageHeartbeat != 0x00 { - log.Debug("get rpc heartbeat response{header: %#v, body: %#v}", p.Header, p.Body) + logger.Debugf("get rpc heartbeat response{header: %#v, body: %#v}", p.Header, p.Body) return } - log.Debug("get rpc response{header: %#v, body: %#v}", p.Header, p.Body) + logger.Debugf("get rpc response{header: %#v, body: %#v}", p.Header, p.Body) h.conn.updateSession(session) @@ -108,12 +108,12 @@ func (h *RpcClientHandler) OnMessage(session getty.Session, pkg interface{}) { func (h *RpcClientHandler) OnCron(session getty.Session) { rpcSession, err := h.conn.getClientRpcSession(session) if err != nil { - log.Error("client.getClientSession(session{%s}) = error{%v}", + logger.Errorf("client.getClientSession(session{%s}) = error{%v}", session.Stat(), perrors.WithStack(err)) return } if h.conn.pool.rpcClient.conf.sessionTimeout.Nanoseconds() < time.Since(session.GetActive()).Nanoseconds() { - log.Warn("session{%s} timeout{%s}, reqNum{%d}", + logger.Warnf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(session.GetActive()).String(), rpcSession.reqNum) h.conn.removeSession(session) // -> h.conn.close() -> h.conn.pool.remove(h.conn) return @@ -154,7 +154,7 @@ func (h *RpcServerHandler) OnOpen(session getty.Session) error { return perrors.WithStack(err) } - log.Info("got session:%s", session.Stat()) + logger.Infof("got session:%s", session.Stat()) h.rwlock.Lock() h.sessionMap[session] = &rpcSession{session: session} h.rwlock.Unlock() @@ -162,14 +162,14 @@ func (h *RpcServerHandler) OnOpen(session getty.Session) error { } func (h *RpcServerHandler) OnError(session getty.Session, err error) { - log.Info("session{%s} got error{%v}, will be closed.", session.Stat(), err) + logger.Infof("session{%s} got error{%v}, will be closed.", session.Stat(), err) h.rwlock.Lock() delete(h.sessionMap, session) h.rwlock.Unlock() } func (h *RpcServerHandler) OnClose(session getty.Session) { - log.Info("session{%s} is closing......", session.Stat()) + logger.Infof("session{%s} is closing......", session.Stat()) h.rwlock.Lock() delete(h.sessionMap, session) h.rwlock.Unlock() @@ -184,14 +184,14 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) { p, ok := pkg.(*DubboPackage) if !ok { - log.Error("illegal packge{%#v}", pkg) + logger.Errorf("illegal packge{%#v}", pkg) return } p.Header.ResponseStatus = hessian.Response_OK // heartbeat if p.Header.Type&hessian.PackageHeartbeat != 0x00 { - log.Debug("get rpc heartbeat request{header: %#v, service: %#v, body: %#v}", p.Header, p.Service, p.Body) + logger.Debugf("get rpc heartbeat request{header: %#v, service: %#v, body: %#v}", p.Header, p.Service, p.Body) h.reply(session, p, hessian.PackageHeartbeat) return } @@ -243,7 +243,7 @@ func (h *RpcServerHandler) OnCron(session getty.Session) { active = session.GetActive() if h.sessionTimeout.Nanoseconds() < time.Since(active).Nanoseconds() { flag = true - log.Warn("session{%s} timeout{%s}, reqNum{%d}", + logger.Warnf("session{%s} timeout{%s}, reqNum{%d}", session.Stat(), time.Since(active).String(), h.sessionMap[session].reqNum) } } @@ -263,13 +263,13 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { if e := recover(); e != nil { req.Header.ResponseStatus = hessian.Response_BAD_REQUEST if err, ok := e.(error); ok { - log.Error("callService panic: %#v", err) + logger.Errorf("callService panic: %#v", err) req.Body = e.(error) } else if err, ok := e.(string); ok { - log.Error("callService panic: %#v", perrors.New(err)) + logger.Errorf("callService panic: %#v", perrors.New(err)) req.Body = perrors.New(err) } else { - log.Error("callService panic: %#v", e) + logger.Errorf("callService panic: %#v", e) req.Body = e } } @@ -277,7 +277,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { svcIf := req.Body.(map[string]interface{})["service"] if svcIf == nil { - log.Error("service not found!") + logger.Errorf("service not found!") req.Header.ResponseStatus = hessian.Response_SERVICE_NOT_FOUND req.Body = perrors.New("service not found") return @@ -285,7 +285,7 @@ func (h *RpcServerHandler) callService(req *DubboPackage, ctx context.Context) { svc := svcIf.(*common.Service) method := svc.Method()[req.Service.Method] if method == nil { - log.Error("method not found!") + logger.Errorf("method not found!") req.Header.ResponseStatus = hessian.Response_SERVICE_NOT_FOUND req.Body = perrors.New("method not found") return @@ -347,6 +347,6 @@ func (h *RpcServerHandler) reply(session getty.Session, req *DubboPackage, tp he } if err := session.WritePkg(resp, WritePkg_Timeout); err != nil { - log.Error("WritePkg error: %#v, %#v", perrors.WithStack(err), req.Header) + logger.Errorf("WritePkg error: %#v, %#v", perrors.WithStack(err), req.Header) } } diff --git a/protocol/dubbo/pool.go b/protocol/dubbo/pool.go index a4c82627fdc80b923593f1a3365ee5dfb6bff86b..60a65e45fe386a027c6e1556949730cf9ef050f4 100644 --- a/protocol/dubbo/pool.go +++ b/protocol/dubbo/pool.go @@ -24,11 +24,14 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" "github.com/dubbogo/getty" perrors "github.com/pkg/errors" ) +import ( + "github.com/dubbo/go-for-apache-dubbo/common/logger" +) + type gettyRPCClient struct { once sync.Once protocol string @@ -70,7 +73,7 @@ func newGettyRPCClientConn(pool *gettyRPCClientPool, protocol, addr string) (*ge } time.Sleep(1e6) } - log.Info("client init ok") + logger.Infof("client init ok") c.created = time.Now().Unix() return c, nil @@ -110,7 +113,7 @@ func (c *gettyRPCClient) 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()) + logger.Debugf("client new session:%s\n", session.Stat()) return nil } @@ -131,7 +134,7 @@ func (c *gettyRPCClient) selectSession() getty.Session { } func (c *gettyRPCClient) addSession(session getty.Session) { - log.Debug("add session{%s}", session.Stat()) + logger.Debugf("add session{%s}", session.Stat()) if session == nil { return } @@ -155,11 +158,11 @@ func (c *gettyRPCClient) 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) + logger.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)) + logger.Infof("after remove session{%s}, left session number:%d", session.Stat(), len(c.sessions)) if len(c.sessions) == 0 { c.close() // -> pool.remove(c) } @@ -220,7 +223,7 @@ func (c *gettyRPCClient) close() error { // delete @c from client pool c.pool.remove(c) for _, s := range c.sessions { - log.Info("close client session{%s, last active:%s, request number:%d}", + logger.Infof("close client session{%s, last active:%s, request number:%d}", s.session.Stat(), s.session.GetActive().String(), s.reqNum) s.session.Close() } diff --git a/protocol/dubbo/readwriter.go b/protocol/dubbo/readwriter.go index 3f51ff5f9626ef51851e2ba1d91e3f821d6af207..87b73aed91d5232975b6f6b1513e3d728c0f2175 100644 --- a/protocol/dubbo/readwriter.go +++ b/protocol/dubbo/readwriter.go @@ -20,13 +20,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" "github.com/dubbogo/getty" perrors "github.com/pkg/errors" ) import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" ) //////////////////////////////////////////// @@ -59,13 +59,13 @@ func (p *RpcClientPackageHandler) Read(ss getty.Session, data []byte) (interface func (p *RpcClientPackageHandler) Write(ss getty.Session, pkg interface{}) error { req, ok := pkg.(*DubboPackage) if !ok { - log.Error("illegal pkg:%+v\n", pkg) + logger.Errorf("illegal pkg:%+v\n", pkg) return perrors.New("invalid rpc request") } buf, err := req.Marshal() if err != nil { - log.Warn("binary.Write(req{%#v}) = err{%#v}", req, perrors.WithStack(err)) + logger.Warnf("binary.Write(req{%#v}) = err{%#v}", req, perrors.WithStack(err)) return perrors.WithStack(err) } @@ -136,13 +136,13 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface func (p *RpcServerPackageHandler) Write(ss getty.Session, pkg interface{}) error { res, ok := pkg.(*DubboPackage) if !ok { - log.Error("illegal pkg:%+v\n, it is %+v", pkg, reflect.TypeOf(pkg)) + logger.Errorf("illegal pkg:%+v\n, it is %+v", pkg, reflect.TypeOf(pkg)) return perrors.New("invalid rpc response") } buf, err := res.Marshal() if err != nil { - log.Warn("binary.Write(res{%#v}) = err{%#v}", res, perrors.WithStack(err)) + logger.Warnf("binary.Write(res{%#v}) = err{%#v}", res, perrors.WithStack(err)) return perrors.WithStack(err) } diff --git a/protocol/dubbo/server.go b/protocol/dubbo/server.go index 9e76fcdb7e5c21480783376daa25e7201b39b8c5..f8de070bcc42bf0f81ad2a2e12658f2283bdf210 100644 --- a/protocol/dubbo/server.go +++ b/protocol/dubbo/server.go @@ -20,13 +20,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" "github.com/dubbogo/getty" "gopkg.in/yaml.v2" ) import ( "github.com/dubbo/go-for-apache-dubbo/common" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/config" "github.com/dubbo/go-for-apache-dubbo/protocol" ) @@ -38,12 +38,12 @@ func init() { // load clientconfig from provider_config protocolConf := config.GetProviderConfig().ProtocolConf if protocolConf == nil { - log.Warn("protocol_conf is nil") + logger.Warnf("protocol_conf is nil") return } dubboConf := protocolConf.(map[interface{}]interface{})[DUBBO] if protocolConf == nil { - log.Warn("dubboConf is nil") + logger.Warnf("dubboConf is nil") return } @@ -121,7 +121,7 @@ func (s *Server) newSession(session getty.Session) error { session.SetWriteTimeout(conf.GettySessionParam.tcpWriteTimeout) session.SetCronPeriod((int)(conf.sessionTimeout.Nanoseconds() / 1e6)) session.SetWaitTime(conf.GettySessionParam.waitTimeout) - log.Debug("app accepts new session:%s\n", session.Stat()) + logger.Debugf("app accepts new session:%s\n", session.Stat()) return nil } @@ -137,7 +137,7 @@ func (s *Server) Start(url common.URL) { getty.WithLocalAddress(addr), ) tcpServer.RunEventLoop(s.newSession) - log.Debug("s bind addr{%s} ok!", addr) + logger.Debugf("s bind addr{%s} ok!", addr) s.tcpServer = tcpServer } diff --git a/protocol/invoker.go b/protocol/invoker.go index 98ce99c06844389ca7e4fa412cac2b8a8b08ebea..bedbb10442031fe8b723286f824c03f321623ca1 100644 --- a/protocol/invoker.go +++ b/protocol/invoker.go @@ -14,12 +14,9 @@ package protocol -import ( - log "github.com/AlexStocks/log4go" -) - import ( "github.com/dubbo/go-for-apache-dubbo/common" + "github.com/dubbo/go-for-apache-dubbo/common/logger" ) // Extension - Invoker @@ -63,7 +60,7 @@ func (bi *BaseInvoker) Invoke(invocation Invocation) Result { } func (bi *BaseInvoker) Destroy() { - log.Info("Destroy invoker: %s", bi.GetUrl().String()) + logger.Infof("Destroy invoker: %s", bi.GetUrl().String()) bi.destroyed = true bi.available = false } diff --git a/protocol/jsonrpc/jsonrpc_exporter.go b/protocol/jsonrpc/jsonrpc_exporter.go index c470d8ba6e0d78d5d197aa476c0403ff80831fe0..144437c10402962b3356706b88f1e2701524a97b 100644 --- a/protocol/jsonrpc/jsonrpc_exporter.go +++ b/protocol/jsonrpc/jsonrpc_exporter.go @@ -18,13 +18,10 @@ import ( "sync" ) -import ( - log "github.com/AlexStocks/log4go" -) - import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" ) @@ -43,6 +40,6 @@ func (je *JsonrpcExporter) Unexport() { je.BaseExporter.Unexport() err := common.ServiceMap.UnRegister(JSONRPC, service) if err != nil { - log.Error("[JsonrpcExporter.Unexport] error: %v", err) + logger.Errorf("[JsonrpcExporter.Unexport] error: %v", err) } } diff --git a/protocol/jsonrpc/jsonrpc_invoker.go b/protocol/jsonrpc/jsonrpc_invoker.go index 18966db2a10d657c341acf633da82c67ab597b4b..75ac88085ff396cde95e1ec2a43a7026777569de 100644 --- a/protocol/jsonrpc/jsonrpc_invoker.go +++ b/protocol/jsonrpc/jsonrpc_invoker.go @@ -18,13 +18,10 @@ import ( "context" ) -import ( - log "github.com/AlexStocks/log4go" -) - import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" invocation_impl "github.com/dubbo/go-for-apache-dubbo/protocol/invocation" ) @@ -59,7 +56,7 @@ func (ji *JsonrpcInvoker) Invoke(invocation protocol.Invocation) protocol.Result if result.Err == nil { result.Rest = inv.Reply() } - log.Debug("result.Err: %v, result.Rest: %v", result.Err, result.Rest) + logger.Debugf("result.Err: %v, result.Rest: %v", result.Err, result.Rest) return &result } diff --git a/protocol/jsonrpc/jsonrpc_protocol.go b/protocol/jsonrpc/jsonrpc_protocol.go index 465e4a1e57e8ba3ab53473c9f279a74b2ed9bdd4..737c9cb175cedaae081abf6a43dfc605fb906d40 100644 --- a/protocol/jsonrpc/jsonrpc_protocol.go +++ b/protocol/jsonrpc/jsonrpc_protocol.go @@ -14,13 +14,10 @@ package jsonrpc -import ( - log "github.com/AlexStocks/log4go" -) - import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/extension" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/config" "github.com/dubbo/go-for-apache-dubbo/protocol" ) @@ -50,7 +47,7 @@ func (jp *JsonrpcProtocol) Export(invoker protocol.Invoker) protocol.Exporter { serviceKey := url.Key() exporter := NewJsonrpcExporter(serviceKey, invoker, jp.ExporterMap()) jp.SetExporterMap(serviceKey, exporter) - log.Info("Export service: %s", url.String()) + logger.Infof("Export service: %s", url.String()) // start server jp.openServer(url) @@ -64,12 +61,12 @@ func (jp *JsonrpcProtocol) Refer(url common.URL) protocol.Invoker { HTTPTimeout: config.GetConsumerConfig().RequestTimeout, })) jp.SetInvokers(invoker) - log.Info("Refer service: %s", url.String()) + logger.Infof("Refer service: %s", url.String()) return invoker } func (jp *JsonrpcProtocol) Destroy() { - log.Info("jsonrpcProtocol destroy.") + logger.Infof("jsonrpcProtocol destroy.") jp.BaseProtocol.Destroy() diff --git a/protocol/jsonrpc/server.go b/protocol/jsonrpc/server.go index a54dcb9d0f0bf97751b85c3c8ea5975fb761e03f..1be5c54d239910c7da7b3fd955512e4120fed4da 100644 --- a/protocol/jsonrpc/server.go +++ b/protocol/jsonrpc/server.go @@ -30,13 +30,13 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" perrors "github.com/pkg/errors" ) import ( "github.com/dubbo/go-for-apache-dubbo/common" "github.com/dubbo/go-for-apache-dubbo/common/constant" + "github.com/dubbo/go-for-apache-dubbo/common/logger" "github.com/dubbo/go-for-apache-dubbo/protocol" "github.com/dubbo/go-for-apache-dubbo/protocol/invocation" ) @@ -74,7 +74,7 @@ func NewServer(exporter protocol.Exporter) *Server { func (s *Server) handlePkg(conn net.Conn) { defer func() { if r := recover(); r != nil { - log.Warn("connection{local:%v, remote:%v} panic error:%#v, debug stack:%s", + logger.Warnf("connection{local:%v, remote:%v} panic error:%#v, debug stack:%s", conn.LocalAddr(), conn.RemoteAddr(), r, string(debug.Stack())) } @@ -115,7 +115,7 @@ func (s *Server) handlePkg(conn net.Conn) { bufReader := bufio.NewReader(conn) r, err := http.ReadRequest(bufReader) if err != nil { - log.Warn("[ReadRequest] error: %v", err) + logger.Warnf("[ReadRequest] error: %v", err) return } @@ -141,7 +141,7 @@ func (s *Server) handlePkg(conn net.Conn) { setTimeout(conn, httpTimeout) r.Header.Set("Content-Type", "text/plain") if errRsp := sendErrorResp(r.Header, []byte(perrors.WithStack(err).Error())); errRsp != nil { - log.Warn("sendErrorResp(header:%#v, error:%v) = error:%s", + logger.Warnf("sendErrorResp(header:%#v, error:%v) = error:%s", r.Header, perrors.WithStack(err), errRsp) } return @@ -160,11 +160,11 @@ func (s *Server) handlePkg(conn net.Conn) { if err := serveRequest(ctx, reqHeader, reqBody, conn, s.exporter); err != nil { if errRsp := sendErrorResp(r.Header, []byte(perrors.WithStack(err).Error())); errRsp != nil { - log.Warn("sendErrorResp(header:%#v, error:%v) = error:%s", + logger.Warnf("sendErrorResp(header:%#v, error:%v) = error:%s", r.Header, perrors.WithStack(err), errRsp) } - log.Info("Unexpected error serving request, closing socket: %v", err) + logger.Infof("Unexpected error serving request, closing socket: %v", err) return } } @@ -189,7 +189,7 @@ func accept(listener net.Listener, fn func(net.Conn)) error { if tmpDelay > DefaultMaxSleepTime { tmpDelay = DefaultMaxSleepTime } - log.Info("http: Accept error: %v; retrying in %v\n", err, tmpDelay) + logger.Infof("http: Accept error: %v; retrying in %v\n", err, tmpDelay) time.Sleep(tmpDelay) continue } @@ -202,7 +202,7 @@ func accept(listener net.Listener, fn func(net.Conn)) error { const size = 64 << 10 buf := make([]byte, size) buf = buf[:runtime.Stack(buf, false)] - log.Error("http: panic serving %v: %v\n%s", c.RemoteAddr(), r, buf) + logger.Errorf("http: panic serving %v: %v\n%s", c.RemoteAddr(), r, buf) c.Close() } }() @@ -215,10 +215,10 @@ func accept(listener net.Listener, fn func(net.Conn)) error { func (s *Server) Start(url common.URL) { listener, err := net.Listen("tcp", url.Location) if err != nil { - log.Error("jsonrpc server [%s] start failed: %v", url.Path, err) + logger.Errorf("jsonrpc server [%s] start failed: %v", url.Path, err) return } - log.Info("rpc server start to listen on %s", listener.Addr()) + logger.Infof("rpc server start to listen on %s", listener.Addr()) s.wg.Add(1) go func() { @@ -232,7 +232,7 @@ func (s *Server) Start(url common.URL) { <-s.done // step1: block to wait for done channel(wait Server.Stop step2) err = listener.Close() // step2: and then close listener if err != nil { - log.Warn("listener{addr:%s}.Close() = error{%#v}", listener.Addr(), err) + logger.Warnf("listener{addr:%s}.Close() = error{%#v}", listener.Addr(), err) } s.wg.Done() }() @@ -318,7 +318,7 @@ func serveRequest(ctx context.Context, if err = codec.ReadBody(&args); err != nil { return perrors.WithStack(err) } - log.Debug("args: %v", args) + logger.Debugf("args: %v", args) // exporter invoke invoker := exporter.GetInvoker() @@ -331,7 +331,7 @@ func serveRequest(ctx context.Context, })) if err := result.Error(); err != nil { if errRsp := sendErrorResp(header, []byte(err.Error())); errRsp != nil { - log.Warn("Exporter: sendErrorResp(header:%#v, error:%v) = error:%s", + logger.Warnf("Exporter: sendErrorResp(header:%#v, error:%v) = error:%s", header, err, errRsp) return perrors.WithStack(errRsp) } @@ -342,7 +342,7 @@ func serveRequest(ctx context.Context, return perrors.WithStack(err) } if errRsp := sendResp(header, rspStream); errRsp != nil { - log.Warn("Exporter: sendResp(header:%#v, error:%v) = error:%s", + logger.Warnf("Exporter: sendResp(header:%#v, error:%v) = error:%s", header, err, errRsp) return perrors.WithStack(errRsp) } @@ -425,11 +425,11 @@ func serveRequest(ctx context.Context, rspBuf := bytes.NewBuffer(make([]byte, DefaultHTTPRspBufferSize)) rspBuf.Reset() if err = rsp.Write(rspBuf); err != nil { - log.Warn("rsp.Write(rsp:%#v) = error:%s", rsp, err) + logger.Warnf("rsp.Write(rsp:%#v) = error:%s", rsp, err) return nil } if _, err = rspBuf.WriteTo(conn); err != nil { - log.Warn("rspBuf.WriteTo(conn:%#v) = error:%s", conn, err) + logger.Warnf("rspBuf.WriteTo(conn:%#v) = error:%s", conn, err) } return nil } diff --git a/protocol/protocol.go b/protocol/protocol.go index 90a9970a8904f00ea3bd595d6b040bc51a62e304..03b2cfbe50c6757a0e86cf4d10385fef97cd8104 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -18,11 +18,9 @@ import ( "sync" ) -import ( - log "github.com/AlexStocks/log4go" -) import ( "github.com/dubbo/go-for-apache-dubbo/common" + "github.com/dubbo/go-for-apache-dubbo/common/logger" ) // Extension - protocol @@ -122,7 +120,7 @@ func (de *BaseExporter) GetInvoker() Invoker { } func (de *BaseExporter) Unexport() { - log.Info("Exporter unexport.") + logger.Infof("Exporter unexport.") de.invoker.Destroy() de.exporterMap.Delete(de.key) } diff --git a/registry/directory/directory.go b/registry/directory/directory.go index 256065fae007ca45c33c87c6cd2b5c120506f86a..c86bc2697edee6686a2e6af33c3d0554d5439212 100644 --- a/registry/directory/directory.go +++ b/registry/directory/directory.go @@ -20,7 +20,7 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/go-for-apache-dubbo/common/logger" perrors "github.com/pkg/errors" ) @@ -77,29 +77,29 @@ func NewRegistryDirectory(url *common.URL, registry registry.Registry, opts ...O func (dir *registryDirectory) Subscribe(url common.URL) { for { if !dir.registry.IsAvailable() { - log.Warn("event listener game over.") + logger.Warnf("event listener game over.") return } listener, err := dir.registry.Subscribe(url) if err != nil { if !dir.registry.IsAvailable() { - log.Warn("event listener game over.") + logger.Warnf("event listener game over.") return } - log.Warn("getListener() = err:%v", perrors.WithStack(err)) + logger.Warnf("getListener() = err:%v", perrors.WithStack(err)) time.Sleep(time.Duration(RegistryConnDelay) * time.Second) continue } for { if serviceEvent, err := listener.Next(); err != nil { - log.Warn("Selector.watch() = error{%v}", perrors.WithStack(err)) + logger.Warnf("Selector.watch() = error{%v}", perrors.WithStack(err)) listener.Close() time.Sleep(time.Duration(RegistryConnDelay) * time.Second) return } else { - log.Info("update begin, service event: %v", serviceEvent.String()) + logger.Infof("update begin, service event: %v", serviceEvent.String()) go dir.update(serviceEvent) } @@ -114,9 +114,9 @@ func (dir *registryDirectory) update(res *registry.ServiceEvent) { return } - log.Debug("registry update, result{%s}", res) + logger.Debugf("registry update, result{%s}", res) - log.Debug("update service name: %s!", res.Service) + logger.Debugf("update service name: %s!", res.Service) dir.refreshInvokers(res) } @@ -130,7 +130,7 @@ func (dir *registryDirectory) refreshInvokers(res *registry.ServiceEvent) { case registry.ServiceDel: //dir.cacheService.Del(res.Path, dir.serviceTTL) dir.uncacheInvoker(res.Service) - log.Info("selector delete service url{%s}", res.Service) + logger.Infof("selector delete service url{%s}", res.Service) default: return } @@ -177,7 +177,7 @@ func (dir *registryDirectory) toGroupInvokers() []protocol.Invoker { } func (dir *registryDirectory) uncacheInvoker(url common.URL) { - log.Debug("service will be deleted in cache invokers: invokers key is %s!", url.Key()) + logger.Debugf("service will be deleted in cache invokers: invokers key is %s!", url.Key()) dir.cacheInvokersMap.Delete(url.Key()) } @@ -188,7 +188,7 @@ func (dir *registryDirectory) cacheInvoker(url common.URL) { url = mergeUrl(url, referenceUrl) if _, ok := dir.cacheInvokersMap.Load(url.Key()); !ok { - log.Debug("service will be added in cache invokers: invokers key is %s!", url.Key()) + logger.Debugf("service will be added in cache invokers: invokers key is %s!", url.Key()) newInvoker := extension.GetProtocol(protocolwrapper.FILTER).Refer(url) if newInvoker != nil { dir.cacheInvokersMap.Store(url.Key(), newInvoker) diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go index e914490973865a3a9c6c9d17cd098728bdf08d97..0c1789ac6593d33289d66d2d63689f95f534c1e4 100644 --- a/registry/protocol/protocol.go +++ b/registry/protocol/protocol.go @@ -19,7 +19,7 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/go-for-apache-dubbo/common/logger" ) import ( @@ -56,7 +56,7 @@ func newRegistryProtocol() *registryProtocol { func getRegistry(regUrl *common.URL) registry.Registry { reg, err := extension.GetRegistry(regUrl.Protocol, regUrl) if err != nil { - log.Error("Registry can not connect success, program is going to panic.Error message is %s", err.Error()) + logger.Errorf("Registry can not connect success, program is going to panic.Error message is %s", err.Error()) panic(err.Error()) } return reg @@ -81,12 +81,12 @@ func (proto *registryProtocol) Refer(url common.URL) protocol.Invoker { //new registry directory for store service url from registry directory, err := directory2.NewRegistryDirectory(®istryUrl, reg) if err != nil { - log.Error("consumer service %v create registry directory error, error message is %s, and will return nil invoker!", serviceUrl.String(), err.Error()) + logger.Errorf("consumer service %v create registry directory error, error message is %s, and will return nil invoker!", serviceUrl.String(), err.Error()) return nil } err = reg.Register(*serviceUrl) if err != nil { - log.Error("consumer service %v register registry %v error, error message is %s", serviceUrl.String(), registryUrl.String(), err.Error()) + logger.Errorf("consumer service %v register registry %v error, error message is %s", serviceUrl.String(), registryUrl.String(), err.Error()) } go directory.Subscribe(*serviceUrl) @@ -113,20 +113,20 @@ func (proto *registryProtocol) Export(invoker protocol.Invoker) protocol.Exporte err := reg.Register(providerUrl) if err != nil { - log.Error("provider service %v register registry %v error, error message is %s", providerUrl.Key(), registryUrl.Key(), err.Error()) + logger.Errorf("provider service %v register registry %v error, error message is %s", providerUrl.Key(), registryUrl.Key(), err.Error()) return nil } key := providerUrl.Key() - log.Info("The cached exporter keys is %v !", key) + logger.Infof("The cached exporter keys is %v !", key) cachedExporter, loaded := proto.bounds.Load(key) if loaded { - log.Info("The exporter has been cached, and will return cached exporter!") + logger.Infof("The exporter has been cached, and will return cached exporter!") } else { wrappedInvoker := newWrappedInvoker(invoker, providerUrl) cachedExporter = extension.GetProtocol(protocolwrapper.FILTER).Export(wrappedInvoker) proto.bounds.Store(key, cachedExporter) - log.Info("The exporter has not been cached, and will return a new exporter!") + logger.Infof("The exporter has not been cached, and will return a new exporter!") } return cachedExporter.(protocol.Exporter) diff --git a/registry/zookeeper/listener.go b/registry/zookeeper/listener.go index a2363f87d6ecdeadf4323420b97d2f4037020806..b6446e7fcc3dd46515e9e50ad2cdbc323263078e 100644 --- a/registry/zookeeper/listener.go +++ b/registry/zookeeper/listener.go @@ -23,7 +23,7 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/go-for-apache-dubbo/common/logger" perrors "github.com/pkg/errors" "github.com/samuel/go-zookeeper/zk" ) @@ -71,23 +71,23 @@ func (l *zkEventListener) listenServiceNodeEvent(zkPath string) bool { for { keyEventCh, err := l.client.existW(zkPath) if err != nil { - log.Error("existW{key:%s} = error{%v}", zkPath, err) + logger.Errorf("existW{key:%s} = error{%v}", zkPath, err) return false } select { case zkEvent = <-keyEventCh: - log.Warn("get a zookeeper zkEvent{type:%s, server:%s, path:%s, state:%d-%s, err:%s}", + logger.Warnf("get a zookeeper zkEvent{type:%s, server:%s, path:%s, state:%d-%s, err:%s}", zkEvent.Type.String(), zkEvent.Server, zkEvent.Path, zkEvent.State, stateToString(zkEvent.State), zkEvent.Err) switch zkEvent.Type { case zk.EventNodeDataChanged: - log.Warn("zk.ExistW(key{%s}) = event{EventNodeDataChanged}", zkPath) + logger.Warnf("zk.ExistW(key{%s}) = event{EventNodeDataChanged}", zkPath) case zk.EventNodeCreated: - log.Warn("zk.ExistW(key{%s}) = event{EventNodeCreated}", zkPath) + logger.Warnf("zk.ExistW(key{%s}) = event{EventNodeCreated}", zkPath) case zk.EventNotWatching: - log.Warn("zk.ExistW(key{%s}) = event{EventNotWatching}", zkPath) + logger.Warnf("zk.ExistW(key{%s}) = event{EventNotWatching}", zkPath) case zk.EventNodeDeleted: - log.Warn("zk.ExistW(key{%s}) = event{EventNodeDeleted}", zkPath) + logger.Warnf("zk.ExistW(key{%s}) = event{EventNodeDeleted}", zkPath) return true } case <-l.client.done(): @@ -111,7 +111,7 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co newChildren, err := l.client.getChildren(zkPath) if err != nil { - log.Error("path{%s} child nodes changed, zk.Children() = error{%v}", zkPath, perrors.WithStack(err)) + logger.Errorf("path{%s} child nodes changed, zk.Children() = error{%v}", zkPath, perrors.WithStack(err)) return } @@ -126,27 +126,27 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co } newNode = path.Join(zkPath, n) - log.Info("add zkNode{%s}", newNode) + logger.Infof("add zkNode{%s}", newNode) //context.TODO serviceURL, err = common.NewURL(context.TODO(), n) if err != nil { - log.Error("NewURL(%s) = error{%v}", n, perrors.WithStack(err)) + logger.Errorf("NewURL(%s) = error{%v}", n, perrors.WithStack(err)) continue } if !conf.URLEqual(serviceURL) { - log.Warn("serviceURL{%s} is not compatible with SubURL{%#v}", serviceURL.Key(), conf.Key()) + logger.Warnf("serviceURL{%s} is not compatible with SubURL{%#v}", serviceURL.Key(), conf.Key()) continue } - log.Info("add serviceURL{%s}", serviceURL) + logger.Infof("add serviceURL{%s}", serviceURL) l.events <- zkEvent{®istry.ServiceEvent{Action: registry.ServiceAdd, Service: serviceURL}, nil} // listen l service node go func(node string, serviceURL common.URL) { - log.Info("delete zkNode{%s}", node) + logger.Infof("delete zkNode{%s}", node) if l.listenServiceNodeEvent(node) { - log.Info("delete serviceURL{%s}", serviceURL) + logger.Infof("delete serviceURL{%s}", serviceURL) l.events <- zkEvent{®istry.ServiceEvent{Action: registry.ServiceDel, Service: serviceURL}, nil} } - log.Warn("listenSelf(zk path{%s}) goroutine exit now", zkPath) + logger.Warnf("listenSelf(zk path{%s}) goroutine exit now", zkPath) }(newNode, serviceURL) } @@ -158,15 +158,15 @@ func (l *zkEventListener) handleZkNodeEvent(zkPath string, children []string, co } oldNode = path.Join(zkPath, n) - log.Warn("delete zkPath{%s}", oldNode) + logger.Warnf("delete zkPath{%s}", oldNode) serviceURL, err = common.NewURL(context.TODO(), n) if !conf.URLEqual(serviceURL) { - log.Warn("serviceURL{%s} has been deleted is not compatible with SubURL{%#v}", serviceURL.Key(), conf.Key()) + logger.Warnf("serviceURL{%s} has been deleted is not compatible with SubURL{%#v}", serviceURL.Key(), conf.Key()) continue } - log.Warn("delete serviceURL{%s}", serviceURL) + logger.Warnf("delete serviceURL{%s}", serviceURL) if err != nil { - log.Error("NewURL(i{%s}) = error{%v}", n, perrors.WithStack(err)) + logger.Errorf("NewURL(i{%s}) = error{%v}", n, perrors.WithStack(err)) continue } l.events <- zkEvent{®istry.ServiceEvent{Action: registry.ServiceDel, Service: serviceURL}, nil} @@ -192,7 +192,7 @@ func (l *zkEventListener) listenDirEvent(zkPath string, conf common.URL) { if MaxFailTimes <= failTimes { failTimes = MaxFailTimes } - log.Error("listenDirEvent(path{%s}) = error{%v}", zkPath, err) + logger.Errorf("listenDirEvent(path{%s}) = error{%v}", zkPath, err) // clear the event channel CLEAR: for { @@ -209,10 +209,10 @@ func (l *zkEventListener) listenDirEvent(zkPath string, conf common.URL) { continue case <-l.client.done(): l.client.unregisterEvent(zkPath, &event) - log.Warn("client.done(), listen(path{%s}, ReferenceConfig{%#v}) goroutine exit now...", zkPath, conf) + logger.Warnf("client.done(), listen(path{%s}, ReferenceConfig{%#v}) goroutine exit now...", zkPath, conf) return case <-event: - log.Info("get zk.EventNodeDataChange notify event") + logger.Infof("get zk.EventNodeDataChange notify event") l.client.unregisterEvent(zkPath, &event) l.handleZkNodeEvent(zkPath, nil, conf) continue @@ -222,14 +222,14 @@ func (l *zkEventListener) listenDirEvent(zkPath string, conf common.URL) { select { case zkEvent = <-childEventCh: - log.Warn("get a zookeeper zkEvent{type:%s, server:%s, path:%s, state:%d-%s, err:%s}", + logger.Warnf("get a zookeeper zkEvent{type:%s, server:%s, path:%s, state:%d-%s, err:%s}", zkEvent.Type.String(), zkEvent.Server, zkEvent.Path, zkEvent.State, stateToString(zkEvent.State), zkEvent.Err) if zkEvent.Type != zk.EventNodeChildrenChanged { continue } l.handleZkNodeEvent(zkEvent.Path, children, conf) case <-l.client.done(): - log.Warn("client.done(), listen(path{%s}, ReferenceConfig{%#v}) goroutine exit now...", zkPath, conf) + logger.Warnf("client.done(), listen(path{%s}, ReferenceConfig{%#v}) goroutine exit now...", zkPath, conf) return } } @@ -254,7 +254,7 @@ func (l *zkEventListener) listenServiceEvent(conf common.URL) { _, ok := l.serviceMap[zkPath] l.serviceMapLock.Unlock() if ok { - log.Warn("@zkPath %s has already been listened.", zkPath) + logger.Warnf("@zkPath %s has already been listened.", zkPath) return } @@ -262,42 +262,42 @@ func (l *zkEventListener) listenServiceEvent(conf common.URL) { l.serviceMap[zkPath] = struct{}{} l.serviceMapLock.Unlock() - log.Info("listen dubbo provider path{%s} event and wait to get all provider zk nodes", zkPath) + logger.Infof("listen dubbo provider path{%s} event and wait to get all provider zk nodes", zkPath) children, err = l.client.getChildren(zkPath) if err != nil { children = nil - log.Error("fail to get children of zk path{%s}", zkPath) + logger.Errorf("fail to get children of zk path{%s}", zkPath) } for _, c := range children { serviceURL, err = common.NewURL(context.TODO(), c) if err != nil { - log.Error("NewURL(r{%s}) = error{%v}", c, err) + logger.Errorf("NewURL(r{%s}) = error{%v}", c, err) continue } if !conf.URLEqual(serviceURL) { - log.Warn("serviceURL %v is not compatible with SubURL %v", serviceURL.Key(), conf.Key()) + logger.Warnf("serviceURL %v is not compatible with SubURL %v", serviceURL.Key(), conf.Key()) continue } - log.Debug("add serviceUrl{%s}", serviceURL) + logger.Debugf("add serviceUrl{%s}", serviceURL) l.events <- zkEvent{®istry.ServiceEvent{Action: registry.ServiceAdd, Service: serviceURL}, nil} // listen l service node dubboPath = path.Join(zkPath, c) - log.Info("listen dubbo service key{%s}", dubboPath) + logger.Infof("listen dubbo service key{%s}", dubboPath) go func(zkPath string, serviceURL common.URL) { if l.listenServiceNodeEvent(dubboPath) { - log.Debug("delete serviceUrl{%s}", serviceURL) + logger.Debugf("delete serviceUrl{%s}", serviceURL) l.events <- zkEvent{®istry.ServiceEvent{Action: registry.ServiceDel, Service: serviceURL}, nil} } - log.Warn("listenSelf(zk path{%s}) goroutine exit now", zkPath) + logger.Warnf("listenSelf(zk path{%s}) goroutine exit now", zkPath) }(dubboPath, serviceURL) } - log.Info("listen dubbo path{%s}", zkPath) + logger.Infof("listen dubbo path{%s}", zkPath) go func(zkPath string, conf common.URL) { l.listenDirEvent(zkPath, conf) - log.Warn("listenDirEvent(zkPath{%s}) goroutine exit now", zkPath) + logger.Warnf("listenDirEvent(zkPath{%s}) goroutine exit now", zkPath) }(zkPath, conf) } @@ -305,20 +305,20 @@ func (l *zkEventListener) Next() (*registry.ServiceEvent, error) { for { select { case <-l.client.done(): - log.Warn("listener's zk client connection is broken, so zk event listener exit now.") + logger.Warnf("listener's zk client connection is broken, so zk event listener exit now.") return nil, perrors.New("listener stopped") case <-l.registry.done: - log.Warn("zk consumer register has quit, so zk event listener exit asap now.") + logger.Warnf("zk consumer register has quit, so zk event listener exit asap now.") return nil, perrors.New("listener stopped") case e := <-l.events: - log.Debug("got zk event %s", e) + logger.Debugf("got zk event %s", e) if e.err != nil { return nil, perrors.WithStack(e.err) } if e.res.Action == registry.ServiceDel && !l.valid() { - log.Warn("update @result{%s}. But its connection to registry is invalid", e.res) + logger.Warnf("update @result{%s}. But its connection to registry is invalid", e.res) continue } //r.update(e.res) diff --git a/registry/zookeeper/registry.go b/registry/zookeeper/registry.go index 69a02c06db06cd3c3bb7260bbd108010a2c20c66..4d553a1658a15416cbcf00c107aeffca11b5031b 100644 --- a/registry/zookeeper/registry.go +++ b/registry/zookeeper/registry.go @@ -26,7 +26,7 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/go-for-apache-dubbo/common/logger" perrors "github.com/pkg/errors" "github.com/samuel/go-zookeeper/zk" ) @@ -173,13 +173,13 @@ func (r *zkRegistry) validateZookeeperClient() error { //in dubbp ,every registry only connect one node ,so this is []string{r.Address} timeout, err := time.ParseDuration(r.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT)) if err != nil { - log.Error("timeout config %v is invalid ,err is %v", + logger.Errorf("timeout config %v is invalid ,err is %v", r.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT), err.Error()) return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", r.Location) } r.client, err = newZookeeperClient(RegistryZkClient, []string{r.Location}, timeout) if err != nil { - log.Warn("newZookeeperClient(name{%s}, zk addresss{%v}, timeout{%d}) = error{%v}", + logger.Warnf("newZookeeperClient(name{%s}, zk addresss{%v}, timeout{%d}) = error{%v}", RegistryZkClient, r.Location, timeout.String(), err) return perrors.WithMessagef(err, "newZookeeperClient(address:%+v)", r.Location) } @@ -209,7 +209,7 @@ LOOP: for { select { case <-r.done: - log.Warn("(ZkProviderRegistry)reconnectZkRegistry goroutine exit now...") + logger.Warnf("(ZkProviderRegistry)reconnectZkRegistry goroutine exit now...") break LOOP // re-register all services case <-r.client.done(): @@ -223,12 +223,12 @@ LOOP: for { select { case <-r.done: - log.Warn("(ZkProviderRegistry)reconnectZkRegistry goroutine exit now...") + logger.Warnf("(ZkProviderRegistry)reconnectZkRegistry goroutine exit now...") break LOOP case <-time.After(time.Duration(1e9 * failTimes * RegistryConnDelay)): // 防止疯狂重连zk } err = r.validateZookeeperClient() - log.Info("ZkProviderRegistry.validateZookeeperClient(zkAddr{%s}) = error{%#v}", + logger.Infof("ZkProviderRegistry.validateZookeeperClient(zkAddr{%s}) = error{%#v}", r.client.zkAddrs, perrors.WithStack(err)) if err == nil { // copy r.services @@ -241,12 +241,12 @@ LOOP: for _, confIf = range services { err = r.register(confIf) if err != nil { - log.Error("(ZkProviderRegistry)register(conf{%#v}) = error{%#v}", + logger.Errorf("(ZkProviderRegistry)register(conf{%#v}) = error{%#v}", confIf, perrors.WithStack(err)) flag = false break } - log.Info("success to re-register service :%v", confIf.Key()) + logger.Infof("success to re-register service :%v", confIf.Key()) } if flag { break @@ -286,7 +286,7 @@ func (r *zkRegistry) Register(conf common.URL) error { r.cltLock.Lock() r.services[conf.Key()] = conf r.cltLock.Unlock() - log.Debug("(consumerZkConsumerRegistry)Register(conf{%#v})", conf) + logger.Debugf("(consumerZkConsumerRegistry)Register(conf{%#v})", conf) r.listenerLock.Lock() listener = r.listener @@ -316,7 +316,7 @@ func (r *zkRegistry) Register(conf common.URL) error { r.services[conf.Key()] = conf r.cltLock.Unlock() - log.Debug("(ZkProviderRegistry)Register(conf{%#v})", conf) + logger.Debugf("(ZkProviderRegistry)Register(conf{%#v})", conf) } return nil @@ -361,7 +361,7 @@ func (r *zkRegistry) register(c common.URL) error { err = r.client.Create(dubboPath) r.cltLock.Unlock() if err != nil { - log.Error("zkClient.create(path{%s}) = error{%#v}", dubboPath, perrors.WithStack(err)) + logger.Errorf("zkClient.create(path{%s}) = error{%#v}", dubboPath, perrors.WithStack(err)) return perrors.WithMessagef(err, "zkclient.Create(path:%s)", dubboPath) } params.Add("anyhost", "true") @@ -377,7 +377,7 @@ func (r *zkRegistry) register(c common.URL) error { if len(c.Methods) == 0 { params.Add("methods", strings.Join(c.Methods, ",")) } - log.Debug("provider zk url params:%#v", params) + logger.Debugf("provider zk url params:%#v", params) var host string if c.Ip == "" { host = localIP + ":" + c.Port @@ -395,7 +395,7 @@ func (r *zkRegistry) register(c common.URL) error { // 把自己注册service providers dubboPath = fmt.Sprintf("/dubbo%s/%s", c.Path, (common.RoleType(common.PROVIDER)).String()) - log.Debug("provider path:%s, url:%s", dubboPath, rawURL) + logger.Debugf("provider path:%s, url:%s", dubboPath, rawURL) case common.CONSUMER: dubboPath = fmt.Sprintf("/dubbo%s/%s", c.Path, common.DubboNodes[common.CONSUMER]) @@ -403,7 +403,7 @@ func (r *zkRegistry) register(c common.URL) error { err = r.client.Create(dubboPath) r.cltLock.Unlock() if err != nil { - log.Error("zkClient.create(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err)) + logger.Errorf("zkClient.create(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err)) return perrors.WithStack(err) } dubboPath = fmt.Sprintf("/dubbo%s/%s", c.Path, common.DubboNodes[common.PROVIDER]) @@ -411,7 +411,7 @@ func (r *zkRegistry) register(c common.URL) error { err = r.client.Create(dubboPath) r.cltLock.Unlock() if err != nil { - log.Error("zkClient.create(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err)) + logger.Errorf("zkClient.create(path{%s}) = error{%v}", dubboPath, perrors.WithStack(err)) return perrors.WithStack(err) } @@ -424,7 +424,7 @@ func (r *zkRegistry) register(c common.URL) error { encodedURL = url.QueryEscape(rawURL) dubboPath = fmt.Sprintf("/dubbo%s/%s", c.Path, (common.RoleType(common.CONSUMER)).String()) - log.Debug("consumer path:%s, url:%s", dubboPath, rawURL) + logger.Debugf("consumer path:%s, url:%s", dubboPath, rawURL) default: return perrors.Errorf("@c{%v} type is not referencer or provider", c) } @@ -447,15 +447,15 @@ func (r *zkRegistry) registerTempZookeeperNode(root string, node string) error { defer r.cltLock.Unlock() err = r.client.Create(root) if err != nil { - log.Error("zk.Create(root{%s}) = err{%v}", root, perrors.WithStack(err)) + logger.Errorf("zk.Create(root{%s}) = err{%v}", root, perrors.WithStack(err)) return perrors.WithStack(err) } zkPath, err = r.client.RegisterTemp(root, node) if err != nil { - log.Error("RegisterTempNode(root{%s}, node{%s}) = error{%v}", root, node, perrors.WithStack(err)) + logger.Errorf("RegisterTempNode(root{%s}, node{%s}) = error{%v}", root, node, perrors.WithStack(err)) return perrors.WithMessagef(err, "RegisterTempNode(root{%s}, node{%s})", root, node) } - log.Debug("create a zookeeper node:%s", zkPath) + logger.Debugf("create a zookeeper node:%s", zkPath) return nil } @@ -506,7 +506,7 @@ func (r *zkRegistry) getListener(conf common.URL) (*zkEventListener, error) { func (r *zkRegistry) closeRegisters() { r.cltLock.Lock() defer r.cltLock.Unlock() - log.Info("begin to close provider zk client") + logger.Infof("begin to close provider zk client") // 先关闭旧client,以关闭tmp node r.client.Close() r.client = nil diff --git a/registry/zookeeper/zk_client.go b/registry/zookeeper/zk_client.go index 00d2a0264cb5b692d064388dd8e7c39f152a7b37..3721cc7b3223178f17507f761e9a8add69241188 100644 --- a/registry/zookeeper/zk_client.go +++ b/registry/zookeeper/zk_client.go @@ -22,7 +22,7 @@ import ( ) import ( - log "github.com/AlexStocks/log4go" + "github.com/dubbo/go-for-apache-dubbo/common/logger" perrors "github.com/pkg/errors" "github.com/samuel/go-zookeeper/zk" ) @@ -145,7 +145,7 @@ func (z *zookeeperClient) handleZkEvent(session <-chan zk.Event) { defer func() { z.wait.Done() - log.Info("zk{path:%v, name:%s} connection goroutine game over.", z.zkAddrs, z.name) + logger.Infof("zk{path:%v, name:%s} connection goroutine game over.", z.zkAddrs, z.name) }() LOOP: @@ -154,11 +154,11 @@ LOOP: case <-z.exit: break LOOP case event = <-session: - log.Warn("client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}", + logger.Warnf("client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}", z.name, event.Type, event.Server, event.Path, event.State, stateToString(event.State), event.Err) switch (int)(event.State) { case (int)(zk.StateDisconnected): - log.Warn("zk{addr:%s} state is StateDisconnected, so close the zk client{name:%s}.", z.zkAddrs, z.name) + logger.Warnf("zk{addr:%s} state is StateDisconnected, so close the zk client{name:%s}.", z.zkAddrs, z.name) z.stop() z.Lock() if z.conn != nil { @@ -168,11 +168,11 @@ LOOP: z.Unlock() break LOOP case (int)(zk.EventNodeDataChanged), (int)(zk.EventNodeChildrenChanged): - log.Info("zkClient{%s} get zk node changed event{path:%s}", z.name, event.Path) + logger.Infof("zkClient{%s} get zk node changed event{path:%s}", z.name, event.Path) z.Lock() for p, a := range z.eventRegistry { if strings.HasPrefix(p, event.Path) { - log.Info("send event{state:zk.EventNodeDataChange, Path:%s} notify event to path{%s} related listener", + logger.Infof("send event{state:zk.EventNodeDataChange, Path:%s} notify event to path{%s} related listener", event.Path, p) for _, e := range a { *e <- struct{}{} @@ -204,7 +204,7 @@ func (z *zookeeperClient) registerEvent(zkPath string, event *chan struct{}) { a := z.eventRegistry[zkPath] a = append(a, event) z.eventRegistry[zkPath] = a - log.Debug("zkClient{%s} register event{path:%s, ptr:%p}", z.name, zkPath, event) + logger.Debugf("zkClient{%s} register event{path:%s, ptr:%p}", z.name, zkPath, event) z.Unlock() } @@ -223,10 +223,10 @@ func (z *zookeeperClient) unregisterEvent(zkPath string, event *chan struct{}) { if e == event { arr := a a = append(arr[:i], arr[i+1:]...) - log.Debug("zkClient{%s} unregister event{path:%s, event:%p}", z.name, zkPath, event) + logger.Debugf("zkClient{%s} unregister event{path:%s, event:%p}", z.name, zkPath, event) } } - log.Debug("after zkClient{%s} unregister event{path:%s, event:%p}, array length %d", + logger.Debugf("after zkClient{%s} unregister event{path:%s, event:%p}, array length %d", z.name, zkPath, event, len(a)) if len(a) == 0 { delete(z.eventRegistry, zkPath) @@ -282,7 +282,7 @@ func (z *zookeeperClient) Close() { z.conn = nil } z.Unlock() - log.Warn("zkClient{name:%s, zk addr:%s} exit now.", z.name, z.zkAddrs) + logger.Warnf("zkClient{name:%s, zk addr:%s} exit now.", z.name, z.zkAddrs) } func (z *zookeeperClient) Create(basePath string) error { @@ -291,7 +291,7 @@ func (z *zookeeperClient) Create(basePath string) error { tmpPath string ) - log.Debug("zookeeperClient.Create(basePath{%s})", basePath) + logger.Debugf("zookeeperClient.Create(basePath{%s})", basePath) for _, str := range strings.Split(basePath, "/")[1:] { tmpPath = path.Join(tmpPath, "/", str) err = errNilZkClientConn @@ -302,9 +302,9 @@ func (z *zookeeperClient) Create(basePath string) error { z.Unlock() if err != nil { if err == zk.ErrNodeExists { - log.Error("zk.create(\"%s\") exists\n", tmpPath) + logger.Errorf("zk.create(\"%s\") exists\n", tmpPath) } else { - log.Error("zk.create(\"%s\") error(%v)\n", tmpPath, perrors.WithStack(err)) + logger.Errorf("zk.create(\"%s\") error(%v)\n", tmpPath, perrors.WithStack(err)) return perrors.WithMessagef(err, "zk.Create(path:%s)", basePath) } } @@ -346,10 +346,10 @@ func (z *zookeeperClient) RegisterTemp(basePath string, node string) (string, er z.Unlock() //if err != nil && err != zk.ErrNodeExists { if err != nil { - log.Warn("conn.Create(\"%s\", zk.FlagEphemeral) = error(%v)\n", zkPath, perrors.WithStack(err)) + logger.Warnf("conn.Create(\"%s\", zk.FlagEphemeral) = error(%v)\n", zkPath, perrors.WithStack(err)) return "", perrors.WithStack(err) } - log.Debug("zkClient{%s} create a temp zookeeper node:%s\n", z.name, tmpPath) + logger.Debugf("zkClient{%s} create a temp zookeeper node:%s\n", z.name, tmpPath) return tmpPath, nil } @@ -371,13 +371,13 @@ func (z *zookeeperClient) RegisterTempSeq(basePath string, data []byte) (string, ) } z.Unlock() - log.Debug("zookeeperClient.RegisterTempSeq(basePath{%s}) = tempPath{%s}", basePath, tmpPath) + logger.Debugf("zookeeperClient.RegisterTempSeq(basePath{%s}) = tempPath{%s}", basePath, tmpPath) if err != nil && err != zk.ErrNodeExists { - log.Error("zkClient{%s} conn.Create(\"%s\", \"%s\", zk.FlagEphemeral|zk.FlagSequence) error(%v)\n", + logger.Errorf("zkClient{%s} conn.Create(\"%s\", \"%s\", zk.FlagEphemeral|zk.FlagSequence) error(%v)\n", z.name, basePath, string(data), err) return "", perrors.WithStack(err) } - log.Debug("zkClient{%s} create a temp zookeeper node:%s\n", z.name, tmpPath) + logger.Debugf("zkClient{%s} create a temp zookeeper node:%s\n", z.name, tmpPath) return tmpPath, nil } @@ -400,7 +400,7 @@ func (z *zookeeperClient) getChildrenW(path string) ([]string, <-chan zk.Event, if err == zk.ErrNoNode { return nil, nil, perrors.Errorf("path{%s} has none children", path) } - log.Error("zk.ChildrenW(path{%s}) = error(%v)", path, err) + logger.Errorf("zk.ChildrenW(path{%s}) = error(%v)", path, err) return nil, nil, perrors.WithMessagef(err, "zk.ChildrenW(path:%s)", path) } if stat == nil { @@ -430,7 +430,7 @@ func (z *zookeeperClient) getChildren(path string) ([]string, error) { if err == zk.ErrNoNode { return nil, perrors.Errorf("path{%s} has none children", path) } - log.Error("zk.Children(path{%s}) = error(%v)", path, perrors.WithStack(err)) + logger.Errorf("zk.Children(path{%s}) = error(%v)", path, perrors.WithStack(err)) return nil, perrors.WithMessagef(err, "zk.Children(path:%s)", path) } if stat == nil { @@ -457,11 +457,11 @@ func (z *zookeeperClient) existW(zkPath string) (<-chan zk.Event, error) { } z.Unlock() if err != nil { - log.Error("zkClient{%s}.ExistsW(path{%s}) = error{%v}.", z.name, zkPath, perrors.WithStack(err)) + logger.Errorf("zkClient{%s}.ExistsW(path{%s}) = error{%v}.", z.name, zkPath, perrors.WithStack(err)) return nil, perrors.WithMessagef(err, "zk.ExistsW(path:%s)", zkPath) } if !exist { - log.Warn("zkClient{%s}'s App zk path{%s} does not exist.", z.name, zkPath) + logger.Warnf("zkClient{%s}'s App zk path{%s} does not exist.", z.name, zkPath) return nil, perrors.Errorf("zkClient{%s} App zk path{%s} does not exist.", z.name, zkPath) }