contentlog

package
v0.22.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package contentlog provides a JSON writer that can write JSON to a buffer without any memory allocations and Logger that can write log entries with strongly-typed parameters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emit

func Emit[T WriterTo](ctx context.Context, l *Logger, entry T)

Emit writes the entry to the segment writer. We are using this particular syntax to avoid allocating an intermediate interface value. This allows exactly zero non-amortized allocations in all cases.

func HashSpanID

func HashSpanID(v string) string

HashSpanID hashes a given value a Span ID.

func Log

func Log(ctx context.Context, l *Logger, text string)

Log logs a message with no parameters.

func Log1

func Log1[T1 ParamWriter](ctx context.Context, l *Logger, format string, value1 T1)

Log1 logs a message with one parameter.

func Log2

func Log2[T1, T2 ParamWriter](ctx context.Context, l *Logger, format string, value1 T1, value2 T2)

Log2 logs a message with two parameters.

func Log3

func Log3[T1, T2, T3 ParamWriter](ctx context.Context, l *Logger, format string, value1 T1, value2 T2, value3 T3)

Log3 logs a message with three parameters.

func Log4

func Log4[T1, T2, T3, T4 ParamWriter](ctx context.Context, l *Logger, format string, value1 T1, value2 T2, value3 T3, value4 T4)

Log4 logs a message with four parameters.

func Log5

func Log5[T1, T2, T3, T4, T5 ParamWriter](ctx context.Context, l *Logger, format string, value1 T1, value2 T2, value3 T3, value4 T4, value5 T5)

Log5 logs a message with five parameters.

func Log6

func Log6[T1, T2, T3, T4, T5, T6 ParamWriter](ctx context.Context, l *Logger, format string, value1 T1, value2 T2, value3 T3, value4 T4, value5 T5, value6 T6)

Log6 logs a message with six parameters.

func RandomSpanID

func RandomSpanID() string

RandomSpanID generates a random span ID (40 bits encoded as 5 base32 characters == 8 ASCII characters).

func WithParams

func WithParams(ctx context.Context, params ...ParamWriter) context.Context

WithParams returns a new logger with the given parameters.

Types

type JSONWriter

type JSONWriter struct {
	// contains filtered or unexported fields
}

JSONWriter is a writer that can write JSON to a buffer without any memory allocations.

func NewJSONWriter

func NewJSONWriter() *JSONWriter

NewJSONWriter creates a new JSON writer.

func (*JSONWriter) BeginList

func (jw *JSONWriter) BeginList()

BeginList starts a list.

func (*JSONWriter) BeginListField

func (jw *JSONWriter) BeginListField(key string)

BeginListField starts a list field.

func (*JSONWriter) BeginObject

func (jw *JSONWriter) BeginObject()

BeginObject starts an object.

func (*JSONWriter) BeginObjectField

func (jw *JSONWriter) BeginObjectField(key string)

BeginObjectField starts an object field.

func (*JSONWriter) BoolElement

func (jw *JSONWriter) BoolElement(value bool)

BoolElement writes a boolean element.

func (*JSONWriter) BoolField

func (jw *JSONWriter) BoolField(key string, value bool)

BoolField writes a boolean field.

func (*JSONWriter) EndList

func (jw *JSONWriter) EndList()

EndList ends a list.

func (*JSONWriter) EndObject

func (jw *JSONWriter) EndObject()

EndObject ends an object.

func (*JSONWriter) ErrorField

func (jw *JSONWriter) ErrorField(key string, value error)

ErrorField writes an error field.

func (*JSONWriter) GetBufferForTesting

func (jw *JSONWriter) GetBufferForTesting() []byte

GetBufferForTesting returns the internal buffer for testing purposes. This should only be used in tests.

func (*JSONWriter) Int16Element

func (jw *JSONWriter) Int16Element(value int16)

Int16Element writes an int16 element.

func (*JSONWriter) Int16Field

func (jw *JSONWriter) Int16Field(key string, value int16)

Int16Field writes an int16 field.

func (*JSONWriter) Int32Element

func (jw *JSONWriter) Int32Element(value int32)

Int32Element writes an int32 element.

func (*JSONWriter) Int32Field

func (jw *JSONWriter) Int32Field(key string, value int32)

