Skip to content

Commit 76f472c

Browse files
author
Dean Karn
authored
V8.0.0 rc9 (#47)
1 parent 3123086 commit 76f472c

File tree

9 files changed

+39
-37
lines changed

9 files changed

+39
-37
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

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

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

2628

2729
[Unreleased]: https://github.com/go-playground/log/compare/v8.0.0...HEAD

README.md

+11-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## log
2-
<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)
2+
<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)
33
[![Test](https://github.com/go-playground/log/actions/workflows/go.yml/badge.svg)](https://github.com/go-playground/log/actions/workflows/go.yml)
44
[![Coverage Status](https://coveralls.io/repos/github/go-playground/log/badge.svg?branch=master)](https://coveralls.io/github/go-playground/log?branch=master)
55
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/log)](https://goreportcard.com/report/github.com/go-playground/log)
@@ -40,12 +40,15 @@ package main
4040

4141
import (
4242
"io"
43+
stdlog "log"
4344

4445
"github.com/go-playground/errors/v5"
4546
"github.com/go-playground/log/v8"
4647
)
4748

4849
func main() {
50+
log.RedirectGoStdLog(true)
51+
4952
// Trace
5053
defer log.WithTrace().Info("time to run")
5154

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

7073
// predefined global fields
7174
log.WithDefaultFields(log.Fields{
72-
{"program", "test"},
73-
{"version", "0.1.3"},
75+
log.F("program", "test"),
76+
log.F("version", "0.1.3"),
7477
}...)
7578

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

8487
logger.WithField("key", "value").Info("test")
88+
89+
stdlog.Println("This was redirected from Go STD output!")
90+
log.RedirectGoStdLog(false)
91+
stdlog.Println("This was NOT redirected from Go STD output!")
8592
}
8693
```
8794

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

173180
Package Versioning
174181
----------
175-
This package strictly adheres to semantic versioning guidelines.
176-
177-
Benchmarks
178-
----------
179-
###### Run on Macbook Pro 15-inch 2017 using go version go1.9.4 darwin/amd64
180-
NOTE: only putting benchmarks at others request, by no means does the number of allocations
181-
make one log library better than another!
182-
```go
183-
go test --bench=. -benchmem=true
184-
goos: darwin
185-
goarch: arm64
186-
pkg: github.com/go-playground/log/v8/benchmarks
187-
BenchmarkLogConsoleTenFieldsParallel-8 2392591 503.3 ns/op 648 B/op 12 allocs/op
188-
BenchmarkLogConsoleSimpleParallel-8 4595101 269.9 ns/op 56 B/op 2 allocs/op
189-
```
182+
This package strictly adheres to semantic versioning guidelines.

_examples/basic/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ func main() {
3434

3535
// predefined global fields
3636
log.WithDefaultFields(log.Fields{
37-
{"program", "test"},
38-
{"version", "0.1.3"},
37+
log.F("program", "test"),
38+
log.F("version", "0.1.3"),
3939
}...)
4040

4141
log.WithField("key", "value").Info("testing default fields")

benchmarks/benchmark_test.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/go-playground/log/v8"
11+
"github.com/go-playground/log/v8/handlers/json"
1112
)
1213

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

3839
func BenchmarkLogConsoleTenFieldsParallel(b *testing.B) {
39-
40+
log.AddHandler(log.NewConsoleBuilder().WithWriter(ioutil.Discard).Build(), log.AllLevels...)
4041
b.ResetTimer()
4142
// log setup in TestMain
4243
b.RunParallel(func(pb *testing.PB) {
@@ -60,6 +61,20 @@ func BenchmarkLogConsoleTenFieldsParallel(b *testing.B) {
6061

6162
func BenchmarkLogConsoleSimpleParallel(b *testing.B) {
6263

64+
log.AddHandler(log.NewConsoleBuilder().WithWriter(ioutil.Discard).Build(), log.AllLevels...)
65+
b.ResetTimer()
66+
// log setup in TestMain
67+
b.RunParallel(func(pb *testing.PB) {
68+
for pb.Next() {
69+
log.Info("Go fast.")
70+
}
71+
72+
})
73+
}
74+
75+
func BenchmarkLogJSONSimpleParallel(b *testing.B) {
76+
77+
log.AddHandler(json.New(ioutil.Discard), log.AllLevels...)
6378
b.ResetTimer()
6479
// log setup in TestMain
6580
b.RunParallel(func(pb *testing.PB) {

entry.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ type Entry struct {
1818
}
1919

2020
func (e Entry) clone(fields ...Field) Entry {
21-
f := make([]Field, 0, len(e.Fields)+len(fields))
22-
e.Fields = append(f, e.Fields...)
23-
e.Fields = append(e.Fields, fields...)
21+
f := make([]Field, len(e.Fields)+len(fields))
22+
copy(f[copy(f, e.Fields):], fields)
23+
e.Fields = f
2424
return e
2525
}
2626

2727
func newEntry(fields ...Field) Entry {
2828
e := Entry{
29-
Fields: make([]Field, 0, len(fields)+len(logFields)),
29+
Fields: make([]Field, len(fields)+len(logFields)),
3030
}
31-
e.Fields = append(e.Fields, logFields...)
32-
e.Fields = append(e.Fields, fields...)
31+
copy(e.Fields[copy(e.Fields, logFields):], fields)
3332
return e
3433
}
3534

handlers/json/json.go

-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,3 @@ func (h *Handler) Log(e log.Entry) {
2828
_ = h.Encoder.Encode(e)
2929
h.m.Unlock()
3030
}
31-
32-
// Close cleans up any resources and de-registers the handler with the logger
33-
func (h *Handler) Close() error {
34-
log.RemoveHandler(h)
35-
return nil
36-
}

handlers/json/json_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
func TestJSONLogger(t *testing.T) {
1212
var buff bytes.Buffer
1313
l := New(&buff)
14-
defer func() { _ = l.Close() }()
1514
log.AddHandler(l, log.AllLevels...)
1615
log.WithField("key", "value").Debug("debug")
1716
expected := `{"message":"debug","timestamp":"","fields":[{"key":"key","value":"value"}],"level":"DEBUG"}`

log.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var (
1717
bytePool = &byteArrayPool{pool: &sync.Pool{
1818
New: func() interface{} {
1919
return &Buffer{
20-
B: make([]byte, 0, 32),
20+
B: make([]byte, 0, 1024),
2121
}
2222
},
2323
}}
@@ -224,7 +224,7 @@ OUTER:
224224
}
225225
}
226226

227-
// WithDefaultFields adds fields to the underlying logger instance
227+
// WithDefaultFields adds fields to the underlying logger instance that will be automatically added to ALL log entries.
228228
func WithDefaultFields(fields ...Field) {
229229
logFields = append(logFields, fields...)
230230
}

logo.png

119 KB
Loading

0 commit comments

Comments
 (0)