Skip to content

Commit

Permalink
Language cleanup (uber-go#120)
Browse files Browse the repository at this point in the history
* Clean up wording and variable naming

* More language fixes
  • Loading branch information
glibsm committed Dec 9, 2016
1 parent 6c8f8d0 commit 5e995c6
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 116 deletions.
4 changes: 2 additions & 2 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (

environment = "_ENVIRONMENT"
datacenter = "_DATACENTER"
configdir = "_CONFIG_DIR"
configDir = "_CONFIG_DIR"
config = "config"
)

Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions config/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/static_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions config/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions modules/rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,4 +39,4 @@ func main() {
}
```

This will spin up the service.
This will spin up the service.
2 changes: 1 addition & 1 deletion modules/rpc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand Down
4 changes: 2 additions & 2 deletions tracing/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
34 changes: 19 additions & 15 deletions ulog/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
```
6 changes: 3 additions & 3 deletions ulog/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}
Expand All @@ -93,7 +93,7 @@ func (lb *LogBuilder) Build() Log {
log = lb.Configure()
}

return &baselogger{
return &baseLogger{
log: log,
}
}
Expand Down
20 changes: 10 additions & 10 deletions ulog/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
}

Expand All @@ -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())
})
}

Expand All @@ -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())
})
}

Expand All @@ -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())
})
}

Expand Down Expand Up @@ -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())
})
}
40 changes: 23 additions & 17 deletions ulog/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand All @@ -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.
//
//
Expand Down Expand Up @@ -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
Loading

0 comments on commit 5e995c6

Please sign in to comment.