Skip to content

Commit

Permalink
Merge pull request #45 from muir/thirtysix
Browse files Browse the repository at this point in the history
Document, fix and test enums
  • Loading branch information
muir authored Sep 3, 2022
2 parents 724a22a + 5740812 commit 9dab975
Show file tree
Hide file tree
Showing 33 changed files with 687 additions and 412 deletions.
25 changes: 13 additions & 12 deletions basegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"time"

"github.com/muir/xop-go/trace"
"github.com/muir/xop-go/xopat"
"github.com/muir/xop-go/xopbase"
"github.com/muir/xop-go/xopconst"
"github.com/muir/xop-go/xopnum"
)

type (
Expand Down Expand Up @@ -141,7 +142,7 @@ func (p prefillings) PrefillComplete(m string) xopbase.Prefilled {
return prefilled
}

func (p prefilleds) Line(level xopconst.Level, t time.Time, pc []uintptr) xopbase.Line {
func (p prefilleds) Line(level xopnum.Level, t time.Time, pc []uintptr) xopbase.Line {
lines := make(lines, len(p))
for i, prefilled := range p {
lines[i] = prefilled.Line(level, t, pc)
Expand All @@ -167,13 +168,13 @@ func (l lines) Static(m string) {
}
}

func (l lines) Enum(k *xopconst.EnumAttribute, v xopconst.Enum) {
func (l lines) Enum(k *xopat.EnumAttribute, v xopat.Enum) {
for _, line := range l {
line.Enum(k, v)
}
}

func (p prefillings) Enum(k *xopconst.EnumAttribute, v xopconst.Enum) {
func (p prefillings) Enum(k *xopat.EnumAttribute, v xopat.Enum) {
for _, prefilling := range p {
prefilling.Enum(k, v)
}
Expand Down Expand Up @@ -299,49 +300,49 @@ func (l lines) Uint(k string, v uint64) {
}
}

func (s baseSpans) MetadataAny(k *xopconst.AnyAttribute, v interface{}) {
func (s baseSpans) MetadataAny(k *xopat.AnyAttribute, v interface{}) {
for _, span := range s {
span.MetadataAny(k, v)
}
}

func (s baseSpans) MetadataBool(k *xopconst.BoolAttribute, v bool) {
func (s baseSpans) MetadataBool(k *xopat.BoolAttribute, v bool) {
for _, span := range s {
span.MetadataBool(k, v)
}
}

func (s baseSpans) MetadataEnum(k *xopconst.EnumAttribute, v xopconst.Enum) {
func (s baseSpans) MetadataEnum(k *xopat.EnumAttribute, v xopat.Enum) {
for _, span := range s {
span.MetadataEnum(k, v)
}
}

func (s baseSpans) MetadataFloat64(k *xopconst.Float64Attribute, v float64) {
func (s baseSpans) MetadataFloat64(k *xopat.Float64Attribute, v float64) {
for _, span := range s {
span.MetadataFloat64(k, v)
}
}

func (s baseSpans) MetadataInt64(k *xopconst.Int64Attribute, v int64) {
func (s baseSpans) MetadataInt64(k *xopat.Int64Attribute, v int64) {
for _, span := range s {
span.MetadataInt64(k, v)
}
}

func (s baseSpans) MetadataLink(k *xopconst.LinkAttribute, v trace.Trace) {
func (s baseSpans) MetadataLink(k *xopat.LinkAttribute, v trace.Trace) {
for _, span := range s {
span.MetadataLink(k, v)
}
}

func (s baseSpans) MetadataString(k *xopconst.StringAttribute, v string) {
func (s baseSpans) MetadataString(k *xopat.StringAttribute, v string) {
for _, span := range s {
span.MetadataString(k, v)
}
}

func (s baseSpans) MetadataTime(k *xopconst.TimeAttribute, v time.Time) {
func (s baseSpans) MetadataTime(k *xopat.TimeAttribute, v time.Time) {
for _, span := range s {
span.MetadataTime(k, v)
}
Expand Down
11 changes: 6 additions & 5 deletions basegroup.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (

"github.com/muir/xop-go/trace"
"github.com/muir/xop-go/xopbase"
"github.com/muir/xop-go/xopconst"
"github.com/muir/xop-go/xopat"
"github.com/muir/xop-go/xopnum"
)

type baseLoggers []xopbase.Logger
Expand Down Expand Up @@ -133,7 +134,7 @@ func (p prefillings) PrefillComplete(m string) xopbase.Prefilled {
return prefilled
}

func (p prefilleds) Line(level xopconst.Level, t time.Time, pc []uintptr) xopbase.Line {
func (p prefilleds) Line(level xopnum.Level, t time.Time, pc []uintptr) xopbase.Line {
lines := make(lines, len(p))
for i, prefilled := range p {
lines[i] = prefilled.Line(level, t, pc)
Expand All @@ -159,13 +160,13 @@ func (l lines) Static(m string) {
}
}

func (l lines) Enum(k *xopconst.EnumAttribute, v xopconst.Enum) {
func (l lines) Enum(k *xopat.EnumAttribute, v xopat.Enum) {
for _, line := range l {
line.Enum(k, v)
}
}

func (p prefillings) Enum(k *xopconst.EnumAttribute, v xopconst.Enum) {
func (p prefillings) Enum(k *xopat.EnumAttribute, v xopat.Enum) {
for _, prefilling := range p {
prefilling.Enum(k, v)
}
Expand All @@ -186,7 +187,7 @@ func (l lines) ZZZ(k string, v zzz) {
}

//MACRO BaseAttribute
func (s baseSpans) MetadataZZZ(k *xopconst.ZZZAttribute, v zzz) {
func (s baseSpans) MetadataZZZ(k *xopat.ZZZAttribute, v zzz) {
for _, span := range s {
span.MetadataZZZ(k, v)
}
Expand Down
27 changes: 14 additions & 13 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"time"

"github.com/muir/xop-go/trace"
"github.com/muir/xop-go/xopat"
"github.com/muir/xop-go/xopbase"
"github.com/muir/xop-go/xopconst"
"github.com/muir/xop-go/xopnum"
"github.com/muir/xop-go/xoputil"

"github.com/mohae/deepcopy"
Expand Down Expand Up @@ -444,7 +445,7 @@ type Line struct {
skip bool
}

func (log *Log) logLine(level xopconst.Level) *Line {
func (log *Log) logLine(level xopnum.Level) *Line {
skip := level < log.settings.minimumLogLevel
recycled := log.span.linePool.Get()
var ll *Line
Expand All @@ -458,7 +459,7 @@ func (log *Log) logLine(level xopconst.Level) *Line {
} else {
if ll.pc == nil {
ll.pc = make([]uintptr, log.settings.stackFramesWanted[level],
log.settings.stackFramesWanted[xopconst.AlertLevel])
log.settings.stackFramesWanted[xopnum.AlertLevel])
} else {
ll.pc = ll.pc[:cap(ll.pc)]
}
Expand All @@ -471,7 +472,7 @@ func (log *Log) logLine(level xopconst.Level) *Line {
}
if !skip && log.settings.stackFramesWanted[level] != 0 {
ll.pc = make([]uintptr, log.settings.stackFramesWanted[level],
log.settings.stackFramesWanted[xopconst.AlertLevel])
log.settings.stackFramesWanted[xopnum.AlertLevel])
n := runtime.Callers(3, ll.pc)
ll.pc = ll.pc[:n]
}
Expand Down Expand Up @@ -523,18 +524,18 @@ func (line *Line) Static(msg string) {
line.log.hasActivity(true)
}

func (log *Log) Line(level xopconst.Level) *Line { return log.logLine(level) }
func (log *Log) Debug() *Line { return log.Line(xopconst.DebugLevel) }
func (log *Log) Trace() *Line { return log.Line(xopconst.TraceLevel) }
func (log *Log) Info() *Line { return log.Line(xopconst.InfoLevel) }
func (log *Log) Warn() *Line { return log.Line(xopconst.WarnLevel) }
func (log *Log) Line(level xopnum.Level) *Line { return log.logLine(level) }
func (log *Log) Debug() *Line { return log.Line(xopnum.DebugLevel) }
func (log *Log) Trace() *Line { return log.Line(xopnum.TraceLevel) }
func (log *Log) Info() *Line { return log.Line(xopnum.InfoLevel) }
func (log *Log) Warn() *Line { return log.Line(xopnum.WarnLevel) }
func (log *Log) Error() *Line {
log.notBoring()
return log.Line(xopconst.ErrorLevel)
return log.Line(xopnum.ErrorLevel)
}
func (log *Log) Alert() *Line {
log.notBoring()
return log.Line(xopconst.AlertLevel)
return log.Line(xopnum.AlertLevel)
}

func (line *Line) Msgs(v ...interface{}) { line.Msg(fmt.Sprint(v...)) }
Expand All @@ -557,11 +558,11 @@ func (line *Line) Duration(k string, v time.Duration) *Line { line.line.Duration
func (line *Line) Float64(k string, v float64) *Line { line.line.Float64(k, v); return line }
func (line *Line) Float32(k string, v float32) *Line { return line.Float64(k, float64(v)) }

func (line *Line) EmbeddedEnum(k xopconst.EmbeddedEnum) *Line {
func (line *Line) EmbeddedEnum(k xopat.EmbeddedEnum) *Line {
return line.Enum(k.EnumAttribute(), k)
}

func (line *Line) Enum(k *xopconst.EnumAttribute, v xopconst.Enum) *Line {
func (line *Line) Enum(k *xopat.EnumAttribute, v xopat.Enum) *Line {
line.line.Enum(k, v)
return line
}
Expand Down
36 changes: 18 additions & 18 deletions span.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/muir/xop-go/trace"
"github.com/muir/xop-go/xopconst"
"github.com/muir/xop-go/xopat"

"github.com/mohae/deepcopy"
)
Expand Down Expand Up @@ -36,19 +36,19 @@ func (span *Span) eft() *Span {

// Int64 adds a int64 key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Int64(k *xopconst.Int64Attribute, v int64) *Span {
func (span *Span) Int64(k *xopat.Int64Attribute, v int64) *Span {
span.base.MetadataInt64(k, v)
return span.eft()
}

// EmbeddedEnum adds a kev/value attribute to the Span. The key and the value
// are bundled together: the key is derrived from the type of the Enum.
// Alternatively, use xopconst.KeyedEnumAttribute() to create functions
// Alternatively, use xopat.KeyedEnumAttribute() to create functions
// to add enum key/value pairs where the key and value are specified
// separately. See xopconst.SpanType for an example of creating an
// EmbeddedEnum.
// The return value does not need to be used.
func (span *Span) EmbeddedEnum(kv xopconst.EmbeddedEnum) *Span {
func (span *Span) EmbeddedEnum(kv xopat.EmbeddedEnum) *Span {
return span.Enum(kv.EnumAttribute(), kv)
}

Expand All @@ -61,7 +61,7 @@ func (span *Span) EmbeddedEnum(kv xopconst.EmbeddedEnum) *Span {
// for the type of the value, that type may or may not be checked depending
// on the base logger being used.
// The return value does not need to be used.
func (span *Span) AnyImmutable(k *xopconst.AnyAttribute, v interface{}) *Span {
func (span *Span) AnyImmutable(k *xopat.AnyAttribute, v interface{}) *Span {
span.base.MetadataAny(k, v)
return span.eft()
}
Expand All @@ -73,7 +73,7 @@ func (span *Span) AnyImmutable(k *xopconst.AnyAttribute, v interface{}) *Span {
// for the type of the value, that type may or may not be checked depending
// on the base logger being used.
// The return value does not need to be used.
func (span *Span) Any(k *xopconst.AnyAttribute, v interface{}) *Span {
func (span *Span) Any(k *xopat.AnyAttribute, v interface{}) *Span {
if span.log.span.referencesKept {
v = deepcopy.Copy(v)
}
Expand All @@ -83,78 +83,78 @@ func (span *Span) Any(k *xopconst.AnyAttribute, v interface{}) *Span {

// Bool adds a bool key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Bool(k *xopconst.BoolAttribute, v bool) *Span {
func (span *Span) Bool(k *xopat.BoolAttribute, v bool) *Span {
span.base.MetadataBool(k, v)
return span.eft()
}

// Enum adds a xopconst.Enum key/value attribute to the current Span.
// Enum adds a xopat.Enum key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Enum(k *xopconst.EnumAttribute, v xopconst.Enum) *Span {
func (span *Span) Enum(k *xopat.EnumAttribute, v xopat.Enum) *Span {
span.base.MetadataEnum(k, v)
return span.eft()
}

// Float64 adds a float64 key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Float64(k *xopconst.Float64Attribute, v float64) *Span {
func (span *Span) Float64(k *xopat.Float64Attribute, v float64) *Span {
span.base.MetadataFloat64(k, v)
return span.eft()
}

// Link adds a trace.Trace key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Link(k *xopconst.LinkAttribute, v trace.Trace) *Span {
func (span *Span) Link(k *xopat.LinkAttribute, v trace.Trace) *Span {
span.base.MetadataLink(k, v)
return span.eft()
}

// String adds a string key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) String(k *xopconst.StringAttribute, v string) *Span {
func (span *Span) String(k *xopat.StringAttribute, v string) *Span {
span.base.MetadataString(k, v)
return span.eft()
}

// Time adds a time.Time key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Time(k *xopconst.TimeAttribute, v time.Time) *Span {
func (span *Span) Time(k *xopat.TimeAttribute, v time.Time) *Span {
span.base.MetadataTime(k, v)
return span.eft()
}

// should skip Int64
// Duration adds a time.Duration key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Duration(k *xopconst.DurationAttribute, v time.Duration) *Span {
func (span *Span) Duration(k *xopat.DurationAttribute, v time.Duration) *Span {
span.base.MetadataInt64(&k.Int64Attribute, int64(v))
return span.eft()
}

// Int adds a int key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Int(k *xopconst.IntAttribute, v int) *Span {
func (span *Span) Int(k *xopat.IntAttribute, v int) *Span {
span.base.MetadataInt64(&k.Int64Attribute, int64(v))
return span.eft()
}

// Int16 adds a int16 key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Int16(k *xopconst.Int16Attribute, v int16) *Span {
func (span *Span) Int16(k *xopat.Int16Attribute, v int16) *Span {
span.base.MetadataInt64(&k.Int64Attribute, int64(v))
return span.eft()
}

// Int32 adds a int32 key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Int32(k *xopconst.Int32Attribute, v int32) *Span {
func (span *Span) Int32(k *xopat.Int32Attribute, v int32) *Span {
span.base.MetadataInt64(&k.Int64Attribute, int64(v))
return span.eft()
}

// Int8 adds a int8 key/value attribute to the current Span.
// The return value does not need to be used.
func (span *Span) Int8(k *xopconst.Int8Attribute, v int8) *Span {
func (span *Span) Int8(k *xopat.Int8Attribute, v int8) *Span {
span.base.MetadataInt64(&k.Int64Attribute, int64(v))
return span.eft()
}
Loading

0 comments on commit 9dab975

Please sign in to comment.