formatter

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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 Details 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 Details added in v0.0.18

type Details 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 (*Details) SetHeaders added in v0.0.18

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

func (*Details) SetRequest added in v0.0.18

func (k *Details) SetRequest(request any)

func (*Details) SetResponse added in v0.0.18

func (k *Details) SetResponse(response any)

type Formatter

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

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   Details   `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