Skip to content

Commit

Permalink
Refactor zap around Faclity (uber-go#201)
Browse files Browse the repository at this point in the history
Pivot the zap API significantly to make `Facility` the central extension point. This greatly reduces the surface area for extension authors to implement, and it alters some APIs to make composition more straightforward.
  • Loading branch information
jcorbin authored and Akshay Shah committed Feb 15, 2017
1 parent 61159f0 commit e5bfe32
Show file tree
Hide file tree
Showing 47 changed files with 1,095 additions and 1,511 deletions.
12 changes: 6 additions & 6 deletions benchmarks/logrus_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ func BenchmarkLogrusAddingFields(b *testing.B) {
}

func BenchmarkZapBarkifyAddingFields(b *testing.B) {
logger := zbark.Barkify(zap.New(
logger := zbark.Barkify(zap.New(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
zap.DiscardOutput,
))
)))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand Down Expand Up @@ -110,11 +110,11 @@ func BenchmarkLogrusWithAccumulatedContext(b *testing.B) {
}

func BenchmarkZapBarkifyWithAccumulatedContext(b *testing.B) {
baseLogger := zbark.Barkify(zap.New(
baseLogger := zbark.Barkify(zap.New(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
zap.DiscardOutput,
))
)))
logger := baseLogger.WithFields(bark.Fields{
"int": 1,
"int64": int64(1),
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/stdlib_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func BenchmarkStandardLibraryWithoutFields(b *testing.B) {

func BenchmarkZapStandardizeWithoutFields(b *testing.B) {
logger, err := zwrap.Standardize(
zap.New(
zap.New(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
zap.DiscardOutput,
),
)),
zap.InfoLevel,
)
if err != nil {
Expand Down
80 changes: 42 additions & 38 deletions benchmarks/zap_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func fakeMessages(n int) []string {
}

func BenchmarkZapDisabledLevelsWithoutFields(b *testing.B) {
logger := zap.New(zap.NewJSONEncoder(), zap.ErrorLevel, zap.DiscardOutput)
logger := zap.New(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.ErrorLevel,
))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand All @@ -87,9 +91,11 @@ func BenchmarkZapDisabledLevelsWithoutFields(b *testing.B) {
func BenchmarkZapDisabledLevelsAccumulatedContext(b *testing.B) {
context := fakeFields()
logger := zap.New(
zap.NewJSONEncoder(),
zap.ErrorLevel,
zap.DiscardOutput,
zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.ErrorLevel,
),
zap.Fields(context...),
)
b.ResetTimer()
Expand All @@ -101,11 +107,11 @@ func BenchmarkZapDisabledLevelsAccumulatedContext(b *testing.B) {
}

func BenchmarkZapDisabledLevelsAddingFields(b *testing.B) {
logger := zap.New(
logger := zap.New(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.ErrorLevel,
zap.DiscardOutput,
)
))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand All @@ -115,27 +121,27 @@ func BenchmarkZapDisabledLevelsAddingFields(b *testing.B) {
}

func BenchmarkZapDisabledLevelsCheckAddingFields(b *testing.B) {
logger := zap.New(
logger := zap.New(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.ErrorLevel,
zap.DiscardOutput,
)
))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if m := logger.Check(zap.InfoLevel, "Should be discarded."); m.OK() {
if m := logger.Check(zap.InfoLevel, "Should be discarded."); m != nil {
m.Write(fakeFields()...)
}
}
})
}

func BenchmarkZapAddingFields(b *testing.B) {
logger := zap.New(
logger := zap.New(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
zap.DiscardOutput,
)
))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand All @@ -147,9 +153,11 @@ func BenchmarkZapAddingFields(b *testing.B) {
func BenchmarkZapWithAccumulatedContext(b *testing.B) {
context := fakeFields()
logger := zap.New(
zap.NewJSONEncoder(),
zap.DebugLevel,
zap.DiscardOutput,
zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
),
zap.Fields(context...),
)
b.ResetTimer()
Expand All @@ -161,11 +169,11 @@ func BenchmarkZapWithAccumulatedContext(b *testing.B) {
}

func BenchmarkZapWithoutFields(b *testing.B) {
logger := zap.New(
logger := zap.New(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
zap.DiscardOutput,
)
))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand All @@ -176,12 +184,11 @@ func BenchmarkZapWithoutFields(b *testing.B) {

func BenchmarkZapSampleWithoutFields(b *testing.B) {
messages := fakeMessages(1000)
base := zap.New(
logger := zap.New(zwrap.Sample(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
zap.DiscardOutput,
)
logger := zwrap.Sample(base, time.Second, 10, 10000)
), time.Second, 10, 10000))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
i := 0
Expand All @@ -194,12 +201,11 @@ func BenchmarkZapSampleWithoutFields(b *testing.B) {

func BenchmarkZapSampleAddingFields(b *testing.B) {
messages := fakeMessages(1000)
base := zap.New(
logger := zap.New(zwrap.Sample(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
zap.DiscardOutput,
)
logger := zwrap.Sample(base, time.Second, 10, 10000)
), time.Second, 10, 10000))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
i := 0
Expand All @@ -212,18 +218,17 @@ func BenchmarkZapSampleAddingFields(b *testing.B) {

func BenchmarkZapSampleCheckWithoutFields(b *testing.B) {
messages := fakeMessages(1000)
base := zap.New(
logger := zap.New(zwrap.Sample(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
zap.DiscardOutput,
)
logger := zwrap.Sample(base, time.Second, 10, 10000)
), time.Second, 10, 10000))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
i++
if cm := logger.Check(zap.InfoLevel, messages[i%1000]); cm.OK() {
if cm := logger.Check(zap.InfoLevel, messages[i%1000]); cm != nil {
cm.Write()
}
}
Expand All @@ -232,18 +237,17 @@ func BenchmarkZapSampleCheckWithoutFields(b *testing.B) {

func BenchmarkZapSampleCheckAddingFields(b *testing.B) {
messages := fakeMessages(1000)
base := zap.New(
logger := zap.New(zwrap.Sample(zap.WriterFacility(
zap.NewJSONEncoder(),
zap.Discard,
zap.DebugLevel,
zap.DiscardOutput,
)
logger := zwrap.Sample(base, time.Second, 10, 10000)
), time.Second, 10, 10000))
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
i := 0
for pb.Next() {
i++
if m := logger.Check(zap.InfoLevel, messages[i%1000]); m.OK() {
if m := logger.Check(zap.InfoLevel, messages[i%1000]); m != nil {
m.Write(fakeFields()...)
}
}
Expand Down
145 changes: 0 additions & 145 deletions checked_message.go

This file was deleted.

Loading

0 comments on commit e5bfe32

Please sign in to comment.