Skip to content

Commit

Permalink
update log demo
Browse files Browse the repository at this point in the history
  • Loading branch information
zouyx committed Sep 14, 2020
1 parent 2a041dc commit ebd94cf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
23 changes: 21 additions & 2 deletions custom/log/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/cihub/seelog"
"github.com/zouyx/agollo/v4"
"github.com/zouyx/agollo/v4/env/config"
)
Expand All @@ -16,7 +17,9 @@ func main() {
IsBackupConfig: false,
Secret: "6ce3ff7e96a24335a9634fe9abca6d51",
}
agollo.SetLogger(&DefaultLogger{})

loggerInterface:=initSeeLog("seelog.xml")
agollo.SetLogger(&DefaultLogger{loggerInterface})

client,error:=agollo.StartWithConfig(func() (*config.AppConfig, error) {
return c, nil
Expand All @@ -36,6 +39,7 @@ func writeConfig(namespace string,client *agollo.Client) {
}

type DefaultLogger struct {
log seelog.LoggerInterface
}

func (this *DefaultLogger) Debugf(format string, params ...interface{}) {
Expand All @@ -55,7 +59,7 @@ func (this *DefaultLogger) Errorf(format string, params ...interface{}) {
}

func (this *DefaultLogger) Debug(v ...interface{}) {
fmt.Println(v)
this.log.Debug(v)
}
func (this *DefaultLogger) Info(v ...interface{}) {
this.Debug(v)
Expand All @@ -67,4 +71,19 @@ func (this *DefaultLogger) Warn(v ...interface{}) {

func (this *DefaultLogger) Error(v ...interface{}) {
this.Debug(v)
}

func initSeeLog(configPath string) seelog.LoggerInterface {
logger, err := seelog.LoggerFromConfigAsFile(configPath)

//if error is happen change to default config.
if err != nil {
logger, err = seelog.LoggerFromConfigAsBytes([]byte("<seelog />"))
}

logger.SetAdditionalStackDepth(1)
seelog.ReplaceLogger(logger)
defer seelog.Flush()

return logger
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module github.com/zouyx/agollo_demo

require github.com/zouyx/agollo/v4 v4.0.0-20200914102923-3ec4472360b3
require (
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
github.com/zouyx/agollo/v4 v4.0.0-20200914102923-3ec4472360b3
)

go 1.13
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 h1:kHaBemcxl8o/pQ5VM1c8PVE1PubbNx3mjUr09OqWGCs=
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575/go.mod h1:9d6lWj8KzO/fd/NrVaLscBKmPigpZpn5YawRPw+e3Yo=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down

0 comments on commit ebd94cf

Please sign in to comment.