Int32Field writes an int32 field.

func (*JSONWriter) Int64Element

func (jw *JSONWriter) Int64Element(value int64)

Int64Element writes an int64 element.

func (*JSONWriter) Int64Field

func (jw *JSONWriter) Int64Field(key string, value int64)

Int64Field writes an int64 field.

func (*JSONWriter) Int8Element

func (jw *JSONWriter) Int8Element(value int8)

Int8Element writes an int8 element.

func (*JSONWriter) Int8Field

func (jw *JSONWriter) Int8Field(key string, value int8)

Int8Field writes an int8 field.

func (*JSONWriter) IntElement

func (jw *JSONWriter) IntElement(value int)

IntElement writes an int element.

func (*JSONWriter) IntField

func (jw *JSONWriter) IntField(key string, value int)

IntField writes an int field.

func (*JSONWriter) NullElement

func (jw *JSONWriter) NullElement()

NullElement writes a null element.

func (*JSONWriter) NullField

func (jw *JSONWriter) NullField(key string)

NullField writes a null field.

func (*JSONWriter) RawJSONField

func (jw *JSONWriter) RawJSONField(key string, value []byte)

RawJSONField writes a raw JSON field where the value is already in JSON format.

func (*JSONWriter) Release

func (jw *JSONWriter) Release()

Release releases the JSON writer back to the pool.

func (*JSONWriter) Result

func (jw *JSONWriter) Result() []byte

Result returns the internal buffer for testing purposes. This should only be used in tests.

func (*JSONWriter) StringElement

func (jw *JSONWriter) StringElement(value string)

StringElement writes a string element.

func (*JSONWriter) StringField

func (jw *JSONWriter) StringField(key, value string)

StringField writes a string field.

func (*JSONWriter) TimeElement

func (jw *JSONWriter) TimeElement(value time.Time)

TimeElement writes a time element.

func (*JSONWriter) TimeField

func (jw *JSONWriter) TimeField(key string, value time.Time)

TimeField writes a time field.

func (*JSONWriter) UInt16Element

func (jw *JSONWriter) UInt16Element(value uint16)

UInt16Element writes a uint16 element.

func (*JSONWriter) UInt16Field

func (jw *JSONWriter) UInt16Field(key string, value uint16)

UInt16Field writes a uint16 field.

func (*JSONWriter) UInt32Element

func (jw *JSONWriter) UInt32Element(value uint32)

UInt32Element writes a uint32 element.

func (*JSONWriter) UInt32Field

func (jw *JSONWriter) UInt32Field(key string, value uint32)

UInt32Field writes a uint32 field.

func (*JSONWriter) UInt64Element

func (jw *JSONWriter) UInt64Element(value uint64)

UInt64Element writes a uint64 element.

func (*JSONWriter) UInt64Field

func (jw *JSONWriter) UInt64Field(key string, value uint64)

UInt64Field writes a uint64 field.

func (*JSONWriter) UInt8Element

func (jw *JSONWriter) UInt8Element(value uint8)

UInt8Element writes a uint8 element.

func (*JSONWriter) UInt8Field

func (jw *JSONWriter) UInt8Field(key string, value uint8)

UInt8Field writes a uint8 field.

func (*JSONWriter) UIntElement

func (jw *JSONWriter) UIntElement(value uint)

UIntElement writes a uint element.

func (*JSONWriter) UIntField

func (jw *JSONWriter) UIntField(key string, value uint)

UIntField writes a uint field.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a logger that writes log entries to the output.

func NewLogger

func NewLogger(out OutputFunc, params ...ParamWriter) *Logger

NewLogger creates a new logger.

type OutputFunc

type OutputFunc func(data []byte)

OutputFunc is a function that writes the log entry to the output.

type ParamWriter

type ParamWriter interface {
	WriteValueTo(jw *JSONWriter)
}

ParamWriter must be implemented by all types that write a parameter ("key":value)to the JSON writer.

type WriterTo

type WriterTo interface {
	WriteTo(jw *JSONWriter)
}

WriterTo is a type that can write itself to a JSON writer.

Directories

Path Synopsis
Package logparam provides parameters for logging.
Package logparam provides parameters for logging.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL