Skip to content

Commit

Permalink
V8.0.0 rc9 (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
deankarn authored Jun 8, 2022
1 parent 3123086 commit 76f472c
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 37 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [8.0.0] - 2022-05-30
## [8.0.0] - 2022-06-07
### Added
- Automatic file, line and package addition to error log when using `WithError`.

Expand All @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Documentation.
- Default timestamp format to RFC3339Nano.
- Console logger uses builder pattern.
- Removed colors from built in console logger.
- Removed ability to remove individual log levels externally; RemoveHandler+AddHandler can do the same.


[Unreleased]: https://github.com/go-playground/log/compare/v8.0.0...HEAD
Expand Down
29 changes: 11 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## log
<img align="right" src="https://raw.githubusercontent.com/go-playground/log/master/logo.png">![Project status](https://img.shields.io/badge/version-8.0.0-green.svg)
<img align="center" src="https://raw.githubusercontent.com/go-playground/log/master/logo.png">![Project status](https://img.shields.io/badge/version-8.0.0-green.svg)
[![Test](https://github.com/go-playground/log/actions/workflows/go.yml/badge.svg)](https://github.com/go-playground/log/actions/workflows/go.yml)
[![Coverage Status](https://coveralls.io/repos/github/go-playground/log/badge.svg?branch=master)](https://coveralls.io/github/go-playground/log?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/log)](https://goreportcard.com/report/github.com/go-playground/log)
Expand Down Expand Up @@ -40,12 +40,15 @@ package main

import (
"io"
stdlog "log"

"github.com/go-playground/errors/v5"
"github.com/go-playground/log/v8"
)

func main() {
log.RedirectGoStdLog(true)

// Trace
defer log.WithTrace().Info("time to run")

Expand All @@ -69,8 +72,8 @@ func main() {

// predefined global fields
log.WithDefaultFields(log.Fields{
{"program", "test"},
{"version", "0.1.3"},
log.F("program", "test"),
log.F("version", "0.1.3"),
}...)

log.WithField("key", "value").Info("testing default fields")
Expand All @@ -82,6 +85,10 @@ func main() {
)

logger.WithField("key", "value").Info("test")

stdlog.Println("This was redirected from Go STD output!")
log.RedirectGoStdLog(false)
stdlog.Println("This was NOT redirected from Go STD output!")
}
```

Expand Down Expand Up @@ -172,18 +179,4 @@ Pull requests for new handlers are welcome when they don't pull in dependencies,

Package Versioning
----------
This package strictly adheres to semantic versioning guidelines.

Benchmarks
----------
###### Run on Macbook Pro 15-inch 2017 using go version go1.9.4 darwin/amd64
NOTE: only putting benchmarks at others request, by no means does the number of allocations
make one log library better than another!
```go
go test --bench=. -benchmem=true
goos: darwin
goarch: arm64
pkg: github.com/go-playground/log/v8/benchmarks
BenchmarkLogConsoleTenFieldsParallel-8 2392591 503.3 ns/op 648 B/op 12 allocs/op
BenchmarkLogConsoleSimpleParallel-8 4595101 269.9 ns/op 56 B/op 2 allocs/op
```
This package strictly adheres to semantic versioning guidelines.
4 changes: 2 additions & 2 deletions _examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func main() {

// predefined global fields
log.WithDefaultFields(log.Fields{
{"program", "test"},
{"version", "0.1.3"},
log.F("program", "test"),
log.F("version", "0.1.3"),
}...)

log.WithField("key", "value").Info("testing default fields")
Expand Down
17 changes: 16 additions & 1 deletion benchmarks/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/go-playground/log/v8"
"github.com/go-playground/log/v8/handlers/json"
)

var errExample = errors.New("fail")
Expand Down Expand Up @@ -36,7 +37,7 @@ func TestMain(m *testing.M) {
}

func BenchmarkLogConsoleTenFieldsParallel(b *testing.B) {

log.AddHandler(log.NewConsoleBuilder().WithWriter(ioutil.Discard).Build(), log.AllLevels...)
b.ResetTimer()
// log setup in TestMain
b.RunParallel(func(pb *testing.PB) {
Expand All @@ -60,6 +61,20 @@ func BenchmarkLogConsoleTenFieldsParallel(b *testing.B) {

func BenchmarkLogConsoleSimpleParallel(b *testing.B) {

log.AddHandler(log.NewConsoleBuilder().WithWriter(ioutil.Discard).Build(), log.AllLevels...)
b.ResetTimer()
// log setup in TestMain
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
log.Info("Go fast.")
}

})
}

func BenchmarkLogJSONSimpleParallel(b *testing.B) {

log.AddHandler(json.New(ioutil.Discard), log.AllLevels...)
b.ResetTimer()
// log setup in TestMain
b.RunParallel(func(pb *testing.PB) {
Expand Down
11 changes: 5 additions & 6 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ type Entry struct {
}

func (e Entry) clone(fields ...Field) Entry {
f := make([]Field, 0, len(e.Fields)+len(fields))
e.Fields = append(f, e.Fields...)
e.Fields = append(e.Fields, fields...)
f := make([]Field, len(e.Fields)+len(fields))
copy(f[copy(f, e.Fields):], fields)
e.Fields = f
return e
}

func newEntry(fields ...Field) Entry {
e := Entry{
Fields: make([]Field, 0, len(fields)+len(logFields)),
Fields: make([]Field, len(fields)+len(logFields)),
}
e.Fields = append(e.Fields, logFields...)
e.Fields = append(e.Fields, fields...)
copy(e.Fields[copy(e.Fields, logFields):], fields)
return e
}

Expand Down
6 changes: 0 additions & 6 deletions handlers/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,3 @@ func (h *Handler) Log(e log.Entry) {
_ = h.Encoder.Encode(e)
h.m.Unlock()
}

// Close cleans up any resources and de-registers the handler with the logger
func (h *Handler) Close() error {
log.RemoveHandler(h)
return nil
}
1 change: 0 additions & 1 deletion handlers/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
func TestJSONLogger(t *testing.T) {
var buff bytes.Buffer
l := New(&buff)
defer func() { _ = l.Close() }()
log.AddHandler(l, log.AllLevels...)
log.WithField("key", "value").Debug("debug")
expected := `{"message":"debug","timestamp":"","fields":[{"key":"key","value":"value"}],"level":"DEBUG"}`
Expand Down
4 changes: 2 additions & 2 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
bytePool = &byteArrayPool{pool: &sync.Pool{
New: func() interface{} {
return &Buffer{
B: make([]byte, 0, 32),
B: make([]byte, 0, 1024),
}
},
}}
Expand Down Expand Up @@ -224,7 +224,7 @@ OUTER:
}
}

// WithDefaultFields adds fields to the underlying logger instance
// WithDefaultFields adds fields to the underlying logger instance that will be automatically added to ALL log entries.
func WithDefaultFields(fields ...Field) {
logFields = append(logFields, fields...)
}
Expand Down
Binary file added logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 76f472c

Please sign in to comment.