Skip to content

Commit

Permalink
xopjson no longer buffers internally.
Browse files Browse the repository at this point in the history
xopbytes has a richer API.

Incompatible changes:

- xopjson no longer supports WithBufferedLines()
- xopbytes.BytesWriter interface has additional and changed methods

  xopbytes.WriteToIOWriter() is unchanged
  • Loading branch information
muir committed Oct 13, 2022
1 parent 6964c2a commit e5a638c
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 350 deletions.
1 change: 1 addition & 0 deletions xopat/attributes.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions xopat/attributes.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (r Attribute) RegistrationNumber() int { return r.number }
func (r Attribute) ExampleValue() interface{} { return r.exampleValue }
func (r Attribute) TypeName() string { return r.typeName }
func (r Attribute) SubType() AttributeType { return r.subType }
func (r *Attribute) Ptr() *Attribute { return r }

// EnumName only provides non-empty answers when SubType() == AttributeTypeEnum
func (r Attribute) EnumName(v int64) string {
Expand Down
29 changes: 27 additions & 2 deletions xopbytes/bytelogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,41 @@
package xopbytes

import (
"time"

"github.com/xoplog/xop-go/trace"
"github.com/xoplog/xop-go/xopat"
"github.com/xoplog/xop-go/xopnum"
)

type BytesWriter interface {
Request(span trace.Bundle) BytesRequest
Buffered() bool
Close() // no point in returning an error
Close() // no point in returning an error
DefineAttribute(*xopat.Attribute) // duplicate calls should be ignored
DefineEnum(*xopat.EnumAttribute, xopat.Enum) // duplicate calls should be ignored
}

type BytesRequest interface {
Flush() error
Write([]byte) (int, error)
ReclaimMemory() // called when we know BytesRequest will never be used again
Span(Span, Buffer) error
Line(Line) error
AttributeReferenced(*xopat.Attribute) error
}

type Buffer interface {
AsBytes() []byte
ReclaimMemory()
}

type Line interface {
Buffer
GetSpanID() trace.HexBytes8
GetLevel() xopnum.Level
GetTime() time.Time
}

type Span interface {
GetSpanID() trace.HexBytes8
}
22 changes: 18 additions & 4 deletions xopbytes/iowriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io"

"github.com/xoplog/xop-go/trace"
"github.com/xoplog/xop-go/xopat"
)

var _ BytesWriter = IOWriter{}
Expand All @@ -18,10 +19,23 @@ func WriteToIOWriter(w io.Writer) BytesWriter {
}
}

func (iow IOWriter) Buffered() bool { return false }
func (iow IOWriter) Flush() error { return nil }
func (iow IOWriter) Request(trace.Bundle) BytesRequest { return iow }

func (iow IOWriter) Buffered() bool { return false }
func (iow IOWriter) Flush() error { return nil }
func (iow IOWriter) ReclaimMemory() {}
func (iow IOWriter) Request(trace.Bundle) BytesRequest { return iow }
func (iow IOWriter) DefineEnum(*xopat.EnumAttribute, xopat.Enum) {}
func (iow IOWriter) DefineAttribute(*xopat.Attribute) {}
func (iow IOWriter) AttributeReferenced(_ *xopat.Attribute) error { return nil }
func (iow IOWriter) Line(line Line) error {
_, err := iow.Write(line.AsBytes())
line.ReclaimMemory()
return err
}
func (iow IOWriter) Span(_ Span, buffer Buffer) error {
_, err := iow.Write(buffer.AsBytes())
buffer.ReclaimMemory()
return err
}
func (iow IOWriter) Close() {
if wc, ok := iow.Writer.(io.WriteCloser); ok {
_ = wc.Close()
Expand Down
174 changes: 28 additions & 146 deletions xopjson/jsonlogger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e5a638c

Please sign in to comment.