From e114c1be439e466203d63966384dfb86afe8c7e3 Mon Sep 17 00:00:00 2001 From: Joe Zou Date: Sat, 28 Sep 2019 15:52:37 +0800 Subject: [PATCH 1/3] remove seelog from agollo --- README.md | 26 +++++++++++++++++++++----- depend.sh | 1 - log.go | 47 ++++++++++++++++++++++++++++++++--------------- log_test.go | 12 ------------ start.go | 27 +++++++++++++++++---------- 5 files changed, 70 insertions(+), 43 deletions(-) delete mode 100644 log_test.go diff --git a/README.md b/README.md index 83f43ed2..fd16eab5 100644 --- a/README.md +++ b/README.md @@ -19,17 +19,22 @@ Installation 如果还没有安装Go开发环境,请参考以下文档[Getting Started](http://golang.org/doc/install.html) ,安装完成后,请执行以下命令: ``` shell -gopm get github.com/cihub/seelog -v -g gopm get github.com/coocood/freecache -v -g ``` 或者 ``` shell -go get -u github.com/cihub/seelog go get -u github.com/coocood/freecache ``` +或者 + +```shell +chmod u+x ./depend.sh +./depend.sh +``` + *请注意*: 最好使用Go 1.8进行开发 @@ -37,7 +42,8 @@ go get -u github.com/coocood/freecache * 实时同步配置 * 灰度配置 * 客户端容灾 -* 配置文件容灾 (v1.6.0+) +* 配置文件容灾 (v1.6.0+) +* 自定义日志组件 (因开源协议原因,从v1.8.0不再存在默认日志组件。请参考自定义日志组件实现) # Usage @@ -65,7 +71,7 @@ func main() { ``` go func main() { - go agollo.StartWithLogger(loggerInterface) + agollo.StartWithLogger(loggerInterface) } ``` @@ -73,7 +79,17 @@ func main() { ``` go func main() { - go agollo.StartWithCache(cacheInterface) + agollo.StartWithCache(cacheInterface) +} +``` + +- 启动agollo - 自定义各种控件 (v1.8.0+) + +```go +func main() { + agollo.SetLogger(loggerInterface) + agollo.SetCache(cacheInterface) + agollo.Start() } ``` diff --git a/depend.sh b/depend.sh index cc3c53c1..92e59d5d 100755 --- a/depend.sh +++ b/depend.sh @@ -1,2 +1 @@ -go get -u github.com/cihub/seelog go get -u github.com/coocood/freecache \ No newline at end of file diff --git a/log.go b/log.go index 2746ca98..08553162 100644 --- a/log.go +++ b/log.go @@ -1,13 +1,9 @@ package agollo -import ( - "github.com/cihub/seelog" -) - var logger LoggerInterface func init() { - initLogger(initSeeLog("seelog.xml")) + logger=&DefaultLogger{} } func initLogger(ILogger LoggerInterface) { @@ -32,17 +28,38 @@ type LoggerInterface interface { Error(v ...interface{}) error } -func initSeeLog(configPath string) LoggerInterface { - logger, err := seelog.LoggerFromConfigAsFile(configPath) +type DefaultLogger struct { +} - //if error is happen change to default config. - if err != nil { - logger, err = seelog.LoggerFromConfigAsBytes([]byte("")) - } +func (this *DefaultLogger)Debugf(format string, params ...interface{}) { + +} - logger.SetAdditionalStackDepth(1) - seelog.ReplaceLogger(logger) - defer seelog.Flush() +func (this *DefaultLogger)Infof(format string, params ...interface{}) { - return logger } + + +func (this *DefaultLogger)Warnf(format string, params ...interface{}) error { + return nil +} + +func (this *DefaultLogger)Errorf(format string, params ...interface{}) error { + return nil +} + + +func (this *DefaultLogger)Debug(v ...interface{}) { + +} +func (this *DefaultLogger)Info(v ...interface{}){ + +} + +func (this *DefaultLogger)Warn(v ...interface{}) error{ + return nil +} + +func (this *DefaultLogger)Error(v ...interface{}) error{ + return nil +} \ No newline at end of file diff --git a/log_test.go b/log_test.go deleted file mode 100644 index 762d3199..00000000 --- a/log_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package agollo - -import ( - "github.com/cihub/seelog" - "testing" -) - -func TestInitNullSeeLog(t *testing.T) { - initSeeLog("joe.config") - - seelog.Error("good girl!") -} diff --git a/start.go b/start.go index a1512fa7..7f98d97a 100644 --- a/start.go +++ b/start.go @@ -2,25 +2,32 @@ package agollo //start apollo func Start() error { - return StartWithLogger(nil) + return startAgollo() } -func StartWithLogger(loggerInterface LoggerInterface) error { - return StartWithParams(loggerInterface,nil) -} - -func StartWithCache(cacheInterface CacheInterface) error { - return StartWithParams(nil,cacheInterface) -} - -func StartWithParams(loggerInterface LoggerInterface,cacheInterface CacheInterface) error { +func SetLogger(loggerInterface LoggerInterface) { if loggerInterface != nil { initLogger(loggerInterface) } +} + +func SetCache(cacheInterface CacheInterface) { if cacheInterface != nil { initCache(cacheInterface) } +} + +func StartWithLogger(loggerInterface LoggerInterface) error { + SetLogger(loggerInterface) + return startAgollo() +} + +func StartWithCache(cacheInterface CacheInterface) error { + SetCache(cacheInterface) + return startAgollo() +} +func startAgollo() error { //init server ip list go initServerIpList() From ab8f6979d909266ec2ad183851e6d88c4f8236b7 Mon Sep 17 00:00:00 2001 From: Joe Zou Date: Sat, 28 Sep 2019 16:07:31 +0800 Subject: [PATCH 2/3] remove seelog from agollo --- seelog.xml | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 seelog.xml diff --git a/seelog.xml b/seelog.xml deleted file mode 100644 index a12599af..00000000 --- a/seelog.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file From 11ee33ab8fe7023e571f07414bd32daa2bbcaba5 Mon Sep 17 00:00:00 2001 From: Joe Zou Date: Sat, 28 Sep 2019 16:26:01 +0800 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fd16eab5..0387673b 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ chmod u+x ./depend.sh * 灰度配置 * 客户端容灾 * 配置文件容灾 (v1.6.0+) -* 自定义日志组件 (因开源协议原因,从v1.8.0不再存在默认日志组件。请参考自定义日志组件实现) +* 自定义日志组件 (因开源协议原因,从v1.8.0不再存在默认日志组件。如还需使用seelog,请参考:[如何使用seelog](https://github.com/zouyx/agollo/wiki/%E4%BD%BF%E7%94%A8seelog%E6%97%A5%E5%BF%97%E7%BB%84%E4%BB%B6)) # Usage