Documentation
¶
Index ¶
- Variables
- func LastLines(logBuffer *RingBuffer, n int, indent string, stripPrefix bool) (string, error)
- func NewFormatWriter(dest io.Writer, serviceName string) io.Writer
- type Entry
- type Iterator
- type Parser
- type RingBuffer
- func (rb *RingBuffer) Available() int
- func (rb *RingBuffer) Buffered() int
- func (rb *RingBuffer) Close() error
- func (rb *RingBuffer) Closed() bool
- func (rb *RingBuffer) Copy(dest []byte, start RingPos) (next RingPos, n int, err error)
- func (rb *RingBuffer) Discard(n int) error
- func (rb *RingBuffer) HeadIterator(lines int) Iterator
- func (rb *RingBuffer) Positions() (start RingPos, end RingPos)
- func (rb *RingBuffer) Size() int
- func (rb *RingBuffer) TailIterator() Iterator
- func (rb *RingBuffer) Write(p []byte) (written int, err error)
- func (rb *RingBuffer) WriteTo(writer io.Writer, start RingPos) (next RingPos, n int64, err error)
- type RingPos
Constants ¶
This section is empty.
Variables ¶
var (
ErrRange = errors.New("out of range")
)
Functions ¶
func LastLines ¶
LastLines fetches the last n lines of output and, if stripPrefix is true, strips the timestamp and service name prefix from each line. If there are more than n lines, the result is prefixed with a "(...)" line.
func NewFormatWriter ¶
NewFormatWriter returns a io.Writer that inserts timestamp and service name for every line in the stream. For the input:
first\n second\n third\n
The expected output is:
2021-05-13T03:16:51.001Z [test] first\n 2021-05-13T03:16:52.002Z [test] second\n 2021-05-13T03:16:53.003Z [test] third\n
Types ¶
type Iterator ¶
type Iterator interface { // Close removes this iterator from the ring buffer. After calling Close, // any future calls to Next will return false. Close() error // Next returns true if there is more data to read. If a non-nil cancel // channel is passed in, Next will wait for more data to become available. // Sending on this channel, or closing it, will cause Next to return // immediately. // If the ring buffer writer produces data faster than the iterator can read // it, the iterator will eventually be truncated and restarted. The // truncation will be identified in the iterator output with the text // specified when the iterator was created. Next(cancel <-chan struct{}) bool // Notify sets the notification channel. When more data is available, the // channel passed in to Notify will have true sent on it. If the channel is // not receiving (unbuffered) or full (buffered), the notification will be // dropped. Notify(ch chan bool) // Buffered returns the approximate number of bytes available to read. Buffered() int io.Reader io.WriterTo }
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses and iterates over logs from a Reader until EOF (or another error occurs).
func (*Parser) Entry ¶
Entry returns the current log entry (should only be called after Next returns true).
type RingBuffer ¶
type RingBuffer struct {
// contains filtered or unexported fields
}
RingBuffer is a io.Writer that uses a single byte buffer to store data written to it until Release is called on the range no-longer required. RingBuffer is effectively a linear allocator with sequential frees that must be done in the same order as the allocations.
func NewRingBuffer ¶
func NewRingBuffer(size int) *RingBuffer
NewRingBuffer creates a RingBuffer with the provided size in bytes for the backing buffer.
func (*RingBuffer) Available ¶
func (rb *RingBuffer) Available() int
Available returns the number of bytes available to allocate.
func (*RingBuffer) Buffered ¶
func (rb *RingBuffer) Buffered() int
Buffered returns the number of bytes readable from the buffer.
func (*RingBuffer) Close ¶
func (rb *RingBuffer) Close() error
Close closes the writer to further writes, readers may continue.
func (*RingBuffer) Closed ¶
func (rb *RingBuffer) Closed() bool
Closed returns true if the writing side has closed.
func (*RingBuffer) Copy ¶
Copy copies bytes into dest upto the length of dest, starting at the supplied start position in the RingBuffer. If start is outside of the range that is buffered, ErrRange is returned.
func (*RingBuffer) Discard ¶
func (rb *RingBuffer) Discard(n int) error
Discard disposes of n bytes from the tail of the buffer making them available to be used for subsequent writes.
func (*RingBuffer) HeadIterator ¶
func (rb *RingBuffer) HeadIterator(lines int) Iterator
HeadIterator returns an iterator from the head of the buffer. If lines is greater than zero, the iterator will start that many lines backwards from the head.
func (*RingBuffer) Positions ¶
func (rb *RingBuffer) Positions() (start RingPos, end RingPos)
Positions returns the start and end positions of readable data in the RingBuffer.
func (*RingBuffer) Size ¶
func (rb *RingBuffer) Size() int
Size returns the size in bytes of the internal buffer.
func (*RingBuffer) TailIterator ¶
func (rb *RingBuffer) TailIterator() Iterator
TailIterator returns an iterator from the tail of the buffer.
func (*RingBuffer) Write ¶
func (rb *RingBuffer) Write(p []byte) (written int, err error)
Write writes p to the backing buffer, allocating the number of bytes in p. If p is larger than the size of the buffer then io.ErrShortWrite is returned and the number of bytes written. If the p is larger than the number of bytes available, then the tail is discarded to make room.