Skip to content

Commit

Permalink
In order to Improve performance:
Browse files Browse the repository at this point in the history
1. add structured/, which will be used to replace fmt.Print..() functions
2. use runtime.Call() to replace "stack..." package
3. use "jsoniter" to replace "encoding/json" package
  • Loading branch information
mishuyuan committed Nov 13, 2019
1 parent 5b9fe49 commit 7f66c2a
Show file tree
Hide file tree
Showing 14 changed files with 1,572 additions and 297 deletions.
3 changes: 2 additions & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ func BenchmarkDescendant8(b *testing.B) {
// (MIT License)
func newLog15() Logger {
logger := New()
logger.SetHandler(StreamHandler(ioutil.Discard, JsonFormat()))
//logger.SetHandler(StreamHandler(ioutil.Discard, JsonFormat()))
logger.SetHandler(StreamHandler(ioutil.Discard, LogfmtFormat()))
return logger
}

Expand Down
56 changes: 28 additions & 28 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,34 @@ or above in JSON formatted output to the file /var/log/service.json
Logging File Names and Line Numbers
This package implements three Handlers that add debugging information to the
context, CallerFileHandler, CallerFuncHandler and CallerStackHandler. Here's
an example that adds the source file and line number of each logging call to
the context.
h := log.CallerFileHandler(log.StdoutHandler)
log.Root().SetHandler(h)
...
log.Error("open file", "err", err)
This will output a line that looks like:
lvl=eror t=2014-05-02T16:07:23-0700 msg="open file" err="file not found" caller=data.go:42
Here's an example that logs the call stack rather than just the call site.
h := log.CallerStackHandler("%+v", log.StdoutHandler)
log.Root().SetHandler(h)
...
log.Error("open file", "err", err)
This will output a line that looks like:
lvl=eror t=2014-05-02T16:07:23-0700 msg="open file" err="file not found" stack="[pkg/data.go:42 pkg/cmd/main.go]"
The "%+v" format instructs the handler to include the path of the source file
relative to the compile time GOPATH. The github.com/go-stack/stack package
documents the full list of formatting verbs and modifiers available.
//This package implements three Handlers that add debugging information to the
//context, CallerFileHandler, CallerFuncHandler and CallerStackHandler. Here's
//an example that adds the source file and line number of each logging call to
//the context.
//
// h := log.CallerFileHandler(log.StdoutHandler)
// log.Root().SetHandler(h)
// ...
// log.Error("open file", "err", err)
//
//This will output a line that looks like:
//
// lvl=eror t=2014-05-02T16:07:23-0700 msg="open file" err="file not found" caller=data.go:42
//
//Here's an example that logs the call stack rather than just the call site.
//
// h := log.CallerStackHandler("%+v", log.StdoutHandler)
// log.Root().SetHandler(h)
// ...
// log.Error("open file", "err", err)
//
//This will output a line that looks like:
//
// lvl=eror t=2014-05-02T16:07:23-0700 msg="open file" err="file not found" stack="[pkg/data.go:42 pkg/cmd/main.go]"
//
//The "%+v" format instructs the handler to include the path of the source file
//relative to the compile time GOPATH. The github.com/go-stack/stack package
//documents the full list of formatting verbs and modifiers available.
Custom Handlers
Expand Down
Loading

0 comments on commit 7f66c2a

Please sign in to comment.