Documentation
¶
Index ¶
- Constants
- Variables
- func CreateFormatter(name string) (types.Formatter, error)
- func CreateFormatterByType(formatType int) (types.Formatter, error)
- func Register(name string, constructor FormatterConstructor) error
- type BatchFormatter
- type ContextualFormatter
- type EnhancedFormatter
- type Factory
- type FormatOption
- type FormatOptions
- type FormatterConstructor
- type JSONFormatter
- type LevelFormat
- type StreamFormatter
- type TextFormatter
Constants ¶
const ( FormatText = 0 FormatJSON = 1 FormatCustom = 2 )
Format type constants
const ( LevelTrace = 0 LevelDebug = 1 LevelInfo = 2 LevelWarn = 3 LevelError = 4 )
Log level constants
Variables ¶
var DefaultFactory = NewFactory()
DefaultFactory is the global formatter factory
Functions ¶
func CreateFormatter ¶
CreateFormatter creates a formatter using the default factory
func CreateFormatterByType ¶
CreateFormatterByType creates a formatter by type using the default factory
func Register ¶
func Register(name string, constructor FormatterConstructor) error
Register registers a formatter with the default factory
Types ¶
type BatchFormatter ¶
type BatchFormatter interface {
types.Formatter
// FormatBatch formats multiple messages as a batch
FormatBatch(messages []types.LogMessage) ([]byte, error)
}
BatchFormatter can format multiple messages at once
type ContextualFormatter ¶
type ContextualFormatter interface {
types.Formatter
// WithContext adds contextual information to the formatter
WithContext(key string, value interface{}) ContextualFormatter
// ClearContext removes all contextual information
ClearContext()
}
ContextualFormatter includes contextual information in formatting
type EnhancedFormatter ¶
type EnhancedFormatter interface {
types.Formatter
// SetFieldOrder sets the order of fields in output
SetFieldOrder(fields []string)
// SetFieldFilter sets which fields to include/exclude
SetFieldFilter(include []string, exclude []string)
// SetIndentation sets indentation for structured output
SetIndentation(indent string)
}
EnhancedFormatter provides enhanced formatting capabilities
type Factory ¶
type Factory struct {
// contains filtered or unexported fields
}
Factory creates formatter instances
func NewFactory ¶
func NewFactory() *Factory
NewFactory creates a new formatter factory with default formatters registered
func (*Factory) CreateFormatter ¶
CreateFormatter creates a formatter by name
func (*Factory) CreateFormatterByType ¶
CreateFormatterByType creates a formatter by type constant
func (*Factory) ListFormatters ¶
ListFormatters returns the names of all registered formatters
type FormatOptions ¶
type FormatOptions struct {
TimestampFormat string
IncludeLevel bool
IncludeTime bool
LevelFormat LevelFormat
IndentJSON bool
FieldSeparator string
TimeZone *time.Location
FlattenFields bool // Whether to flatten nested fields in JSON output
IncludeSource bool // Whether to include source field
IncludeHost bool // Whether to include hostname field
}
FormatOptions controls the output format
func DefaultFormatOptions ¶
func DefaultFormatOptions() FormatOptions
DefaultFormatOptions returns default formatting options
type FormatterConstructor ¶
FormatterConstructor is a function that creates a formatter
type JSONFormatter ¶
type JSONFormatter struct {
Options FormatOptions
IncludeFields []string // Optional: specific fields to include
ExcludeFields []string // Optional: fields to exclude
}
JSONFormatter formats log messages as JSON
func NewJSONFormatter ¶
func NewJSONFormatter() *JSONFormatter
NewJSONFormatter creates a new JSON formatter
func (*JSONFormatter) Format ¶
func (f *JSONFormatter) Format(msg types.LogMessage) ([]byte, error)
Format formats a log message as JSON
func (*JSONFormatter) WithExcludeFields ¶
func (f *JSONFormatter) WithExcludeFields(fields ...string) *JSONFormatter
WithExcludeFields sets fields to exclude from JSON output
func (*JSONFormatter) WithIncludeFields ¶
func (f *JSONFormatter) WithIncludeFields(fields ...string) *JSONFormatter
WithIncludeFields sets fields to include in JSON output
type LevelFormat ¶
type LevelFormat int
LevelFormat defines level format options
const ( // LevelFormatName formats levels as their names (DEBUG, INFO, etc) LevelFormatName LevelFormat = iota // LevelFormatNameUpper formats levels as uppercase names LevelFormatNameUpper // LevelFormatNameLower formats levels as lowercase names LevelFormatNameLower // LevelFormatSymbol formats levels as single-character symbols LevelFormatSymbol )
type StreamFormatter ¶
type StreamFormatter interface {
types.Formatter
// StartStream initializes streaming output
StartStream() ([]byte, error)
// EndStream finalizes streaming output
EndStream() ([]byte, error)
}
StreamFormatter formats messages for streaming output
type TextFormatter ¶
type TextFormatter struct {
Options FormatOptions
}
TextFormatter formats log messages as human-readable text
func NewTextFormatter ¶
func NewTextFormatter() *TextFormatter
NewTextFormatter creates a new text formatter
func (*TextFormatter) Format ¶
func (f *TextFormatter) Format(msg types.LogMessage) ([]byte, error)
Format formats a log message as text
func (*TextFormatter) FormatFields ¶
func (f *TextFormatter) FormatFields(fields map[string]interface{}) string
FormatFields formats fields as key=value pairs