log

package
v1.2.2-alpha Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const MsgKey = "msg"

Variables

View Source
var FieldsFromContext func(ctx context.Context) []Field

FieldsFromContext can be set to extract structured fields from the context (e.g., trace IDs, user IDs).

View Source
var OnDropEvent func(*Event)

OnDropEvent is a callback function that is called when an event is dropped.

View Source
var StringFromContext func(ctx context.Context) string

StringFromContext can be set to extract a string from the context.

View Source
var TimeNow func(ctx context.Context) time.Time

TimeNow is a function that can be overridden to provide custom timestamp behavior (e.g., for testing).

Functions

func Debug

func Debug(ctx context.Context, tag *Tag, fn func() []Field)

Debug logs a message at DebugLevel using a tag and a lazy field-generating function.

func DumpNode

func DumpNode(node *Node, indent int, buf *bytes.Buffer)

DumpNode prints the structure of a Node to a buffer.

func Error

func Error(ctx context.Context, tag *Tag, fields ...Field)

Error logs a message at ErrorLevel using structured fields.

func Fatal

func Fatal(ctx context.Context, tag *Tag, fields ...Field)

Fatal logs a message at FatalLevel using structured fields.

func Info

func Info(ctx context.Context, tag *Tag, fields ...Field)

Info logs a message at InfoLevel using structured fields.

func NewPlugin

func NewPlugin(t reflect.Type, node *Node, properties map[string]string) (reflect.Value, error)

NewPlugin Creates and initializes a plugin instance.

func Panic

func Panic(ctx context.Context, tag *Tag, fields ...Field)

Panic logs a message at PanicLevel using structured fields.

func PutEvent

func PutEvent(e *Event)

func Record

func Record(ctx context.Context, level Level, tag *Tag, fields ...Field)

Record is the core function that handles publishing log events. It checks the logger level, captures caller information, gathers context fields, and sends the log event to the logger.

func RefreshFile

func RefreshFile(fileName string) error

RefreshFile loads a logging configuration from a file by its name.

func RefreshReader

func RefreshReader(input io.Reader, ext string) error

RefreshReader reads the configuration from an io.Reader using the reader for the given extension.

func RegisterConverter

func RegisterConverter[T any](fn Converter[T])

RegisterConverter Registers a converter for a specific type T.

func RegisterPlugin

func RegisterPlugin[T Lifecycle](name string, typ PluginType)

RegisterPlugin Registers a plugin with a given name and type.

func RegisterReader

func RegisterReader(r Reader, ext ...string)

RegisterReader registers a Reader for one or more file extensions. This allows dynamic selection of parsers based on file type.

func Trace

func Trace(ctx context.Context, tag *Tag, fn func() []Field)

Trace logs a message at TraceLevel using a tag and a lazy field-generating function.

func Warn

func Warn(ctx context.Context, tag *Tag, fields ...Field)

Warn logs a message at WarnLevel using structured fields.

func WriteFields

func WriteFields(enc Encoder, fields []Field)

WriteFields writes a slice of Field objects to the encoder.

Types

type Appender

type Appender interface {
	Lifecycle        // Appenders must be startable and stoppable
	Append(e *Event) // Handles writing a log event
}

Appender is an interface that defines components that handle log output.

type AppenderRef

type AppenderRef struct {
	Ref string `PluginAttribute:"ref"`
	// contains filtered or unexported fields
}

AppenderRef represents a reference to an appender by name, which will be resolved and bound later.

func (*AppenderRef) Start

func (a *AppenderRef) Start() error

func (*AppenderRef) Stop

func (a *AppenderRef) Stop()

type ArrayValue

type ArrayValue []Value

ArrayValue represents a slice of Value carried by Field.

func (ArrayValue) Encode

