Skip to content

Commit

Permalink
Finish RemoveLog
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed Sep 28, 2019
2 parents b300395 + 11ee33a commit c7fd672
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 55 deletions.
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,31 @@ 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进行开发

# Features
* 实时同步配置
* 灰度配置
* 客户端容灾
* 配置文件容灾 (v1.6.0+)
* 配置文件容灾 (v1.6.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

Expand Down Expand Up @@ -65,15 +71,25 @@ func main() {

``` go
func main() {
go agollo.StartWithLogger(loggerInterface)
agollo.StartWithLogger(loggerInterface)
}
```

- 启动agollo - 自定义cache控件 (v1.7.0+)

``` 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()
}
```

Expand Down
1 change: 0 additions & 1 deletion depend.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
go get -u github.com/cihub/seelog
go get -u github.com/coocood/freecache
47 changes: 32 additions & 15 deletions log.go
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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("<seelog />"))
}
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
}
12 changes: 0 additions & 12 deletions log_test.go

This file was deleted.

12 changes: 0 additions & 12 deletions seelog.xml

This file was deleted.

27 changes: 17 additions & 10 deletions start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit c7fd672

Please sign in to comment.