Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
change all log API call
  • Loading branch information
tianxiaoliang authored Aug 28, 2020
1 parent ca794d5 commit 9cb622d
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 173 deletions.
17 changes: 9 additions & 8 deletions archaius.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package archaius

import (
"errors"
"fmt"
"os"
"strings"

Expand All @@ -14,7 +15,7 @@ import (
"github.com/go-chassis/go-archaius/source/env"
"github.com/go-chassis/go-archaius/source/file"
"github.com/go-chassis/go-archaius/source/mem"
"github.com/go-mesh/openlogging"
"github.com/go-chassis/openlog"
)

var (
Expand All @@ -31,31 +32,31 @@ func initFileSource(o *Options) (source.ConfigSource, error) {
// adding all files with file source
for _, v := range o.RequiredFiles {
if err := fs.AddFile(v, filesource.DefaultFilePriority, o.FileHandler); err != nil {
openlogging.GetLogger().Errorf("add file source error [%s].", err.Error())
openlog.Error(fmt.Sprintf("add file source error [%s].", err.Error()))
return nil, err
}
files = append(files, v)
}
for _, v := range o.OptionalFiles {
_, err := os.Stat(v)
if os.IsNotExist(err) {
openlogging.GetLogger().Infof("[%s] not exist", v)
openlog.Info(fmt.Sprintf("[%s] not exist", v))
continue
}
if err := fs.AddFile(v, filesource.DefaultFilePriority, o.FileHandler); err != nil {
openlogging.GetLogger().Infof("%v", err)
openlog.Info(err.Error())
return nil, err
}
files = append(files, v)
}
openlogging.GetLogger().Infof("Configuration files: %s", strings.Join(files, ", "))
openlog.Info(fmt.Sprintf("Configuration files: %s", strings.Join(files, ", ")))
return fs, nil
}

// Init create a Archaius config singleton
func Init(opts ...Option) error {
if running {
openlogging.Warn("can not init archaius again, call Clean first")
openlog.Warn("can not init archaius again, call Clean first")
return nil
}
var err error
Expand Down Expand Up @@ -101,7 +102,7 @@ func Init(opts ...Option) error {
}
}

openlogging.Info("archaius init success")
openlog.Info("archaius init success")
running = true
return nil
}
Expand All @@ -128,7 +129,7 @@ func EnableRemoteSource(remoteSource string, ci *RemoteInfo) error {
return errors.New("RemoteInfo can not be empty")
}
if configServerRunning {
openlogging.Warn("can not init config server again, call Clean first")
openlog.Warn("can not init config server again, call Clean first")
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions archaius_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package archaius_test

import (
"fmt"
"github.com/go-chassis/go-archaius"
"github.com/go-chassis/go-archaius/event"
"github.com/go-mesh/openlogging"
"github.com/go-chassis/openlog"
"github.com/stretchr/testify/assert"
"io"
"os"
Expand All @@ -14,7 +15,7 @@ import (
type EListener struct{}

func (e EListener) Event(event *event.Event) {
openlogging.GetLogger().Infof("config value after change ", event.Key, " | ", event.Value)
openlog.Info(fmt.Sprintf("config value after change %s |%s", event.Key, event.Value))
}

var filename2 string
Expand Down
12 changes: 6 additions & 6 deletions event/event_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package event

import (
"errors"
"github.com/go-mesh/openlogging"
"github.com/go-chassis/openlog"
"regexp"
"strings"
)
Expand Down Expand Up @@ -77,7 +77,7 @@ func NewDispatcher() *Dispatcher {
func (dis *Dispatcher) RegisterListener(listenerObj Listener, keys ...string) error {
if listenerObj == nil {
err := ErrNilListener
openlogging.GetLogger().Error("nil listener supplied:" + err.Error())
openlog.Error("nil listener supplied:" + err.Error())
return ErrNilListener
}

Expand Down Expand Up @@ -139,12 +139,12 @@ func (dis *Dispatcher) DispatchEvent(event *Event) error {
for regKey, listeners := range dis.listeners {
matched, err := regexp.MatchString(regKey, event.Key)
if err != nil {
openlogging.GetLogger().Errorf("regular expresssion for key %s failed: %s", regKey, err)
openlog.Error("regular expression for key " + regKey + " failed:" + err.Error())
continue
}
if matched {
for _, listener := range listeners {
openlogging.GetLogger().Infof("event generated for %s", regKey)
openlog.Info("event generated for " + regKey)
go listener.Event(event)
}
}
Expand All @@ -157,7 +157,7 @@ func (dis *Dispatcher) DispatchEvent(event *Event) error {
func (dis *Dispatcher) RegisterModuleListener(listenerObj ModuleListener, modulePrefixes ...string) error {
if listenerObj == nil {
err := ErrNilListener
openlogging.GetLogger().Error("nil moduleListener supplied:" + err.Error())
openlog.Error("nil moduleListener supplied:" + err.Error())
return ErrNilListener
}

Expand Down Expand Up @@ -223,7 +223,7 @@ func (dis *Dispatcher) DispatchModuleEvent(events []*Event) error {
for key, events := range eventsList {
if listeners, ok := dis.moduleListeners[key]; ok {
for _, listener := range listeners {
openlogging.GetLogger().Infof("events generated for %s", key)
openlog.Info("events generated for " + key)
go listener.Event(events)
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/apollo/apollo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/go-chassis/go-archaius/event"
"github.com/go-chassis/go-archaius/source/apollo"
_ "github.com/go-chassis/go-archaius/source/apollo"
"github.com/go-mesh/openlogging"
"github.com/go-chassis/openlog"
"time"
)

Expand All @@ -17,9 +17,9 @@ type Listener struct {

func (li *Listener) Event(event *event.Event) {
fmt.Printf("listen:%+v", *event)
openlogging.GetLogger().Info(event.Key)
openlogging.GetLogger().Infof(fmt.Sprintf("%v\n", event.Value))
openlogging.GetLogger().Info(event.EventType)
openlog.Info(event.Key)
openlog.Info(fmt.Sprintf("%v\n", event.Value))
openlog.Info(event.EventType)
}

func main() {
Expand Down
10 changes: 5 additions & 5 deletions examples/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/go-chassis/go-archaius"
"github.com/go-chassis/go-archaius/event"
"github.com/go-mesh/openlogging"
"github.com/go-chassis/openlog"
)

//Listener is a struct used for Event listener
Expand All @@ -17,17 +17,17 @@ type Listener struct {

//Event is a method for QPS event listening
func (e *Listener) Event(event *event.Event) {
openlogging.GetLogger().Info(event.Key)
openlogging.GetLogger().Infof(fmt.Sprintf("%v", event.Value))
openlogging.GetLogger().Info(event.EventType)
openlog.Info(event.Key)
openlog.Info(fmt.Sprintf("%v", event.Value))
openlog.Info(event.EventType)
}

func main() {
err := archaius.Init(archaius.WithRequiredFiles([]string{
"./event.yaml",
}))
if err != nil {
openlogging.GetLogger().Error("Error:" + err.Error())
openlog.Error("Error:" + err.Error())
}
archaius.RegisterListener(&Listener{}, "age")
for {
Expand Down
4 changes: 2 additions & 2 deletions examples/file/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package main
import (
"github.com/go-chassis/go-archaius"
"github.com/go-chassis/go-archaius/source/util"
"github.com/go-mesh/openlogging"
"github.com/go-chassis/openlog"
"log"
)

func main() {
err := archaius.Init(archaius.WithRequiredFiles([]string{"./dir", "f1.yaml"}))
if err != nil {
openlogging.GetLogger().Error("Error:" + err.Error())
openlog.Error("Error:" + err.Error())
}
log.Println(archaius.Get("age"))
log.Println(archaius.Get("name"))
Expand Down
4 changes: 2 additions & 2 deletions examples/kie/kie.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"github.com/go-chassis/go-archaius/event"
"github.com/go-chassis/go-archaius/source/remote"
_ "github.com/go-chassis/go-archaius/source/remote/kie"
"github.com/go-mesh/openlogging"
"github.com/go-chassis/openlog"
)

type Listener struct {
Key string
}

func (li *Listener) Event(event *event.Event) {
openlogging.GetLogger().Infof("change event :%+v", *event)
openlog.Info(fmt.Sprintf("change event : %+v", *event))
}

func main() {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/go-chassis/go-archaius
require (
github.com/Shonminh/apollo-client v0.4.0
github.com/fsnotify/fsnotify v1.4.7
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4
github.com/go-mesh/openlogging v1.0.1
github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3
github.com/go-chassis/openlog v1.1.1
github.com/gorilla/websocket v1.4.0
github.com/spf13/cast v1.2.0
github.com/stretchr/testify v1.4.0
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,25 @@ github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ=
github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4 h1:wx8JXvg/n4i8acXsBJ5zIkiK7EO2kn/HuEjKK3kSgv8=
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c=
github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3 h1:c+bwT0qLY69jSU8TmzuNcb9UL/QFAiU96kjuX5TMiQc=
github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c=
github.com/go-chassis/go-archaius v1.0.0/go.mod h1:Px2evF91zbMr78UQ+lwehjEwXelwgvTtHzIeODsBEEE=
github.com/go-chassis/go-chassis v1.8.2-0.20191227102336-e3ac2ea137b1 h1:7cVyV9MzmpzCPobya0nlxAkUTLPpT3iGmnvCAu5R/gE=
github.com/go-chassis/go-chassis v1.8.2-0.20191227102336-e3ac2ea137b1/go.mod h1:vI0rU2FNAtGi6owfYKXBVj6cvq633/n+8bqbsVfib7E=
github.com/go-chassis/go-restful-swagger20 v1.0.2 h1:Zq74EQP7IjlJK/PnYP/rF3Ptk2QskZVPoNgiVwtvpFM=
github.com/go-chassis/go-restful-swagger20 v1.0.2/go.mod h1:ZK4hlfS6Q6E46ViezAjn6atrzoteyWl1OBEpUBn/36k=
github.com/go-chassis/openlog v1.0.1 h1:6raaXo8SK+wuQX1VoNi6QJCSf1fTOFWh7f5f6b2ZEmY=
github.com/go-chassis/openlog v1.0.1/go.mod h1:qaKi+amO+hsGin2q1GmW+/NcbZpMPnTufwrWzDmIuuU=
github.com/go-chassis/openlog v1.1.1 h1:iX7U0JP52SaJc5p7iOPVvpcbx3ML/53U1RuZDArW9xc=
github.com/go-chassis/openlog v1.1.1/go.mod h1:ZZOS68OvrFIKEJbuBa4YnYzmxyVx3lmcMfMKb+Hx/yQ=
github.com/go-chassis/paas-lager v1.0.2-0.20190328010332-cf506050ddb2/go.mod h1:tILYbn3+0jjCxhY6/ue9L8eRq+VJ60U6VYIdugqchB4=
github.com/go-chassis/paas-lager v1.1.1 h1:/6wqawUGjPCpd57A/tzJzgC4MnEhNuigbayQS+2VWPQ=
github.com/go-chassis/paas-lager v1.1.1/go.mod h1:tILYbn3+0jjCxhY6/ue9L8eRq+VJ60U6VYIdugqchB4=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-mesh/openlogging v1.0.1 h1:6raaXo8SK+wuQX1VoNi6QJCSf1fTOFWh7f5f6b2ZEmY=
github.com/go-mesh/openlogging v1.0.1/go.mod h1:qaKi+amO+hsGin2q1GmW+/NcbZpMPnTufwrWzDmIuuU=
github.com/go-mesh/openlogging v1.1.1 h1:tCZw9YA0hfcNZWmixQND0oZIpjxX0rhUS8kZZsA/gCc=
github.com/go-mesh/openlogging v1.1.1/go.mod h1:qaKi+amO+hsGin2q1GmW+/NcbZpMPnTufwrWzDmIuuU=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc=
Expand Down
Loading

0 comments on commit 9cb622d

Please sign in to comment.