formatter

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Overview

Package formatter provides the structured log models and formatting strategies used by the logger module.

It defines the shape of log entries, service traces, and request metadata, and it can render logs as plain text, JSON, or custom templates.

Main entry points:

  • New to create a template-aware formatter
  • Formatter as the formatting contract
  • LogFormat, Service, and KibanaData as the core log data structures

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CustomFormatter

type CustomFormatter struct {
	Template string
}

func New

func New(template string) *CustomFormatter

func (*CustomFormatter) Format

func (f *CustomFormatter) Format(log LogFormat) ([]byte, error)

func (*CustomFormatter) FormatJSON

func (f *CustomFormatter) FormatJSON(log LogFormat) ([]byte, error)

func (*CustomFormatter) FormatTemplate

func (f *CustomFormatter) FormatTemplate(log LogFormat) ([]byte, error)

func (*CustomFormatter) FormatText

func (f *CustomFormatter) FormatText(log LogFormat) ([]byte, error)

type Formatter

type Formatter interface {
	Format(log LogFormat) ([]byte, error)
}

type KibanaData

type KibanaData struct {
	System   string      `json:"system"`
	Client   string      `json:"client,omitempty"`
	Protocol string      `json:"protocol,omitempty"`
	Method   string      `json:"method,omitempty"`
	Path     string      `json:"path,omitempty"`
	Headers  http.Header `json:"headers,omitempty"`
	Request  any         `json:"request,omitempty"`
	Response any         `json:"response,omitempty"`
}

func (*KibanaData) SetHeaders

func (k *KibanaData) SetHeaders(headers http.Header)

func (*KibanaData) SetRequest

func (k *KibanaData) SetRequest(request any)

func (*KibanaData) SetResponse

func (k *KibanaData) SetResponse(response any)

type Level

type Level string
const (
	InfoLevel  Level = "INFO"
	DebugLevel Level = "DEBUG"
	WarnLevel  Level = "WARN"
	ErrorLevel Level = "ERROR"
)

type LogFormat

type LogFormat struct {
	Timestamp string     `json:"timestamp"`
	TraceID   string     `json:"traceID"`
	Level     Level      `json:"level"`
	Message   string     `json:"message"`
	Details   KibanaData `json:"details"`
	Services  []Service  `json:"services"`
	Method    string     `json:"method"`
	Line      int        `json:"line"`
	Latency   int64      `json:"latency"`
}

type Service

type Service struct {
	TraceID string `json:"traceID,omitempty"`
	System  string `json:"system"`
	Process string `json:"process"`

	Server   string       `json:"server,omitempty"`
	Headers  *http.Header `json:"headers,omitempty"`
	Protocol string       `json:"protocol,omitempty"`
	Method   string       `json:"method,omitempty"`
	Code     int64        `json:"code,omitempty"`
	Path     string       `json:"path,omitempty"`

	DisableBody bool `json:"-"`
	Request     any  `json:"request,omitempty"`
	Response    any  `json:"response,omitempty"`

	Status  Status `json:"status"`
	Latency int64  `json:"latency"`

	TimeInit time.Time  `json:"-"`
	Span     trace.Span `json:"-"`
}

type Status

type Status string
const (
	SUCCESS Status = "SUCCESS"
	ERROR   Status = "ERROR"
	OTHER   Status = "OTHER"
)

Jump to

Keyboard shortcuts

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