adding in logging
This commit is contained in:
58
vendor/go.uber.org/zap/benchmarks/apex_test.go
generated
vendored
Normal file
58
vendor/go.uber.org/zap/benchmarks/apex_test.go
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package benchmarks
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/apex/log/handlers/json"
|
||||
)
|
||||
|
||||
func newDisabledApexLog() *log.Logger {
|
||||
return &log.Logger{
|
||||
Handler: json.New(ioutil.Discard),
|
||||
Level: log.ErrorLevel,
|
||||
}
|
||||
}
|
||||
|
||||
func newApexLog() *log.Logger {
|
||||
return &log.Logger{
|
||||
Handler: json.New(ioutil.Discard),
|
||||
Level: log.DebugLevel,
|
||||
}
|
||||
}
|
||||
|
||||
func fakeApexFields() log.Fields {
|
||||
return log.Fields{
|
||||
"int": 1,
|
||||
"int64": int64(1),
|
||||
"float": 3.0,
|
||||
"string": "four!",
|
||||
"bool": true,
|
||||
"time": time.Unix(0, 0),
|
||||
"error": errExample.Error(),
|
||||
"duration": time.Second,
|
||||
"user-defined type": _jane,
|
||||
"another string": "done!",
|
||||
}
|
||||
}
|
||||
23
vendor/go.uber.org/zap/benchmarks/doc.go
generated
vendored
Normal file
23
vendor/go.uber.org/zap/benchmarks/doc.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
// Package benchmarks contains only benchmarks comparing zap to other
|
||||
// structured logging libraries.
|
||||
package benchmarks
|
||||
31
vendor/go.uber.org/zap/benchmarks/kit_test.go
generated
vendored
Normal file
31
vendor/go.uber.org/zap/benchmarks/kit_test.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package benchmarks
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/go-kit/kit/log"
|
||||
)
|
||||
|
||||
func newKitLog(fields ...interface{}) log.Logger {
|
||||
return log.With(log.NewJSONLogger(ioutil.Discard), fields...)
|
||||
}
|
||||
31
vendor/go.uber.org/zap/benchmarks/lion_test.go
generated
vendored
Normal file
31
vendor/go.uber.org/zap/benchmarks/lion_test.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package benchmarks
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"go.pedge.io/lion"
|
||||
)
|
||||
|
||||
func newLion() lion.Logger {
|
||||
return lion.NewLogger(lion.NewJSONWritePusher(ioutil.Discard))
|
||||
}
|
||||
33
vendor/go.uber.org/zap/benchmarks/log15_test.go
generated
vendored
Normal file
33
vendor/go.uber.org/zap/benchmarks/log15_test.go
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package benchmarks
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"gopkg.in/inconshreveable/log15.v2"
|
||||
)
|
||||
|
||||
func newLog15() log15.Logger {
|
||||
logger := log15.New()
|
||||
logger.SetHandler(log15.StreamHandler(ioutil.Discard, log15.JsonFormat()))
|
||||
return logger
|
||||
}
|
||||
58
vendor/go.uber.org/zap/benchmarks/logrus_test.go
generated
vendored
Normal file
58
vendor/go.uber.org/zap/benchmarks/logrus_test.go
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package benchmarks
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func newDisabledLogrus() *logrus.Logger {
|
||||
logger := newLogrus()
|
||||
logger.Level = logrus.ErrorLevel
|
||||
return logger
|
||||
}
|
||||
|
||||
func newLogrus() *logrus.Logger {
|
||||
return &logrus.Logger{
|
||||
Out: ioutil.Discard,
|
||||
Formatter: new(logrus.JSONFormatter),
|
||||
Hooks: make(logrus.LevelHooks),
|
||||
Level: logrus.DebugLevel,
|
||||
}
|
||||
}
|
||||
|
||||
func fakeLogrusFields() logrus.Fields {
|
||||
return logrus.Fields{
|
||||
"int": 1,
|
||||
"int64": int64(1),
|
||||
"float": 3.0,
|
||||
"string": "four!",
|
||||
"bool": true,
|
||||
"time": time.Unix(0, 0),
|
||||
"error": errExample.Error(),
|
||||
"duration": time.Second,
|
||||
"user-defined type": _jane,
|
||||
"another string": "done!",
|
||||
}
|
||||
}
|
||||
565
vendor/go.uber.org/zap/benchmarks/scenario_bench_test.go
generated
vendored
Normal file
565
vendor/go.uber.org/zap/benchmarks/scenario_bench_test.go
generated
vendored
Normal file
@@ -0,0 +1,565 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package benchmarks
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func BenchmarkDisabledWithoutFields(b *testing.B) {
|
||||
b.Logf("Logging at a disabled level without any structured context.")
|
||||
b.Run("Zap", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Check", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
if m := logger.Check(zap.InfoLevel, getMessage(0)); m != nil {
|
||||
m.Write()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Sugar", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.SugarFormatting", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Infof("%v %v %v %s %v %v %v %v %v %s\n",
|
||||
1,
|
||||
int64(1),
|
||||
3.0,
|
||||
"four!",
|
||||
true,
|
||||
time.Unix(0, 0),
|
||||
errExample,
|
||||
time.Second,
|
||||
_jane,
|
||||
"done!",
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("apex/log", func(b *testing.B) {
|
||||
logger := newDisabledApexLog()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("sirupsen/logrus", func(b *testing.B) {
|
||||
logger := newDisabledLogrus()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkDisabledAccumulatedContext(b *testing.B) {
|
||||
b.Logf("Logging at a disabled level with some accumulated context.")
|
||||
b.Run("Zap", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel).With(fakeFields()...)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Check", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel).With(fakeFields()...)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
if m := logger.Check(zap.InfoLevel, getMessage(0)); m != nil {
|
||||
m.Write()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Sugar", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel).With(fakeFields()...).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.SugarFormatting", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel).With(fakeFields()...).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Infof("%v %v %v %s %v %v %v %v %v %s\n",
|
||||
1,
|
||||
int64(1),
|
||||
3.0,
|
||||
"four!",
|
||||
true,
|
||||
time.Unix(0, 0),
|
||||
errExample,
|
||||
time.Second,
|
||||
_jane,
|
||||
"done!",
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("apex/log", func(b *testing.B) {
|
||||
logger := newDisabledApexLog().WithFields(fakeApexFields())
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("sirupsen/logrus", func(b *testing.B) {
|
||||
logger := newDisabledLogrus().WithFields(fakeLogrusFields())
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkDisabledAddingFields(b *testing.B) {
|
||||
b.Logf("Logging at a disabled level, adding context at each log site.")
|
||||
b.Run("Zap", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0), fakeFields()...)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Check", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
if m := logger.Check(zap.InfoLevel, getMessage(0)); m != nil {
|
||||
m.Write(fakeFields()...)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Sugar", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.ErrorLevel).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Infow(getMessage(0), fakeSugarFields()...)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("apex/log", func(b *testing.B) {
|
||||
logger := newDisabledApexLog()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.WithFields(fakeApexFields()).Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("sirupsen/logrus", func(b *testing.B) {
|
||||
logger := newDisabledLogrus()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.WithFields(fakeLogrusFields()).Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkWithoutFields(b *testing.B) {
|
||||
b.Logf("Logging without any structured context.")
|
||||
b.Run("Zap", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Check", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
if ce := logger.Check(zap.InfoLevel, getMessage(0)); ce != nil {
|
||||
ce.Write()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.CheckSampled", func(b *testing.B) {
|
||||
logger := newSampledLogger(zap.DebugLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
i := 0
|
||||
for pb.Next() {
|
||||
i++
|
||||
if ce := logger.Check(zap.InfoLevel, getMessage(i)); ce != nil {
|
||||
ce.Write()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Sugar", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.SugarFormatting", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Infof("%v %v %v %s %v %v %v %v %v %s\n",
|
||||
1,
|
||||
int64(1),
|
||||
3.0,
|
||||
"four!",
|
||||
true,
|
||||
time.Unix(0, 0),
|
||||
errExample,
|
||||
time.Second,
|
||||
_jane,
|
||||
"done!",
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("apex/log", func(b *testing.B) {
|
||||
logger := newApexLog()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("go-kit/kit/log", func(b *testing.B) {
|
||||
logger := newKitLog()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Log(getMessage(0), getMessage(1))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("inconshreveable/log15", func(b *testing.B) {
|
||||
logger := newLog15()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("sirupsen/logrus", func(b *testing.B) {
|
||||
logger := newLogrus()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("go.pedge.io/lion", func(b *testing.B) {
|
||||
logger := newLion()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Printf(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("stdlib.Println", func(b *testing.B) {
|
||||
logger := log.New(ioutil.Discard, "", log.LstdFlags)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Println(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("stdlib.Printf", func(b *testing.B) {
|
||||
logger := log.New(ioutil.Discard, "", log.LstdFlags)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Printf("%v %v %v %s %v %v %v %v %v %s\n",
|
||||
1,
|
||||
int64(1),
|
||||
3.0,
|
||||
"four!",
|
||||
true,
|
||||
time.Unix(0, 0),
|
||||
errExample,
|
||||
time.Second,
|
||||
_jane,
|
||||
"done!",
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkAccumulatedContext(b *testing.B) {
|
||||
b.Logf("Logging with some accumulated context.")
|
||||
b.Run("Zap", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel).With(fakeFields()...)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Check", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel).With(fakeFields()...)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
if ce := logger.Check(zap.InfoLevel, getMessage(0)); ce != nil {
|
||||
ce.Write()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.CheckSampled", func(b *testing.B) {
|
||||
logger := newSampledLogger(zap.DebugLevel).With(fakeFields()...)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
i := 0
|
||||
for pb.Next() {
|
||||
i++
|
||||
if ce := logger.Check(zap.InfoLevel, getMessage(i)); ce != nil {
|
||||
ce.Write()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Sugar", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel).With(fakeFields()...).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.SugarFormatting", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel).With(fakeFields()...).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Infof("%v %v %v %s %v %v %v %v %v %s\n",
|
||||
1,
|
||||
int64(1),
|
||||
3.0,
|
||||
"four!",
|
||||
true,
|
||||
time.Unix(0, 0),
|
||||
errExample,
|
||||
time.Second,
|
||||
_jane,
|
||||
"done!",
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("apex/log", func(b *testing.B) {
|
||||
logger := newApexLog().WithFields(fakeApexFields())
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("go-kit/kit/log", func(b *testing.B) {
|
||||
logger := newKitLog(fakeSugarFields()...)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Log(getMessage(0), getMessage(1))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("inconshreveable/log15", func(b *testing.B) {
|
||||
logger := newLog15().New(fakeSugarFields())
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("sirupsen/logrus", func(b *testing.B) {
|
||||
logger := newLogrus().WithFields(fakeLogrusFields())
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("go.pedge.io/lion", func(b *testing.B) {
|
||||
logger := newLion().WithFields(fakeLogrusFields())
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Infof(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkAddingFields(b *testing.B) {
|
||||
b.Logf("Logging with additional context at each log site.")
|
||||
b.Run("Zap", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0), fakeFields()...)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Check", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
if ce := logger.Check(zap.InfoLevel, getMessage(0)); ce != nil {
|
||||
ce.Write(fakeFields()...)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.CheckSampled", func(b *testing.B) {
|
||||
logger := newSampledLogger(zap.DebugLevel)
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
i := 0
|
||||
for pb.Next() {
|
||||
i++
|
||||
if ce := logger.Check(zap.InfoLevel, getMessage(i)); ce != nil {
|
||||
ce.Write(fakeFields()...)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("Zap.Sugar", func(b *testing.B) {
|
||||
logger := newZapLogger(zap.DebugLevel).Sugar()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Infow(getMessage(0), fakeSugarFields()...)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("apex/log", func(b *testing.B) {
|
||||
logger := newApexLog()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.WithFields(fakeApexFields()).Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("go-kit/kit/log", func(b *testing.B) {
|
||||
logger := newKitLog()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Log(fakeSugarFields()...)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("inconshreveable/log15", func(b *testing.B) {
|
||||
logger := newLog15()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.Info(getMessage(0), fakeSugarFields()...)
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("sirupsen/logrus", func(b *testing.B) {
|
||||
logger := newLogrus()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.WithFields(fakeLogrusFields()).Info(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
b.Run("go.pedge.io/lion", func(b *testing.B) {
|
||||
logger := newLion()
|
||||
b.ResetTimer()
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
logger.WithFields(fakeLogrusFields()).Infof(getMessage(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
117
vendor/go.uber.org/zap/benchmarks/zap_test.go
generated
vendored
Normal file
117
vendor/go.uber.org/zap/benchmarks/zap_test.go
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
// Copyright (c) 2016 Uber Technologies, Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
package benchmarks
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
"go.uber.org/zap/zaptest"
|
||||
)
|
||||
|
||||
var (
|
||||
errExample = errors.New("fail")
|
||||
|
||||
_messages = fakeMessages(1000)
|
||||
)
|
||||
|
||||
func fakeMessages(n int) []string {
|
||||
messages := make([]string, n)
|
||||
for i := range messages {
|
||||
messages[i] = fmt.Sprintf("Test logging, but use a somewhat realistic message length. (#%v)", i)
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
func getMessage(iter int) string {
|
||||
return _messages[iter%1000]
|
||||
}
|
||||
|
||||
type user struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
func (u user) MarshalLogObject(enc zapcore.ObjectEncoder) error {
|
||||
enc.AddString("name", u.Name)
|
||||
enc.AddString("email", u.Email)
|
||||
enc.AddInt64("created_at", u.CreatedAt.UnixNano())
|
||||
return nil
|
||||
}
|
||||
|
||||
var _jane = user{
|
||||
Name: "Jane Doe",
|
||||
Email: "jane@test.com",
|
||||
CreatedAt: time.Date(1980, 1, 1, 12, 0, 0, 0, time.UTC),
|
||||
}
|
||||
|
||||
func newZapLogger(lvl zapcore.Level) *zap.Logger {
|
||||
// use the canned production encoder configuration
|
||||
enc := zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig())
|
||||
return zap.New(zapcore.NewCore(
|
||||
enc,
|
||||
&zaptest.Discarder{},
|
||||
lvl,
|
||||
))
|
||||
}
|
||||
|
||||
func newSampledLogger(lvl zapcore.Level) *zap.Logger {
|
||||
return zap.New(zapcore.NewSampler(
|
||||
newZapLogger(zap.DebugLevel).Core(),
|
||||
100*time.Millisecond,
|
||||
10, // first
|
||||
10, // thereafter
|
||||
))
|
||||
}
|
||||
|
||||
func fakeFields() []zapcore.Field {
|
||||
return []zapcore.Field{
|
||||
zap.Int("int", 1),
|
||||
zap.Int64("int64", 2),
|
||||
zap.Float64("float", 3.0),
|
||||
zap.String("string", "four!"),
|
||||
zap.Bool("bool", true),
|
||||
zap.Time("time", time.Unix(0, 0)),
|
||||
zap.Error(errExample),
|
||||
zap.Duration("duration", time.Second),
|
||||
zap.Object("user-defined type", _jane),
|
||||
zap.String("another string", "done!"),
|
||||
}
|
||||
}
|
||||
|
||||
func fakeSugarFields() []interface{} {
|
||||
return []interface{}{
|
||||
"int", 1,
|
||||
"int64", 2,
|
||||
"float", 3.0,
|
||||
"string", "four!",
|
||||
"bool", true,
|
||||
"time", time.Unix(0, 0),
|
||||
"error", errExample,
|
||||
"duration", time.Second,
|
||||
"user-defined type", _jane,
|
||||
"another string", "done!",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user