From 5e995c6903fa1dee081140d5f07c81c3f39758dd Mon Sep 17 00:00:00 2001 From: Glib Smaga Date: Thu, 8 Dec 2016 17:48:23 -0800 Subject: [PATCH] Language cleanup (#120) * Clean up wording and variable naming * More language fixes --- config/README.md | 4 +- config/config.go | 4 +- config/doc.go | 4 +- config/static_provider.go | 2 +- config/value.go | 8 ++-- modules/rpc/README.md | 4 +- modules/rpc/doc.go | 2 +- tracing/tracer_test.go | 4 +- ulog/README.md | 34 ++++++++------- ulog/builder.go | 6 +-- ulog/builder_test.go | 20 ++++----- ulog/doc.go | 40 ++++++++++-------- ulog/log.go | 84 +++++++++++++++++++------------------- ulog/log_benchmark_test.go | 6 +-- ulog/log_test.go | 18 ++++---- ulog/noop_logger.go | 2 +- 16 files changed, 126 insertions(+), 116 deletions(-) diff --git a/config/README.md b/config/README.md index fa31fbfc..832e817b 100644 --- a/config/README.md +++ b/config/README.md @@ -93,8 +93,8 @@ environment-based configuration providers. Dynamic configuration providers frequently need some bootstrap configuration to be useful, so UberFx treats them specially. Dynamic configuration providers -conform to the `Provider` interface, but they're instantianted -**after** the Static `Provider`s on order to read bootstarp values. +conform to the `Provider` interface, but they're instantiated +**after** the Static `Provider`s on order to read bootstrap values. For example, if you were to implement a ZooKeeper-backed `Provider`, you'd likely need to specify (via YAML or environment diff --git a/config/config.go b/config/config.go index 5f5d283d..5cc16659 100644 --- a/config/config.go +++ b/config/config.go @@ -38,7 +38,7 @@ const ( environment = "_ENVIRONMENT" datacenter = "_DATACENTER" - configdir = "_CONFIG_DIR" + configDir = "_CONFIG_DIR" config = "config" ) @@ -108,7 +108,7 @@ func IsDevelopment() bool { // Path returns path to the yaml configurations func Path() string { - configPath := os.Getenv(EnvironmentPrefix() + configdir) + configPath := os.Getenv(EnvironmentPrefix() + configDir) if configPath == "" { configPath = config } diff --git a/config/doc.go b/config/doc.go index 6b94c883..91286412 100644 --- a/config/doc.go +++ b/config/doc.go @@ -114,8 +114,8 @@ // Dynamic configuration providers frequently need some bootstrap configuration to // be useful, so UberFx treats them specially. Dynamic configuration providers // conform to the -// Provider interface, but they're instantianted -// **after** the Static Providers on order to read bootstarp values. +// Provider interface, but they're instantiated +// **after** the Static Providers on order to read bootstrap values. // // For example, if you were to implement a ZooKeeper-backed // Provider, you'd likely need to specify (via YAML or environment diff --git a/config/static_provider.go b/config/static_provider.go index 1359018c..2433b474 100644 --- a/config/static_provider.go +++ b/config/static_provider.go @@ -72,7 +72,7 @@ func (s *staticProvider) Scope(prefix string) Provider { } func (s *staticProvider) RegisterChangeCallback(key string, callback ConfigurationChangeCallback) error { - // Staic provider don't receive callback events + // Static provider don't receive callback events return nil } diff --git a/config/value.go b/config/value.go index 08325f03..5f90624f 100644 --- a/config/value.go +++ b/config/value.go @@ -168,7 +168,7 @@ func (cv Value) TryAsString() (string, bool) { return "", false } -// TryAsInt attempts to return the confniguration value as an int +// TryAsInt attempts to return the configuration value as an int func (cv Value) TryAsInt() (int, bool) { v := cv.Value() if val, err := convertValue(v, reflect.TypeOf(0)); v != nil && err == nil { @@ -320,8 +320,8 @@ func derefType(t reflect.Type) reflect.Type { return t } -// this is a quick-and-dirty converstion method that only handles -// a couple of cases and complains if it finds one it doen't like. +// this is a quick-and-dirty conversion method that only handles +// a couple of cases and complains if it finds one it doesn't like. // needs a bunch more cases. func convertValue(value interface{}, targetType reflect.Type) (interface{}, error) { if value == nil { @@ -528,7 +528,7 @@ func (cv Value) valueStruct(key string, target interface{}) (interface{}, error) if val != nil { destMap := reflect.ValueOf(reflect.MakeMap(fieldType).Interface()) - // child yamlnode parsed from yaml file is of type map[interface{}]interface{} + // child yamlNode parsed from yaml file is of type map[interface{}]interface{} // type casting here makes sure that we are iterating over a parsed map. v, ok := val.(map[interface{}]interface{}) if ok { diff --git a/modules/rpc/README.md b/modules/rpc/README.md index 792e2dee..742da4e8 100644 --- a/modules/rpc/README.md +++ b/modules/rpc/README.md @@ -11,7 +11,7 @@ This module works in a way that's pretty similar to existing RPC projects: * Implement the service interface handlers as method receivers on a struct * Implement a top-level function, conforming to the - `rpc.CreateThriftServiceFunc` signature (`uberfx/modules/rpc/thrift.go` that + `rpc.CreateThriftServiceFunc` signature (`fx/modules/rpc/thrift.go` that returns a `[]transport.Registrant` YARPC implementation from the handler: ```go @@ -39,4 +39,4 @@ func main() { } ``` -This will spin up the service. \ No newline at end of file +This will spin up the service. diff --git a/modules/rpc/doc.go b/modules/rpc/doc.go index a5184257..61ea2521 100644 --- a/modules/rpc/doc.go +++ b/modules/rpc/doc.go @@ -33,7 +33,7 @@ // • Implement the service interface handlers as method receivers on a struct // // • Implement a top-level function, conforming to the -// rpc.CreateThriftServiceFunc signature (uberfx/modules/rpc/thrift.go that +// rpc.CreateThriftServiceFunc signature (fx/modules/rpc/thrift.go that // returns a // []transport.Registrant YARPC implementation from the handler: // diff --git a/tracing/tracer_test.go b/tracing/tracer_test.go index c27f3784..b09d8d9a 100644 --- a/tracing/tracer_test.go +++ b/tracing/tracer_test.go @@ -85,8 +85,8 @@ func TestLoadAppConfig_NilJaegerConfig(t *testing.T) { } func TestJaegerLogger(t *testing.T) { - testutils.WithInMemoryLogger(t, nil, func(zaplogger zap.Logger, buf *testutils.TestBuffer) { - loggerWithZap := ulog.Builder().SetLogger(zaplogger).Build() + testutils.WithInMemoryLogger(t, nil, func(zapLogger zap.Logger, buf *testutils.TestBuffer) { + loggerWithZap := ulog.Builder().SetLogger(zapLogger).Build() jLogger := jaegerLogger{log: loggerWithZap} jLogger.Infof("info message", "c", "d") jLogger.Error("error message") diff --git a/ulog/README.md b/ulog/README.md index 03060254..472e7efd 100644 --- a/ulog/README.md +++ b/ulog/README.md @@ -1,14 +1,17 @@ # Logging package -`package ulog` provides an API wrapper around the logging library [zap](https://github.com/uber-go/zap). -`package ulog` uses the builder pattern to instantiate the logger. With `LogBuilder` you can perform pre-initialization setup -by injecting configuration, custom logger, and log level prior to building the usable `ulog.Log` object. `ulog.Log` -interface provides a few benefits: +`package ulog` provides an API wrapper around the logging library +[zap](https://github.com/uber-go/zap). `package ulog` uses the builder pattern +to instantiate the logger. With `LogBuilder` you can perform pre-initialization +setup by injecting configuration, custom logger, and log level prior to building +the usable `ulog.Log` object. + +`ulog.Log` interface provides a few benefits: + - Decouple services from the logger used underneath the framework - Easy to use API for logging - Easily swappable backend logger without changing the service - ## Sample usage ```go @@ -25,13 +28,13 @@ func main() { log := lobBuilder.Build() // Use logger in your service - log.Info("Message describing loggging reason", "key", "value") + log.Info("Message describing logging reason", "key", "value") } ``` ## Context -It is very common that in addition to loggin a string message, it is desirable +It is very common that in addition to logging a string message, it is desirable to provide additional information: customer uuid, tracing id, etc. For that very reason, the logging methods (`Info`,`Warn`, `Debug`, etc) take @@ -94,12 +97,13 @@ logging: ### Benchmarks -Current performance benchmark data with `ulog interface`, `ulog baselogger struct`, and `zap.Logger` - -|-------------------------------------------|----------|-----------|-----------|------------| -|BenchmarkUlogWithoutFields-8 |5000000 |226 ns/op |48 B/op |1 allocs/op | -|BenchmarkUlogWithFieldsLogIFace-8 |2000000 |1026 ns/op |1052 B/op |19 allocs/op| -|BenchmarkUlogWithFieldsBaseLoggerStruct-8 |2000000 |912 ns/op |795 B/op |18 allocs/op| -|BenchmarkUlogWithFieldsZapLogger-8 |3000000 |558 ns/op |513 B/op |1 allocs/op | -|BenchmarkUlogLiteWithFields-8 |3000000 |466 ns/op |297 B/op |7 allocs/op | +Current performance benchmark data with `ulog interface`, +`ulog baseLogger struct`, and `zap.Logger` +``` +BenchmarkUlogWithoutFields-8 5000000 226 ns/op 48 B/op 1 allocs/op +BenchmarkUlogWithFieldsLogIFace-8 2000000 1026 ns/op 1052 B/op 19 allocs/op +BenchmarkUlogWithFieldsBaseLoggerStruct-8 2000000 912 ns/op 795 B/op 18 allocs/op +BenchmarkUlogWithFieldsZapLogger-8 3000000 558 ns/op 513 B/op 1 allocs/op +BenchmarkUlogLiteWithFields-8 3000000 466 ns/op 297 B/op 7 allocs/op +``` diff --git a/ulog/builder.go b/ulog/builder.go index 862427ee..cf9472fb 100644 --- a/ulog/builder.go +++ b/ulog/builder.go @@ -30,7 +30,7 @@ import ( "github.com/uber-go/zap" ) -// Configuration for logging with uberfx +// Configuration for logging with UberFx type Configuration struct { Level string File *FileConfiguration @@ -82,7 +82,7 @@ func (lb *LogBuilder) Build() Log { // When setLogger is called, we will always use logger that has been set if lb.log != nil { - return &baselogger{ + return &baseLogger{ log: lb.log, } } @@ -93,7 +93,7 @@ func (lb *LogBuilder) Build() Log { log = lb.Configure() } - return &baselogger{ + return &baseLogger{ log: log, } } diff --git a/ulog/builder_test.go b/ulog/builder_test.go index 0d332c2e..e00e8fe8 100644 --- a/ulog/builder_test.go +++ b/ulog/builder_test.go @@ -44,8 +44,8 @@ func TestConfiguredLogger(t *testing.T) { Verbose: false, } log := builder.WithConfiguration(cfg).Build() - zaplogger := log.RawLogger() - assert.True(t, zaplogger.Check(zap.DebugLevel, "").OK()) + zapLogger := log.RawLogger() + assert.True(t, zapLogger.Check(zap.DebugLevel, "").OK()) }) } @@ -64,8 +64,8 @@ func TestConfiguredLoggerWithTextFormatter(t *testing.T) { }, } log := Builder().WithConfiguration(cfg).Build() - zaplogger := log.RawLogger() - assert.True(t, zaplogger.Check(zap.DebugLevel, "").OK()) + zapLogger := log.RawLogger() + assert.True(t, zapLogger.Check(zap.DebugLevel, "").OK()) }) } @@ -76,8 +76,8 @@ func TestConfiguredLoggerWithTextFormatter_NonDev(t *testing.T) { Level: "debug", TextFormatter: &txt, }).Build() - zaplogger := log.RawLogger() - assert.True(t, zaplogger.Check(zap.DebugLevel, "").OK()) + zapLogger := log.RawLogger() + assert.True(t, zapLogger.Check(zap.DebugLevel, "").OK()) }) } @@ -95,8 +95,8 @@ func TestConfiguredLoggerWithStdout(t *testing.T) { }, } log := Builder().WithConfiguration(cfg).Build() - zaplogger := log.RawLogger() - assert.True(t, zaplogger.Check(zap.DebugLevel, "").OK()) + zapLogger := log.RawLogger() + assert.True(t, zapLogger.Check(zap.DebugLevel, "").OK()) }) } @@ -132,7 +132,7 @@ func TestDefaultPackageLogger(t *testing.T) { withLogger(t, func(builder *LogBuilder, tmpDir string, logFile string) { defer testutils.EnvOverride(t, config.EnvironmentKey(), "development")() log := New() - zaplogger := log.RawLogger() - assert.True(t, zaplogger.Check(zap.DebugLevel, "").OK()) + zapLogger := log.RawLogger() + assert.True(t, zapLogger.Check(zap.DebugLevel, "").OK()) }) } diff --git a/ulog/doc.go b/ulog/doc.go index 76576bce..6d5cb1b0 100644 --- a/ulog/doc.go +++ b/ulog/doc.go @@ -20,14 +20,21 @@ // Package ulog is the Logging package. // -// package ulog provides an API wrapper around the logging library zap (https://github.com/uber-go/zap). -// package ulog uses the builder pattern to instantiate the logger. With LogBuilder you can perform pre-initialization setup -// by injecting configuration, custom logger, and log level prior to building the usable -// ulog.Log object. ulog.Loginterface provides a few benefits: -// - Decouple services from the logger used underneath the framework -// - Easy to use API for logging -// - Easily swappable backend logger without changing the service +// package ulog provides an API wrapper around the logging library +// zap (https://github.com/uber-go/zap). package ulog uses the builder pattern +// to instantiate the logger. With +// LogBuilder you can perform pre-initialization +// setup by injecting configuration, custom logger, and log level prior to building +// the usable +// ulog.Log object. // +// ulog.Log interface provides a few benefits: +// +// • Decouple services from the logger used underneath the framework +// +// • Easy to use API for logging +// +// • Easily swappable backend logger without changing the service // // Sample usage // @@ -44,12 +51,12 @@ // log := lobBuilder.Build() // // // Use logger in your service -// log.Info("Message describing loggging reason", "key", "value") +// log.Info("Message describing logging reason", "key", "value") // } // // Context // -// It is very common that in addition to loggin a string message, it is desirable +// It is very common that in addition to logging a string message, it is desirable // to provide additional information: customer uuid, tracing id, etc. // // @@ -107,15 +114,14 @@ // // Benchmarks // -// Current performance benchmark data with ulog interface, ulog baselogger struct, and zap.Logger -// -// |-------------------------------------------|----------|-----------|-----------|------------| -// |BenchmarkUlogWithoutFields-8 |5000000 |226 ns/op |48 B/op |1 allocs/op | -// |BenchmarkUlogWithFieldsLogIFace-8 |2000000 |1026 ns/op |1052 B/op |19 allocs/op| -// |BenchmarkUlogWithFieldsBaseLoggerStruct-8 |2000000 |912 ns/op |795 B/op |18 allocs/op| -// |BenchmarkUlogWithFieldsZapLogger-8 |3000000 |558 ns/op |513 B/op |1 allocs/op | -// |BenchmarkUlogLiteWithFields-8 |3000000 |466 ns/op |297 B/op |7 allocs/op | +// Current performance benchmark data with ulog interface, +// ulog baseLogger struct, and zap.Logger // +// BenchmarkUlogWithoutFields-8 5000000 226 ns/op 48 B/op 1 allocs/op +// BenchmarkUlogWithFieldsLogIFace-8 2000000 1026 ns/op 1052 B/op 19 allocs/op +// BenchmarkUlogWithFieldsBaseLoggerStruct-8 2000000 912 ns/op 795 B/op 18 allocs/op +// BenchmarkUlogWithFieldsZapLogger-8 3000000 558 ns/op 513 B/op 1 allocs/op +// BenchmarkUlogLiteWithFields-8 3000000 466 ns/op 297 B/op 7 allocs/op // // package ulog diff --git a/ulog/log.go b/ulog/log.go index 00e808d1..f612b31a 100644 --- a/ulog/log.go +++ b/ulog/log.go @@ -27,23 +27,23 @@ import ( "github.com/uber-go/zap" ) -type baselogger struct { +type baseLogger struct { log zap.Logger } -// Log is the Uberfx wrapper for underlying logging service +// Log is the UberFx wrapper for underlying logging service type Log interface { // With creates a child logger with the provided parameters as key value pairs // ulog uses uber-go/zap library as its child logger which needs pairs of key value objects // in the form of zap.Fields(key, value). ulog performs field conversion from - // supplied keyvals pair to zap.Fields format. + // supplied keyVals pair to zap.Fields format. // // **IMPORTANT**: With should never be used if the resulting logger // object is not being retained. If you need to add some context to // a logging message, use the Error, Info, etc. functions // and pass in additional interface{} pairs for logging. - With(keyvals ...interface{}) Log + With(keyVals ...interface{}) Log // Check returns a zap.CheckedMessage if logging a message at the specified level is enabled. Check(level zap.Level, message string) *zap.CheckedMessage @@ -52,34 +52,34 @@ type Log interface { RawLogger() zap.Logger // Log at the provided zap.Level with message, and a sequence of parameters as key value pairs - Log(level zap.Level, message string, keyvals ...interface{}) + Log(level zap.Level, message string, keyVals ...interface{}) // Debug logs at Debug level with message, and parameters as key value pairs - Debug(message string, keyvals ...interface{}) + Debug(message string, keyVals ...interface{}) // Info logs at Info level with message, and parameters as key value pairs - Info(message string, keyvals ...interface{}) + Info(message string, keyVals ...interface{}) // Warn ogs at Warn level with message, and parameters as key value pairs - Warn(message string, keyvals ...interface{}) + Warn(message string, keyVals ...interface{}) // Error logs at Error level with message, and parameters as key value pairs - Error(message string, keyvals ...interface{}) + Error(message string, keyVals ...interface{}) // Panic logs at Panic level with message, and parameters as key value pairs - Panic(message string, keyvals ...interface{}) + Panic(message string, keyVals ...interface{}) // Fatal logs at Fatal level with message, and parameters as key value pairs - Fatal(message string, keyvals ...interface{}) + Fatal(message string, keyVals ...interface{}) // DPanic logs at Debug level (Fatal for development) with message, and parameters as key value pairs - DPanic(message string, keyvals ...interface{}) + DPanic(message string, keyVals ...interface{}) } var _std = defaultLogger() func defaultLogger() Log { - return &baselogger{ + return &baseLogger{ log: zap.New(zap.NewJSONEncoder()), } } @@ -87,69 +87,69 @@ func defaultLogger() Log { // Logger returns the package-level logger configured for the service // TODO:(at) Remove Logger() call, _std and defaultLogger() access in ulog func Logger() Log { - return &baselogger{ - log: _std.(*baselogger).log, + return &baseLogger{ + log: _std.(*baseLogger).log, } } // RawLogger returns underneath zap implementation for use -func (l *baselogger) RawLogger() zap.Logger { +func (l *baseLogger) RawLogger() zap.Logger { return l.log } -func (l *baselogger) With(keyvals ...interface{}) Log { - return &baselogger{ - log: l.log.With(l.fieldsConversion(keyvals...)...), +func (l *baseLogger) With(keyVals ...interface{}) Log { + return &baseLogger{ + log: l.log.With(l.fieldsConversion(keyVals...)...), } } -func (l *baselogger) Check(level zap.Level, expr string) *zap.CheckedMessage { +func (l *baseLogger) Check(level zap.Level, expr string) *zap.CheckedMessage { return l.log.Check(level, expr) } -func (l *baselogger) Debug(message string, keyvals ...interface{}) { - l.Log(zap.DebugLevel, message, keyvals...) +func (l *baseLogger) Debug(message string, keyVals ...interface{}) { + l.Log(zap.DebugLevel, message, keyVals...) } -func (l *baselogger) Info(message string, keyvals ...interface{}) { - l.Log(zap.InfoLevel, message, keyvals...) +func (l *baseLogger) Info(message string, keyVals ...interface{}) { + l.Log(zap.InfoLevel, message, keyVals...) } -func (l *baselogger) Warn(message string, keyvals ...interface{}) { - l.Log(zap.WarnLevel, message, keyvals...) +func (l *baseLogger) Warn(message string, keyVals ...interface{}) { + l.Log(zap.WarnLevel, message, keyVals...) } -func (l *baselogger) Error(message string, keyvals ...interface{}) { - l.Log(zap.ErrorLevel, message, keyvals...) +func (l *baseLogger) Error(message string, keyVals ...interface{}) { + l.Log(zap.ErrorLevel, message, keyVals...) } -func (l *baselogger) Panic(message string, keyvals ...interface{}) { - l.Log(zap.PanicLevel, message, keyvals...) +func (l *baseLogger) Panic(message string, keyVals ...interface{}) { + l.Log(zap.PanicLevel, message, keyVals...) } -func (l *baselogger) Fatal(message string, keyvals ...interface{}) { - l.Log(zap.FatalLevel, message, keyvals...) +func (l *baseLogger) Fatal(message string, keyVals ...interface{}) { + l.Log(zap.FatalLevel, message, keyVals...) } -func (l *baselogger) DPanic(message string, keyvals ...interface{}) { - l.log.DPanic(message, l.fieldsConversion(keyvals...)...) +func (l *baseLogger) DPanic(message string, keyVals ...interface{}) { + l.log.DPanic(message, l.fieldsConversion(keyVals...)...) } -func (l *baselogger) Log(lvl zap.Level, message string, keyvals ...interface{}) { +func (l *baseLogger) Log(lvl zap.Level, message string, keyVals ...interface{}) { if cm := l.Check(lvl, message); cm.OK() { - cm.Write(l.fieldsConversion(keyvals...)...) + cm.Write(l.fieldsConversion(keyVals...)...) } } -func (l *baselogger) fieldsConversion(keyvals ...interface{}) []zap.Field { - fields := make([]zap.Field, 0, len(keyvals)/2) - if len(keyvals)%2 != 0 { +func (l *baseLogger) fieldsConversion(keyVals ...interface{}) []zap.Field { + fields := make([]zap.Field, 0, len(keyVals)/2) + if len(keyVals)%2 != 0 { fields = append(fields, zap.Error(fmt.Errorf("invalid number of arguments"))) return fields } - for idx := 0; idx < len(keyvals); idx += 2 { - if key, ok := keyvals[idx].(string); ok { - switch value := keyvals[idx+1].(type) { + for idx := 0; idx < len(keyVals); idx += 2 { + if key, ok := keyVals[idx].(string); ok { + switch value := keyVals[idx+1].(type) { case bool: fields = append(fields, zap.Bool(key, value)) case float64: diff --git a/ulog/log_benchmark_test.go b/ulog/log_benchmark_test.go index f2e7f020..bf824789 100644 --- a/ulog/log_benchmark_test.go +++ b/ulog/log_benchmark_test.go @@ -71,7 +71,7 @@ func BenchmarkUlogWithFieldsLogIFace(b *testing.B) { func BenchmarkUlogWithFieldsBaseLoggerStruct(b *testing.B) { withDiscardedLogger(b, func(log Log) { - base := log.(*baselogger) + base := log.(*baseLogger) b.ResetTimer() b.RunParallel(func(pb *testing.PB) { for pb.Next() { @@ -91,11 +91,11 @@ func BenchmarkUlogWithFieldsBaseLoggerStruct(b *testing.B) { func BenchmarkUlogWithFieldsZapLogger(b *testing.B) { withDiscardedLogger(b, func(log Log) { - zaplogger := log.RawLogger() + zapLogger := log.RawLogger() b.ResetTimer() b.RunParallel(func(pb *testing.PB) { for pb.Next() { - zaplogger.Info("Ulog message", + zapLogger.Info("Ulog message", zap.Int("int", 123), zap.Int64("int64", 123), zap.Float64("float", 123.123), diff --git a/ulog/log_test.go b/ulog/log_test.go index 825a7061..e394608e 100644 --- a/ulog/log_test.go +++ b/ulog/log_test.go @@ -33,8 +33,8 @@ import ( ) func TestSimpleLogger(t *testing.T) { - testutils.WithInMemoryLogger(t, nil, func(zaplogger zap.Logger, buf *testutils.TestBuffer) { - log := Builder().SetLogger(zaplogger).Build() + testutils.WithInMemoryLogger(t, nil, func(zapLogger zap.Logger, buf *testutils.TestBuffer) { + log := Builder().SetLogger(zapLogger).Build() log.Debug("debug message", "a", "b") log.Info("info message", "c", "d") @@ -50,8 +50,8 @@ func TestSimpleLogger(t *testing.T) { } func TestLoggerWithInitFields(t *testing.T) { - testutils.WithInMemoryLogger(t, nil, func(zaplogger zap.Logger, buf *testutils.TestBuffer) { - log := Builder().SetLogger(zaplogger).Build().With("method", "test_method") + testutils.WithInMemoryLogger(t, nil, func(zapLogger zap.Logger, buf *testutils.TestBuffer) { + log := Builder().SetLogger(zapLogger).Build().With("method", "test_method") log.Debug("debug message", "a", "b") log.Info("info message", "c", "d") log.Warn("warn message", "e", "f") @@ -66,8 +66,8 @@ func TestLoggerWithInitFields(t *testing.T) { } func TestLoggerWithInvalidFields(t *testing.T) { - testutils.WithInMemoryLogger(t, nil, func(zaplogger zap.Logger, buf *testutils.TestBuffer) { - log := Builder().SetLogger(zaplogger).Build() + testutils.WithInMemoryLogger(t, nil, func(zapLogger zap.Logger, buf *testutils.TestBuffer) { + log := Builder().SetLogger(zapLogger).Build() log.Info("info message", "c") log.Info("info message", "c", "d", "e") log.DPanic("debug message") @@ -80,8 +80,8 @@ func TestLoggerWithInvalidFields(t *testing.T) { } func TestFatalsAndPanics(t *testing.T) { - testutils.WithInMemoryLogger(t, nil, func(zaplogger zap.Logger, buf *testutils.TestBuffer) { - log := Builder().SetLogger(zaplogger).Build() + testutils.WithInMemoryLogger(t, nil, func(zapLogger zap.Logger, buf *testutils.TestBuffer) { + log := Builder().SetLogger(zapLogger).Build() assert.Panics(t, func() { log.Panic("panic level") }, "Expected to panic") assert.Equal(t, `{"level":"panic","msg":"panic level"}`, buf.Stripped(), "Unexpected output") }) @@ -99,7 +99,7 @@ func (m *marshalObject) MarshalLog(kv zap.KeyValue) error { func TestFieldConversion(t *testing.T) { log := New() - base := log.(*baselogger) + base := log.(*baseLogger) assert.Equal(t, zap.Bool("a", true), base.fieldsConversion("a", true)[0]) assert.Equal(t, zap.Float64("a", 5.5), base.fieldsConversion("a", 5.5)[0]) diff --git a/ulog/noop_logger.go b/ulog/noop_logger.go index ad2f047c..40f7333a 100644 --- a/ulog/noop_logger.go +++ b/ulog/noop_logger.go @@ -23,7 +23,7 @@ package ulog import "github.com/uber-go/zap" func noopLogger() Log { - return &baselogger{ + return &baseLogger{ log: zap.New(zap.NullEncoder()), } }