formatter

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package formatter provides various strategies for transforming structured LogMessage objects into strings suitable for different output targets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter interface {
	// Format takes a LogMessage and returns its string representation.
	// It must be thread-safe if shared across multiple goroutines.
	Format(msg types.LogMessage) string
}

Formatter defines the contract for any component that needs to convert a LogMessage into a printable format. Implementations can focus on human readability, machine parsing, or specific external log protocols.

type HumanFormatter

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

HumanFormatter converts LogMessages into a visually rich, color-coded string optimized for terminal consumption. It maintains state to ensure that container names are consistently colored throughout the session.

func NewHumanFormatter

func NewHumanFormatter(timeFormat string, colors []*color.Color) *HumanFormatter

NewHumanFormatter initializes a HumanFormatter with a specific time layout and a color palette.

func (*HumanFormatter) Format

func (h *HumanFormatter) Format(msg types.LogMessage) string

Format applies colorization and layout to a LogMessage. The output format is: [LEVEL][TIMESTAMP] container="name" message...

type JsonFormatter

type JsonFormatter struct{}

JsonFormatter transforms a LogMessage into a single-line JSON string. This is ideal for piping output into tools like 'jq' or sending logs to centralized logging systems like ELK or Datadog.

func NewJsonFormatter

func NewJsonFormatter() *JsonFormatter

NewJsonFormatter creates a new instance of JsonFormatter.

func (*JsonFormatter) Format

func (j *JsonFormatter) Format(msg types.LogMessage) string

Format marshals the LogMessage into JSON and appends a newline. It ignores any errors during marshaling and returns an empty string if it fails.

Jump to

Keyboard shortcuts

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