Documentation
¶
Index ¶
- type Formatter
- func ErrorFormatter(fieldName string) Formatter
- func Format[T any](formatter func([]string, string, slog.Value) slog.Value) Formatter
- func FormatByFieldType[T any](key string, formatter func(T) slog.Value) Formatter
- func FormatByGroup(targetGroup []string, formatter func([]slog.Attr) slog.Value) Formatter
- func FormatByGroupKey(targetGroup []string, key string, formatter func(slog.Value) slog.Value) Formatter
- func FormatByGroupKeyType[T any](targetGroup []string, key string, formatter func(T) slog.Value) Formatter
- func FormatByKey(key string, formatter func(slog.Value) slog.Value) Formatter
- func FormatByKind(kind slog.Kind, formatter func(slog.Value) slog.Value) Formatter
- func FormatByType[T any](formatter func(T) slog.Value) Formatter
- func HTTPRequestFormatter(ignoreHeaders bool) Formatter
- func HTTPResponseFormatter(ignoreHeaders bool) Formatter
- func IPAddressFormatter(key string) Formatter
- func PIIFormatter(key string) Formatter
- func TimeFormatter(timeFormat string, location *time.Location) Formatter
- func TimezoneConverter(location *time.Location) Formatter
- func UnixTimestampFormatter(precision time.Duration) Formatter
- type FormatterAdapter
- type LogValuerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Formatter ¶
func ErrorFormatter ¶
ErrorFormatter transforms a go error into a readable error.
Example:
err := reader.Close()
err = fmt.Errorf("could not close reader: %v", err)
logger.With("error", reader.Close()).Log("error")
passed to ErrorFormatter("error"), will be transformed into:
"error": {
"message": "could not close reader: file already closed",
"type": "*io.ErrClosedPipe"
}
func FormatByFieldType ¶
FormatByFieldType pass attributes matching both key and generic type into a formatter.
func FormatByGroup ¶
FormatByGroup pass attributes under a group into a formatter.
func FormatByGroupKey ¶
func FormatByGroupKey(targetGroup []string, key string, formatter func(slog.Value) slog.Value) Formatter
FormatByGroupKey pass attributes under a group and matching key, into a formatter.
func FormatByGroupKeyType ¶
func FormatByGroupKeyType[T any](targetGroup []string, key string, formatter func(T) slog.Value) Formatter
FormatByGroupKeyType pass attributes under a group, matching key and matching a generic type, into a formatter.
func FormatByKey ¶
FormatByKey pass attributes matching key into a formatter.
func FormatByKind ¶
FormatByKind pass attributes matching `slog.Kind` into a formatter.
func FormatByType ¶
FormatByType pass attributes matching generic type into a formatter.
func HTTPRequestFormatter ¶
HTTPRequestFormatter transforms a *http.Request into a readable object.
func HTTPResponseFormatter ¶
HTTPResponseFormatter transforms a *http.Response into a readable object.
func IPAddressFormatter ¶
IPAddressFormatter transforms an IP address into "********".
Example:
"context": {
"ip_address": "bd57ffbd-8858-4cc4-a93b-426cef16de61"
}
passed to IPAddressFormatter("ip_address"), will be transformed into:
"context": {
"ip_address": "********",
}
func PIIFormatter ¶
PIIFormatter transforms any value under provided key into "********". IDs are kept as is.
Example:
"user": {
"id": "bd57ffbd-8858-4cc4-a93b-426cef16de61",
"email": "foobar@example.com",
"address": {
"street": "1st street",
"city": "New York",
"country": USA",
"zip": 123456
}
}
passed to PIIFormatter("user"), will be transformed into:
"user": {
"id": "bd57ffbd-8858-4cc4-a93b-426cef16de61",
"email": "foob********",
"address": {
"street": "1st *******",
"city": "New *******",
"country": "*******",
"zip": "*******"
}
}
func TimeFormatter ¶
TimeFormatter transforms a `time.Time` into a readable string.
func TimezoneConverter ¶
TimezoneConverter set a `time.Time` to a different timezone.
func UnixTimestampFormatter ¶
UnixTimestampFormatter transforms a `time.Time` into a unix timestamp.
type FormatterAdapter ¶
type FormatterAdapter struct {
*modules.BaseModule
// contains filtered or unexported fields
}
FormatterAdapter 格式化器模块适配器
func NewFormatterAdapter ¶
func NewFormatterAdapter() *FormatterAdapter
NewFormatterAdapter 创建格式化器适配器
func (*FormatterAdapter) Configure ¶
func (f *FormatterAdapter) Configure(config modules.Config) error
Configure 配置格式化器模块
func (*FormatterAdapter) FormatterFunctions ¶ added in v0.1.2
FormatterFunctions 实现 modules.FormatterProvider,避免反射与 interface{} 转换。
func (*FormatterAdapter) GetFormatters ¶
func (f *FormatterAdapter) GetFormatters() interface{}
GetFormatters 获取格式化器列表(返回兼容的函数类型)