Skip to content

Commit

Permalink
Merge pull request #16 from tianxiaoliang/master
Browse files Browse the repository at this point in the history
support depth
  • Loading branch information
tianxiaoliang authored Nov 23, 2018
2 parents eff93e5 + ef83ebb commit 005283c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ jobs:
script:
- go get -u github.com/jgautheron/goconst/cmd/goconst
- bash -x scripts/travis/goConstChecker.sh
- stage: GoLint Checker
script:
- go get -u github.com/golang/lint/golint
- bash -x scripts/travis/goLintChecker.sh
- stage: GoCyclo Checker
script:
- go get github.com/fzipp/gocyclo
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ func main() {
}

```
See [Example](examples/main.go)
See [Examples](examples)
8 changes: 4 additions & 4 deletions examples/main.go → examples/native/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func main() {
rotate.RunLogRotate("test.log", &rotate.RotateConfig{}, logger)
logger.Infof("Hi %s, system is starting up ...", "paas-bot")

logger.Debug("check-info", openlogging.Tags{
logger.Debug("check-info", openlogging.WithTags(openlogging.Tags{
"info": "something",
})
}))

logger.Warn("failed-to-do-somthing", openlogging.Tags{
logger.Warn("failed-to-do-somthing", openlogging.WithTags(openlogging.Tags{
"info": "something",
})
}))
logger.Warnf("failed-to-do-%s-somthing", "1")

logger.Error("failed-to-do-somthing")
Expand Down
32 changes: 32 additions & 0 deletions examples/openlogging/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"github.com/go-chassis/paas-lager"
"github.com/go-mesh/openlogging"
)

func main() {
log.Init(log.Config{
LoggerLevel: "DEBUG",
LoggerFile: "test.log",
EnableRsyslog: false,
LogFormatText: true,
Writers: []string{"file", "stdout"},
})

logger := log.NewLogger("example")
openlogging.SetLogger(logger)

openlogging.Debug("check-info", openlogging.WithTags(openlogging.Tags{
"info": "something",
}))

openlogging.Warn("failed-to-do-somthing", openlogging.WithTags(openlogging.Tags{
"info": "something",
}))

openlogging.Error("failed-to-do-somthing")

openlogging.Info("shutting-down")

}
18 changes: 1 addition & 17 deletions lager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package log_test
import (
"fmt"
"github.com/go-chassis/paas-lager"
"gopkg.in/yaml.v2"
"testing"
)

func BenchmarkInit(b *testing.B) {
log.Init(log.Config{
LoggerLevel: "DEBUG",
LogFormatText: true,
Writers: []string{"file", "stdout"},
Writers: []string{"stdout"},
})

logger := log.NewLogger("example")
Expand All @@ -34,18 +33,3 @@ func (w *w) Write(p []byte) (n int, err error) {
func TestRegisterWriter(t *testing.T) {
log.RegisterWriter("test", &w{})
}

func TestInit(t *testing.T) {
b := []byte(`
writers: [file, stdout]
`)
c := &log.Config{}
err := yaml.Unmarshal(b, c)
if err != nil {
t.Error(err)
}
if len(c.Writers) != 2 {
t.Error(c.Writers)
}
}
6 changes: 3 additions & 3 deletions third_party/forked/cloudfoundry/lager/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (l *logger) logs(ss []Sink, loglevel LogLevel, action string, opts ...openl
}

// add file, lineno
addExtLogInfo(&log)
addExtLogInfo(&log, opt.Depth)
var logInfo string
for _, sink := range l.sinks {
if l.logFormatText {
Expand Down Expand Up @@ -256,10 +256,10 @@ func currentTimestamp() string {
return time.Now().Format("2006-01-02 15:04:05.000 -07:00")
}

func addExtLogInfo(logf *LogFormat) {
func addExtLogInfo(logf *LogFormat, depth int) {

for i := 3; i <= 5; i++ {
_, file, line, ok := runtime.Caller(i)
_, file, line, ok := runtime.Caller(depth + i)

if strings.Index(file, "logger.go") > 0 {
continue
Expand Down

0 comments on commit 005283c

Please sign in to comment.