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) 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 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 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:"-"`
}
Click to show internal directories.
Click to hide internal directories.