Documentation
¶
Index ¶
- Constants
- func AppendJSONEvent(buf *bytes.Buffer, when time.Time, level slog.Level, logger string, ...)
- func AppendJSONFixedEvent(buf *bytes.Buffer, when time.Time, level slog.Level, logger string, ...)
- func RequiresSynchronizedFormatting(layout Layout) bool
- func WriteFooter(writer io.Writer, layout Layout) (int, error)
- func WriteHeader(writer io.Writer, layout Layout) (int, error)
- type CSVLayout
- type Event
- type GELFLayout
- type HTMLLayout
- type JSONLayout
- func (l JSONLayout) AppendFooter(buf *bytes.Buffer) error
- func (l JSONLayout) AppendHeader(buf *bytes.Buffer) error
- func (l JSONLayout) CloneLayout() Layout
- func (l JSONLayout) Format(buf *bytes.Buffer, event Event) error
- func (l JSONLayout) Options() LayoutOptions
- func (l JSONLayout) RequiresSynchronizedFormatting() bool
- type JSONTemplateLayout
- func (l *JSONTemplateLayout) AppendFooter(buf *bytes.Buffer) error
- func (l *JSONTemplateLayout) AppendHeader(buf *bytes.Buffer) error
- func (l *JSONTemplateLayout) CloneLayout() Layout
- func (l *JSONTemplateLayout) Format(buf *bytes.Buffer, event Event) error
- func (l *JSONTemplateLayout) RequiresSynchronizedFormatting() bool
- type JSONTemplateLayoutOption
- type JSONTemplateResolver
- type JSONTemplateResolverBuildConfig
- type JSONTemplateResolverFactory
- type JSONTemplateResolverLookup
- type Layout
- type LayoutOptions
- type PatternLayout
- type RFC5424Layout
- type StructuredECSOptions
- type StructuredFormat
- type StructuredGELFOptions
- type StructuredJSONCustomizer
- type StructuredJSONCustomizerFunc
- type StructuredJSONFieldAppender
- type StructuredJSONLayout
- type StructuredJSONOptions
- type StructuredStacktraceOptions
- type StructuredStacktracePrinter
- type SyslogLayout
- type TextLayout
- type Throwable
- type XMLLayout
- type YAMLLayout
Constants ¶
const DefaultSpringBootPattern = "%d{yyyy-MM-dd HH:mm:ss.SSS} %5level %pid - " +
"[%15.15thread] %-40.40logger{1.2*} : %msg%attrs%n"
DefaultSpringBootPattern 是默认控制台输出格式,风格对齐 Spring Boot。
Variables ¶
This section is empty.
Functions ¶
func AppendJSONEvent ¶
func AppendJSONEvent( buf *bytes.Buffer, when time.Time, level slog.Level, logger string, message string, attrs []slog.Attr, )
AppendJSONEvent 用零额外状态编码 JSON 单行事件。
func AppendJSONFixedEvent ¶
func AppendJSONFixedEvent( buf *bytes.Buffer, when time.Time, level slog.Level, logger string, message string, attrs [3]slog.Attr, count int, )
AppendJSONFixedEvent 编码最多三个属性的固定数组事件,避免热路径切片分配。
func RequiresSynchronizedFormatting ¶
RequiresSynchronizedFormatting 判断布局格式化是否必须与写入在同一临界区内完成。
func WriteFooter ¶
WriteFooter 在支持生命周期的布局上写入流页脚。
Types ¶
type CSVLayout ¶
type CSVLayout struct {
// contains filtered or unexported fields
}
CSVLayout 输出单行 CSV,字段顺序固定。
type GELFLayout ¶
type GELFLayout struct {
// contains filtered or unexported fields
}
GELFLayout 输出 Graylog Extended Log Format 单行 JSON。
func NewGELFLayout ¶
func NewGELFLayout(options LayoutOptions) GELFLayout
NewGELFLayout 创建可配置 GELF 布局。
func (GELFLayout) AppendFooter ¶
func (l GELFLayout) AppendFooter(buf *bytes.Buffer) error
func (GELFLayout) AppendHeader ¶
func (l GELFLayout) AppendHeader(buf *bytes.Buffer) error
type HTMLLayout ¶
type HTMLLayout struct {
// contains filtered or unexported fields
}
HTMLLayout 输出 HTML 表格行,适合文件或控制台片段组合。
func NewHTMLLayout ¶
func NewHTMLLayout(options LayoutOptions) HTMLLayout
NewHTMLLayout 创建可配置 HTML 布局。
func (HTMLLayout) AppendFooter ¶
func (l HTMLLayout) AppendFooter(buf *bytes.Buffer) error
func (HTMLLayout) AppendHeader ¶
func (l HTMLLayout) AppendHeader(buf *bytes.Buffer) error
type JSONLayout ¶
type JSONLayout struct {
// contains filtered or unexported fields
}
JSONLayout 输出 JSON 事件。
func NewJSONLayout ¶
func NewJSONLayout(options LayoutOptions) JSONLayout
NewJSONLayout 创建可配置 JSON 布局。
func (JSONLayout) AppendFooter ¶
func (l JSONLayout) AppendFooter(buf *bytes.Buffer) error
func (JSONLayout) AppendHeader ¶
func (l JSONLayout) AppendHeader(buf *bytes.Buffer) error
func (JSONLayout) CloneLayout ¶
func (l JSONLayout) CloneLayout() Layout
CloneLayout 为每个 appender 隔离 Complete 模式的事件计数。
func (JSONLayout) RequiresSynchronizedFormatting ¶
func (l JSONLayout) RequiresSynchronizedFormatting() bool
RequiresSynchronizedFormatting 说明 Complete JSON 流需要按实际写入顺序生成分隔符。
type JSONTemplateLayout ¶
type JSONTemplateLayout struct {
// contains filtered or unexported fields
}
JSONTemplateLayout 按 JSON 事件模板输出日志事件。
func NewJSONTemplateLayout ¶
func NewJSONTemplateLayout( template string, options ...JSONTemplateLayoutOption, ) (*JSONTemplateLayout, error)
func NewJSONTemplateLayoutFromFile ¶
func NewJSONTemplateLayoutFromFile( path string, options ...JSONTemplateLayoutOption, ) (*JSONTemplateLayout, error)
NewJSONTemplateLayoutFromFile 从本地文件编译 JSON 事件模板。
func (*JSONTemplateLayout) AppendFooter ¶
func (l *JSONTemplateLayout) AppendFooter(buf *bytes.Buffer) error
func (*JSONTemplateLayout) AppendHeader ¶
func (l *JSONTemplateLayout) AppendHeader(buf *bytes.Buffer) error
func (*JSONTemplateLayout) CloneLayout ¶
func (l *JSONTemplateLayout) CloneLayout() Layout
CloneLayout 为每个 appender 隔离 Complete 模式的事件计数。
func (*JSONTemplateLayout) Format ¶
func (l *JSONTemplateLayout) Format(buf *bytes.Buffer, event Event) error
func (*JSONTemplateLayout) RequiresSynchronizedFormatting ¶
func (l *JSONTemplateLayout) RequiresSynchronizedFormatting() bool
RequiresSynchronizedFormatting 说明 Complete JSON 模板流需要按实际写入顺序生成分隔符。
type JSONTemplateLayoutOption ¶
type JSONTemplateLayoutOption func(*jsonTemplateLayoutOptions)
JSONTemplateLayoutOption 调整 JSONTemplateLayout 编译行为。
func WithJSONTemplateLayoutOptions ¶
func WithJSONTemplateLayoutOptions(layoutOptions LayoutOptions) JSONTemplateLayoutOption
WithJSONTemplateLayoutOptions 设置 JSON Template 布局的通用输出参数。
func WithJSONTemplateResolverLookup ¶
func WithJSONTemplateResolverLookup(lookup JSONTemplateResolverLookup) JSONTemplateLayoutOption
WithJSONTemplateResolverLookup 设置用于解析自定义 resolver 的查找函数。
type JSONTemplateResolver ¶
JSONTemplateResolver 是 JSON Template 字段值编码器。
type JSONTemplateResolverBuildConfig ¶
type JSONTemplateResolverBuildConfig struct {
Name string
Options map[string]sonic.NoCopyRawMessage
}
JSONTemplateResolverBuildConfig 是 JSON Template resolver 插件的构建输入。
type JSONTemplateResolverFactory ¶
type JSONTemplateResolverFactory func( config JSONTemplateResolverBuildConfig, ) (JSONTemplateResolver, error)
JSONTemplateResolverFactory 从配置构建 JSON Template resolver。
type JSONTemplateResolverLookup ¶
type JSONTemplateResolverLookup func(kind string) (JSONTemplateResolverFactory, bool)
JSONTemplateResolverLookup 按规范化前的名称查找自定义 resolver 工厂。
type Layout ¶
Layout 把日志事件编码为字节。
func CloneLayout ¶
CloneLayout 为 appender 绑定创建隔离布局,避免生命周期状态跨输出流共享。
func NewCharsetLayout ¶ added in v0.0.3
NewCharsetLayout 使用指定字符集编码布局结果,UTF-8 不增加转换层。
type LayoutOptions ¶
type LayoutOptions struct {
// Compact 禁用默认事件换行,适合由上层协议自行分隔事件的场景。
Compact bool
// EventEOL 在 Compact 模式下仍然为每个事件追加换行。
EventEOL bool
// Complete 启用布局页眉和页脚输出,由 appender 在流生命周期内写一次。
Complete bool
// IncludeStacktrace 在支持异常结构的布局中输出完整异常结构。
IncludeStacktrace bool
// StacktraceAsString 将异常栈输出为字符串,便于兼容文本型采集器。
StacktraceAsString bool
// PropertiesAsList 将上下文属性输出为键值列表。
PropertiesAsList bool
// IncludeNullDelimiter 在事件结束后追加 NUL 字节,用于 GELF 等协议分隔。
IncludeNullDelimiter bool
// DisableANSI 禁用 PatternLayout 中 highlight/style 转换器的 ANSI SGR 输出。
DisableANSI bool
// Header 是 Complete 模式下流打开时写入的页眉。
Header string
Footer string
}
LayoutOptions 描述通用结构化布局参数。
type PatternLayout ¶
type PatternLayout struct {
// contains filtered or unexported fields
}
PatternLayout 支持常用日志 pattern 占位符。
func NewPatternLayout ¶
func NewPatternLayout(pattern string) (*PatternLayout, error)
NewPatternLayout 编译 pattern,避免热路径反复解析。
func NewPatternLayoutWithOptions ¶
func NewPatternLayoutWithOptions(pattern string, options LayoutOptions) (*PatternLayout, error)
NewPatternLayoutWithOptions 使用指定布局参数编译 pattern。
type RFC5424Layout ¶
RFC5424Layout 输出 RFC 5424 syslog 单行事件。
type StructuredECSOptions ¶ added in v0.0.3
type StructuredECSOptions struct {
ServiceEnvironment string
ServiceName string
ServiceNodeName string
ServiceVersion string
}
StructuredECSOptions 描述 ECS 服务元数据。
type StructuredFormat ¶ added in v0.0.3
type StructuredFormat string
StructuredFormat 标识受支持的结构化日志协议。
const ( StructuredFormatECS StructuredFormat = "ecs" StructuredFormatGELF StructuredFormat = "gelf" StructuredFormatLogstash StructuredFormat = "logstash" )
type StructuredGELFOptions ¶ added in v0.0.3
StructuredGELFOptions 描述 GELF 主机与服务元数据。
type StructuredJSONCustomizer ¶ added in v0.0.3
type StructuredJSONCustomizer interface {
Customize(event Event, fields StructuredJSONFieldAppender)
}
StructuredJSONCustomizer 以显式 Go API 追加结构化成员。
type StructuredJSONCustomizerFunc ¶ added in v0.0.3
type StructuredJSONCustomizerFunc func(event Event, fields StructuredJSONFieldAppender)
StructuredJSONCustomizerFunc 把函数适配为 StructuredJSONCustomizer。
func (StructuredJSONCustomizerFunc) Customize ¶ added in v0.0.3
func (f StructuredJSONCustomizerFunc) Customize(event Event, fields StructuredJSONFieldAppender)
type StructuredJSONFieldAppender ¶ added in v0.0.3
StructuredJSONFieldAppender 接收自定义结构化成员。
type StructuredJSONLayout ¶ added in v0.0.3
type StructuredJSONLayout struct {
// contains filtered or unexported fields
}
StructuredJSONLayout 输出 Spring Boot 兼容的 ECS、GELF 或 Logstash JSON。
func NewStructuredJSONLayout ¶ added in v0.0.3
func NewStructuredJSONLayout(options StructuredJSONOptions) (*StructuredJSONLayout, error)
NewStructuredJSONLayout 编译结构化日志规则。
type StructuredJSONOptions ¶ added in v0.0.3
type StructuredJSONOptions struct {
Format StructuredFormat
Include []string
Exclude []string
Rename map[string]string
Add map[string]string
IncludeContext bool
ContextPrefix string
Stacktrace StructuredStacktraceOptions
ECS StructuredECSOptions
GELF StructuredGELFOptions
Customizers []StructuredJSONCustomizer
}
StructuredJSONOptions 描述结构化 JSON 的编译参数。
type StructuredStacktraceOptions ¶ added in v0.0.3
type StructuredStacktraceOptions struct {
Printer StructuredStacktracePrinter
RootFirst bool
MaxLength int
MaxThrowableDepth int
IncludeCommonFrames bool
IncludeHashes bool
}
StructuredStacktraceOptions 描述异常链输出规则。
type StructuredStacktracePrinter ¶ added in v0.0.3
type StructuredStacktracePrinter string
StructuredStacktracePrinter 标识结构化日志的异常栈打印策略。
const ( StructuredStacktracePrinterStandard StructuredStacktracePrinter = "standard" StructuredStacktracePrinterLoggingSystem StructuredStacktracePrinter = "logging-system" )
type XMLLayout ¶
type XMLLayout struct {
// contains filtered or unexported fields
}
XMLLayout 输出单事件 XML 片段。
type YAMLLayout ¶
type YAMLLayout struct {
// contains filtered or unexported fields
}
YAMLLayout 输出单事件 YAML 文档。
func NewYAMLLayout ¶
func NewYAMLLayout(options LayoutOptions) YAMLLayout
NewYAMLLayout 创建可配置 YAML 布局。
func (YAMLLayout) AppendFooter ¶
func (l YAMLLayout) AppendFooter(buf *bytes.Buffer) error
func (YAMLLayout) AppendHeader ¶
func (l YAMLLayout) AppendHeader(buf *bytes.Buffer) error
Source Files
¶
- charset.go
- default.go
- json_template.go
- json_template_resolvers.go
- layout.go
- logger_abbreviation.go
- pattern_part1.go
- pattern_part2.go
- pattern_render.go
- structured.go
- structured_json.go
- structured_json_formats.go
- structured_paths.go
- structured_stacktrace.go
- structured_writer.go
- structured_xml.go
- structured_yaml.go
- text_table.go