Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Commit

Permalink
Delint
Browse files Browse the repository at this point in the history
  • Loading branch information
bhs committed Sep 26, 2016
1 parent 6d12712 commit 802a549
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
19 changes: 18 additions & 1 deletion log/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Field struct {
interfaceVal interface{}
}

// String adds a string-valued key:value pair to a Span.LogFields() record
func String(key, val string) Field {
return Field{
key: key,
Expand All @@ -41,6 +42,7 @@ func String(key, val string) Field {
}
}

// Bool adds a bool-valued key:value pair to a Span.LogFields() record
func Bool(key string, val bool) Field {
var numericVal int64
if val {
Expand All @@ -53,6 +55,7 @@ func Bool(key string, val bool) Field {
}
}

// Int adds an int-valued key:value pair to a Span.LogFields() record
func Int(key string, val int) Field {
return Field{
key: key,
Expand All @@ -61,6 +64,7 @@ func Int(key string, val int) Field {
}
}

// Int32 adds an int32-valued key:value pair to a Span.LogFields() record
func Int32(key string, val int32) Field {
return Field{
key: key,
Expand All @@ -69,6 +73,7 @@ func Int32(key string, val int32) Field {
}
}

// Int64 adds an int64-valued key:value pair to a Span.LogFields() record
func Int64(key string, val int64) Field {
return Field{
key: key,
Expand All @@ -77,6 +82,7 @@ func Int64(key string, val int64) Field {
}
}

// Uint32 adds a uint32-valued key:value pair to a Span.LogFields() record
func Uint32(key string, val uint32) Field {
return Field{
key: key,
Expand All @@ -85,6 +91,7 @@ func Uint32(key string, val uint32) Field {
}
}

// Uint64 adds a uint64-valued key:value pair to a Span.LogFields() record
func Uint64(key string, val uint64) Field {
return Field{
key: key,
Expand All @@ -93,6 +100,7 @@ func Uint64(key string, val uint64) Field {
}
}

// Float32 adds a float32-valued key:value pair to a Span.LogFields() record
func Float32(key string, val float32) Field {
return Field{
key: key,
Expand All @@ -101,6 +109,7 @@ func Float32(key string, val float32) Field {
}
}

// Float64 adds a float64-valued key:value pair to a Span.LogFields() record
func Float64(key string, val float64) Field {
return Field{
key: key,
Expand All @@ -109,6 +118,7 @@ func Float64(key string, val float64) Field {
}
}

// Error adds an error with the key "error" to a Span.LogFields() record
func Error(err error) Field {
return Field{
key: "error",
Expand All @@ -117,6 +127,7 @@ func Error(err error) Field {
}
}

// Object adds an object-valued key:value pair to a Span.LogFields() record
func Object(key string, obj interface{}) Field {
return Field{
key: key,
Expand All @@ -125,9 +136,15 @@ func Object(key string, obj interface{}) Field {
}
}

// LazyLogger allows for user-defined, late-bound logging of arbitrary data
type LazyLogger func(fv FieldVisitor)

func Lazy(key string, ll LazyLogger) Field {
// Lazy adds a LazyLogger to a Span.LogFields() record; the tracing
// implementation will call the LazyLogger function at an indefinite time in
// the future (after Lazy() returns).
//
// Note that `ignoredKey` is ignored (as the LazyLogger can control the key).
func Lazy(ignoredKey string, ll LazyLogger) Field {
return Field{
key: key,
fieldType: lazyLoggerType,
Expand Down
21 changes: 21 additions & 0 deletions mocktracer/mocklogrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,56 +25,77 @@ type MockKeyValue struct {
ValueString string
}

// AddString belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddString(key, value string) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddBool belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddBool(key string, value bool) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddInt belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddInt(key string, value int) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddInt32 belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddInt32(key string, value int32) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddInt64 belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddInt64(key string, value int64) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddUint32 belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddUint32(key string, value uint32) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddUint64 belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddUint64(key string, value uint64) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddFloat32 belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddFloat32(key string, value float32) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddFloat64 belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddFloat64(key string, value float64) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddObject belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddObject(key string, value interface{}) {
m.Key = key
m.ValueKind = reflect.TypeOf(value).Kind()
m.ValueString = fmt.Sprint(value)
}

// AddLazyLogger belongs to the log.FieldVisitor interface
func (m *MockKeyValue) AddLazyLogger(key string, value log.LazyLogger) {
var meta MockKeyValue
value(&meta)
Expand Down

0 comments on commit 802a549

Please sign in to comment.