func (v ArrayValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type AsyncLoggerConfig

type AsyncLoggerConfig struct {
	BufferSize int `PluginAttribute:"bufferSize,default=10000"`
	// contains filtered or unexported fields
}

AsyncLoggerConfig is an asynchronous logger configuration. It buffers log events and processes them in a separate goroutine.

func (*AsyncLoggerConfig) Start

func (c *AsyncLoggerConfig) Start() error

Start initializes the asynchronous logger and starts its worker goroutine.

func (*AsyncLoggerConfig) Stop

func (c *AsyncLoggerConfig) Stop()

Stop shuts down the asynchronous logger and waits for the worker goroutine to finish.

type BaseAppender

type BaseAppender struct {
	Name   string `PluginAttribute:"name"` // Appender name from config
	Layout Layout `PluginElement:"Layout"` // Layout defines how logs are formatted
}

BaseAppender provides shared configuration and behavior for appenders.

func (*BaseAppender) Append

func (c *BaseAppender) Append(e *Event)

func (*BaseAppender) Start

func (c *BaseAppender) Start() error

func (*BaseAppender) Stop

func (c *BaseAppender) Stop()

type BaseLayout

type BaseLayout struct {
	BufferSize     HumanizeBytes `PluginAttribute:"bufferSize,default=1MB"`
	FileLineLength int           `PluginAttribute:"fileLineLength,default=48"`
	// contains filtered or unexported fields
}

BaseLayout is the base class for Layout.

func (*BaseLayout) GetBuffer

func (c *BaseLayout) GetBuffer() *bytes.Buffer

GetBuffer returns a buffer that can be used to format the log event.

func (*BaseLayout) GetFileLine

func (c *BaseLayout) GetFileLine(e *Event) string

GetFileLine returns the file name and line number of the log event.

func (*BaseLayout) PutBuffer

func (c *BaseLayout) PutBuffer(buf *bytes.Buffer)

PutBuffer puts a buffer back into the pool.

func (*BaseLayout) Start

func (c *BaseLayout) Start() error

func (*BaseLayout) Stop

func (c *BaseLayout) Stop()

type BoolValue

type BoolValue bool

BoolValue represents a bool carried by Field.

func (BoolValue) Encode

func (v BoolValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type BoolsValue

type BoolsValue []bool

BoolsValue represents a slice of bool carried by Field.

func (BoolsValue) Encode

func (v BoolsValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type ConsoleAppender

type ConsoleAppender struct {
	BaseAppender
}

ConsoleAppender writes formatted log events to stdout.

func (*ConsoleAppender) Append

func (c *ConsoleAppender) Append(e *Event)

Append formats the event and writes it to standard output.

type Converter

type Converter[T any] func(string) (T, error)

Converter function type that converts string to a specific type T.

type DiscardAppender

type DiscardAppender struct {
	BaseAppender
}

DiscardAppender ignores all log events (no output).

type Encoder

type Encoder interface {
	AppendEncoderBegin()
	AppendEncoderEnd()
	AppendObjectBegin()
	AppendObjectEnd()
	AppendArrayBegin()
	AppendArrayEnd()
	AppendKey(key string)
	AppendBool(v bool)
	AppendInt64(v int64)
	AppendUint64(v uint64)
	AppendFloat64(v float64)
	AppendString(v string)
	AppendReflect(v interface{})
}

Encoder is an interface that defines methods for appending structured data elements.

type Event

type Event struct {
	Level     Level     // The severity level of the log (e.g., INFO, ERROR, DEBUG)
	Time      time.Time // The timestamp when the event occurred
	File      string    // The source file where the log was triggered
	Line      int       // The line number in the source file
	Tag       string    // A tag used to categorize the log (e.g., subsystem name)
	Fields    []Field   // Custom fields provided specifically for this log event
	CtxString string    // The string representation of the context
	CtxFields []Field   // Additional fields derived from the context (e.g., request ID, user ID)
}

Event provides contextual information about a log message.

func GetEvent

func GetEvent() *Event

func (*Event) Reset

func (e *Event) Reset()

type Field

type Field struct {
	Key string // The name of the field.
	Val Value  // The value of the field.
}

Field represents a structured log field with a key and a value.

func Any

func Any(key string, value interface{}) Field

Any creates a Field from a value of any type by inspecting its dynamic type. It dispatches to the appropriate typed constructor based on the actual value. If the type is not explicitly handled, it falls back to using Reflect.

func Array

func Array(key string, val ...Value) Field

Array creates a Field containing a variadic slice of Values, wrapped as an array.

func Bool

func Bool(key string, val bool) Field

Bool creates a Field for a boolean value.

func BoolPtr

func BoolPtr(key string, val *bool) Field

BoolPtr creates a Field from a *bool, or a nil Field if the pointer is nil.

func Bools

func Bools(key string, val []bool) Field

Bools creates a Field with a slice of booleans.

func Float32

func Float32(key string, val float32) Field

Float32 creates a Field for a float32 value.

func Float32Ptr

func Float32Ptr(key string, val *float32) Field

Float32Ptr creates a Field from a *float32, or returns Nil if pointer is nil.

func Float32s

func Float32s(key string, val []float32) Field

Float32s creates a Field with a slice of float32 values.

func Float64

func Float64(key string, val float64) Field

Float64 creates a Field for a float64 value.

func Float64Ptr

func Float64Ptr(key string, val *float64) Field

Float64Ptr creates a Field from a *float64, or returns Nil if pointer is nil.

func Float64s

func Float64s(key string, val []float64) Field

Float64s creates a Field with a slice of float64 values.

func Int

func Int(key string, val int) Field

Int creates a Field for an int value.

func Int16

func Int16(key string, val int16) Field

Int16 creates a Field for an int16 value.

func Int16Ptr

func Int16Ptr(key string, val *int16) Field

Int16Ptr creates a Field from a *int16, or returns Nil if pointer is nil.

func Int16s

func Int16s(key string, val []int16) Field

Int16s creates a Field with a slice of int16 values.

func Int32

func Int32(key string, val int32) Field

Int32 creates a Field for an int32 value.

func Int32Ptr

func Int32Ptr(key string, val *int32) Field

Int32Ptr creates a Field from a *int32, or returns Nil if pointer is nil.

func Int32s

func Int32s(key string, val []int32) Field

Int32s creates a Field with a slice of int32 values.

func Int64

func Int64(key string, val int64) Field

Int64 creates a Field for an int64 value.

func Int64Ptr

func Int64Ptr(key string, val *int64) Field

Int64Ptr creates a Field from a *int64, or returns Nil if pointer is nil.

func Int64s

func Int64s(key string, val []int64) Field

Int64s creates a Field with a slice of int64 values.

func Int8

func Int8(key string, val int8) Field

Int8 creates a Field for an int8 value.

func Int8Ptr

func Int8Ptr(key string, val *int8) Field

Int8Ptr creates a Field from a *int8, or returns Nil if pointer is nil.

func Int8s

func Int8s(key string, val []int8) Field

Int8s creates a Field with a slice of int8 values.

func IntPtr

func IntPtr(key string, val *int) Field

IntPtr creates a Field from a *int, or returns Nil if pointer is nil.

func Ints

func Ints(key string, val []int) Field

Ints creates a Field with a slice of integers.

func Msg

func Msg(msg string) Field

Msg creates a string Field with the "msg" key.

func Msgf

func Msgf(format string, args ...any) Field

Msgf formats a message using fmt.Sprintf and creates a string Field with "msg" key.

func Nil

func Nil(key string) Field

Nil creates a Field with a nil value.

func Object

func Object(key string, fields ...Field) Field

Object creates a Field containing a variadic slice of Fields, treated as a nested object.

func Reflect

func Reflect(key string, val interface{}) Field

Reflect wraps any value into a Field using reflection.

func String

func String(key string, val string) Field

String creates a Field for a string value.

func StringPtr

func StringPtr(key string, val *string) Field

StringPtr creates a Field from a *string, or returns Nil if pointer is nil.

func Strings

func Strings(key string, val []string) Field

Strings creates a Field with a slice of strings.

func Uint

func Uint(key string, val uint) Field

Uint creates a Field for an uint value.

func Uint16

func Uint16(key string, val uint16) Field

Uint16 creates a Field for an uint16 value.

func Uint16Ptr

func Uint16Ptr(key string, val *uint16) Field

Uint16Ptr creates a Field from a *uint16, or returns Nil if pointer is nil.

func Uint16s

func Uint16s(key string, val []uint16) Field

Uint16s creates a Field with a slice of uint16 values.

func Uint32

func Uint32(key string, val uint32) Field

Uint32 creates a Field for an uint32 value.

func Uint32Ptr

func Uint32Ptr(key string, val *uint32) Field

Uint32Ptr creates a Field from a *uint32, or returns Nil if pointer is nil.

func Uint32s

func Uint32s(key string, val []uint32) Field

Uint32s creates a Field with a slice of uint32 values.

func Uint64

func Uint64(key string, val uint64) Field

Uint64 creates a Field for an uint64 value.

func Uint64Ptr

func Uint64Ptr(key string, val *uint64) Field

Uint64Ptr creates a Field from a *uint64, or returns Nil if pointer is nil.

func Uint64s

func Uint64s(key string, val []uint64) Field

Uint64s creates a Field with a slice of uint64 values.

func Uint8

func Uint8(key string, val uint8) Field

Uint8 creates a Field for an uint8 value.

func Uint8Ptr

func Uint8Ptr(key string, val *uint8) Field

Uint8Ptr creates a Field from a *uint8, or returns Nil if pointer is nil.

func Uint8s

func Uint8s(key string, val []uint8) Field

Uint8s creates a Field with a slice of uint8 values.

func UintPtr

func UintPtr(key string, val *uint) Field

UintPtr creates a Field from a *uint, or returns Nil if pointer is nil.

func Uints

func Uints(key string, val []uint) Field

Uints creates a Field with a slice of unsigned integers.

type FileAppender

type FileAppender struct {
	BaseAppender
	FileName string `PluginAttribute:"fileName"`
	// contains filtered or unexported fields
}

FileAppender writes formatted log events to a specified file.

func (*FileAppender) Append

func (c *FileAppender) Append(e *Event)

Append formats the log event and writes it to the file.

func (*FileAppender) Start

func (c *FileAppender) Start() error

func (*FileAppender) Stop

func (c *FileAppender) Stop()

Stop closes the file.

type Float32sValue

type Float32sValue []float32

Float32sValue represents a slice of float32 carried by Field.

func (Float32sValue) Encode

func (v Float32sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Float64Value

type Float64Value float64

Float64Value represents a float64 carried by Field.

func (Float64Value) Encode

func (v Float64Value) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Float64sValue

type Float64sValue []float64

Float64sValue represents a slice of float64 carried by Field.

func (Float64sValue) Encode

func (v Float64sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type HumanizeBytes

type HumanizeBytes int

func ParseHumanizeBytes

func ParseHumanizeBytes(s string) (HumanizeBytes, error)

ParseHumanizeBytes converts a human-readable byte string to an integer.

type Int16sValue

type Int16sValue []int16

Int16sValue represents a slice of int16 carried by Field.

func (Int16sValue) Encode

func (v Int16sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Int32sValue

type Int32sValue []int32

Int32sValue represents a slice of int32 carried by Field.

func (Int32sValue) Encode

func (v Int32sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Int64Value

type Int64Value int64

Int64Value represents an int64 carried by Field.

func (Int64Value) Encode

func (v Int64Value) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Int64sValue

type Int64sValue []int64

Int64sValue represents a slice of int64 carried by Field.

func (Int64sValue) Encode

func (v Int64sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Int8sValue

type Int8sValue []int8

Int8sValue represents a slice of int8 carried by Field.

func (Int8sValue) Encode

func (v Int8sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type IntsValue

type IntsValue []int

IntsValue represents a slice of int carried by Field.

func (IntsValue) Encode

func (v IntsValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type JSONEncoder

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

JSONEncoder is a simple JSON encoder.

func NewJSONEncoder

func NewJSONEncoder(buf *bytes.Buffer) *JSONEncoder

NewJSONEncoder creates a new JSONEncoder.

func (*JSONEncoder) AppendArrayBegin

func (enc *JSONEncoder) AppendArrayBegin()

AppendArrayBegin writes the beginning of a JSON array.

func (*JSONEncoder) AppendArrayEnd

func (enc *JSONEncoder) AppendArrayEnd()

AppendArrayEnd writes the end of a JSON array.

func (*JSONEncoder) AppendBool

func (enc *JSONEncoder) AppendBool(v bool)

AppendBool writes a boolean value.

func (*JSONEncoder) AppendEncoderBegin

func (enc *JSONEncoder) AppendEncoderBegin()

AppendEncoderBegin writes the start of an encoder section.

func (*JSONEncoder) AppendEncoderEnd

func (enc *JSONEncoder) AppendEncoderEnd()

AppendEncoderEnd writes the end of an encoder section.

func (*JSONEncoder) AppendFloat64

func (enc *JSONEncoder) AppendFloat64(v float64)

AppendFloat64 writes a float64 value.

func (*JSONEncoder) AppendInt64

func (enc *JSONEncoder) AppendInt64(v int64)

AppendInt64 writes an int64 value.

func (*JSONEncoder) AppendKey

func (enc *JSONEncoder) AppendKey(key string)

AppendKey writes a JSON key.

func (*JSONEncoder) AppendObjectBegin

func (enc *JSONEncoder) AppendObjectBegin()

AppendObjectBegin writes the beginning of a JSON object.

func (*JSONEncoder) AppendObjectEnd

func (enc *JSONEncoder) AppendObjectEnd()

AppendObjectEnd writes the end of a JSON object.

func (*JSONEncoder) AppendReflect

func (enc *JSONEncoder) AppendReflect(v interface{})

AppendReflect marshals any Go value into JSON and appends it.

func (*JSONEncoder) AppendString

func (enc *JSONEncoder) AppendString(v string)

AppendString writes a string value with proper escaping.

func (*JSONEncoder) AppendUint64

func (enc *JSONEncoder) AppendUint64(u uint64)

AppendUint64 writes an uint64 value.

func (*JSONEncoder) Reset

func (enc *JSONEncoder) Reset()

Reset resets the encoder's state.

type JSONLayout

type JSONLayout struct {
	BaseLayout
}

JSONLayout formats the log event as a structured JSON object.

func (*JSONLayout) ToBytes

func (c *JSONLayout) ToBytes(e *Event) []byte

ToBytes converts a log event to a JSON-formatted byte slice.

type Layout

type Layout interface {
	Lifecycle
	ToBytes(e *Event) []byte
}

Layout is the interface that defines how a log event is converted to bytes.

type Level

type Level int32

Level is an enumeration used to identify the severity of a logging event.

const (
	NoneLevel  Level = iota // No logging
	TraceLevel              // Very detailed logging, typically for debugging at a granular level
	DebugLevel              // Debugging information
	InfoLevel               // General informational messages
	WarnLevel               // Warnings that may indicate a potential problem
	ErrorLevel              // Errors that allow the application to continue running
	PanicLevel              // Severe issues that may lead to a panic
	FatalLevel              // Critical issues that will cause application termination
)

func ParseLevel

func ParseLevel(str string) (Level, error)

ParseLevel converts a string (case-insensitive) into a corresponding Level value. Returns an error if the input string does not match any valid level.

func (Level) String

func (level Level) String() string

type Lifecycle

type Lifecycle interface {
	Start() error
	Stop()
}

Lifecycle Optional lifecycle interface for plugin instances.

type Logger

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

Logger is the primary logging structure used to emit log events.

type LoggerConfig

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

LoggerConfig is a synchronous logger configuration.

func (*LoggerConfig) Start

func (c *LoggerConfig) Start() error

func (*LoggerConfig) Stop

func (c *LoggerConfig) Stop()

type Node

type Node struct {
	Label      string            // Tag name of the XML element
	Children   []*Node           // Child elements (nested tags)
	Attributes map[string]string // Attributes of the XML element
	Text       string            // Text content of the XML element
}

Node represents a parsed XML element with a label (tag name), child nodes, and a map of attributes.

type ObjectValue

type ObjectValue []Field

ObjectValue represents a slice of Field carried by Field.

func (ObjectValue) Encode

func (v ObjectValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Plugin

type Plugin struct {
	Name  string       // Name of plugin
	Type  PluginType   // Type of plugin
	Class reflect.Type // Underlying struct type
	File  string       // Source file of registration
	Line  int          // Line number of registration
}

Plugin metadata structure

type PluginTag

type PluginTag string

func (PluginTag) Get

func (tag PluginTag) Get(key string) string

Get Gets the value of a key or the first unnamed value.

func (PluginTag) Lookup

func (tag PluginTag) Lookup(key string) (value string, ok bool)

Lookup Looks up a key-value pair in the tag.

type PluginType

type PluginType string

PluginType Defines types of plugins supported by the logging system.

const (
	PluginTypeAppender    PluginType = "Appender"
	PluginTypeLayout      PluginType = "Layout"
	PluginTypeAppenderRef PluginType = "AppenderRef"
	PluginTypeRoot        PluginType = "Root"
	PluginTypeAsyncRoot   PluginType = "AsyncRoot"
	PluginTypeLogger      PluginType = "Logger"
	PluginTypeAsyncLogger PluginType = "AsyncLogger"
)

type Reader

type Reader interface {
	Read(b []byte) (*Node, error)
}

Reader is an interface for reading and parsing data into a Node structure.

type ReflectValue

type ReflectValue struct {
	Val interface{}
}

ReflectValue represents an interface{} carried by Field.

func (ReflectValue) Encode

func (v ReflectValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type StringValue

type StringValue string

StringValue represents a string carried by Field.

func (StringValue) Encode

func (v StringValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type StringsValue

type StringsValue []string

StringsValue represents a slice of string carried by Field.

func (StringsValue) Encode

func (v StringsValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Tag

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

Tag is a struct representing a named logging tag. It holds a pointer to a Logger and a string identifier.

func GetTag

func GetTag(tag string) *Tag

GetTag creates or retrieves a Tag by name. If the tag does not exist, it is created and added to the global registry.

func (*Tag) GetLogger

func (m *Tag) GetLogger() *Logger

GetLogger returns the Logger associated with this tag. It uses atomic loading to ensure safe concurrent access.

func (*Tag) GetName

func (m *Tag) GetName() string

GetName returns the name of the tag.

func (*Tag) SetLogger

func (m *Tag) SetLogger(logger *Logger)

SetLogger sets or replaces the Logger associated with this tag. Uses atomic storing to ensure thread safety.

type TextEncoder

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

TextEncoder encodes key-value pairs in a plain text format, optionally using JSON when inside objects/arrays.

func NewTextEncoder

func NewTextEncoder(buf *bytes.Buffer, separator string) *TextEncoder

NewTextEncoder creates a new TextEncoder, using the specified separator.

func (*TextEncoder) AppendArrayBegin

func (enc *TextEncoder) AppendArrayBegin()

AppendArrayBegin signals the start of a JSON array. Increments the depth and delegates to the JSON encoder.

func (*TextEncoder) AppendArrayEnd

func (enc *TextEncoder) AppendArrayEnd()

AppendArrayEnd signals the end of a JSON array. Decrements the depth and resets the JSON encoder if back to top level.

func (*TextEncoder) AppendBool

func (enc *TextEncoder) AppendBool(v bool)

AppendBool appends a boolean value, using JSON encoder if nested.

func (*TextEncoder) AppendEncoderBegin

func (enc *TextEncoder) AppendEncoderBegin()

AppendEncoderBegin writes the start of an encoder section.

func (*TextEncoder) AppendEncoderEnd

func (enc *TextEncoder) AppendEncoderEnd()

AppendEncoderEnd writes the end of an encoder section.

func (*TextEncoder) AppendFloat64

func (enc *TextEncoder) AppendFloat64(v float64)

AppendFloat64 appends a float64 value, using JSON encoder if nested.

func (*TextEncoder) AppendInt64

func (enc *TextEncoder) AppendInt64(v int64)

AppendInt64 appends an int64 value, using JSON encoder if nested.

func (*TextEncoder) AppendKey

func (enc *TextEncoder) AppendKey(key string)

AppendKey appends a key for a key-value pair. If inside a JSON structure, the key is handled by the JSON encoder. Otherwise, it's written directly with proper separator handling.

func (*TextEncoder) AppendObjectBegin

func (enc *TextEncoder) AppendObjectBegin()

AppendObjectBegin signals the start of a JSON object. Increments the depth and delegates to the JSON encoder.

func (*TextEncoder) AppendObjectEnd

func (enc *TextEncoder) AppendObjectEnd()

AppendObjectEnd signals the end of a JSON object. Decrements the depth and resets the JSON encoder if back to top level.

func (*TextEncoder) AppendReflect

func (enc *TextEncoder) AppendReflect(v interface{})

AppendReflect uses reflection to marshal any value as JSON. If nested, delegates to JSON encoder.

func (*TextEncoder) AppendString

func (enc *TextEncoder) AppendString(v string)

AppendString appends a string value, using JSON encoder if nested.

func (*TextEncoder) AppendUint64

func (enc *TextEncoder) AppendUint64(v uint64)

AppendUint64 appends a uint64 value, using JSON encoder if nested.

type TextLayout

type TextLayout struct {
	BaseLayout
}

TextLayout formats the log event as a human-readable text string.

func (*TextLayout) ToBytes

func (c *TextLayout) ToBytes(e *Event) []byte

ToBytes converts a log event to a formatted plain-text line.

type Uint16sValue

type Uint16sValue []uint16

Uint16sValue represents a slice of uint16 carried by Field.

func (Uint16sValue) Encode

func (v Uint16sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Uint32sValue

type Uint32sValue []uint32

Uint32sValue represents a slice of uint32 carried by Field.

func (Uint32sValue) Encode

func (v Uint32sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Uint64Value

type Uint64Value uint64

Uint64Value represents an uint64 carried by Field.

func (Uint64Value) Encode

func (v Uint64Value) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Uint64sValue

type Uint64sValue []uint64

Uint64sValue represents a slice of uint64 carried by Field.

func (Uint64sValue) Encode

func (v Uint64sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Uint8sValue

type Uint8sValue []uint8

Uint8sValue represents a slice of uint8 carried by Field.

func (Uint8sValue) Encode

func (v Uint8sValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type UintsValue

type UintsValue []uint

UintsValue represents a slice of uint carried by Field.

func (UintsValue) Encode

func (v UintsValue) Encode(enc Encoder)

Encode encodes the data represented by v to an Encoder.

type Value

type Value interface {
	Encode(enc Encoder)
}

Value is an interface for types that can encode themselves using an Encoder.

type XMLReader

type XMLReader struct{}

XMLReader is an implementation of the Reader interface that parses XML data.

func (*XMLReader) Read

func (r *XMLReader) Read(b []byte) (*Node, error)

Read parses XML bytes into a tree of Nodes. It uses a stack to track the current position in the XML hierarchy.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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