Documentation ¶
Overview ¶
Package fblog provides slog handler and its options to print logs in the fblog-like style.
Index ¶
- Constants
- type Handler
- type Option
- func Err(w io.Writer) Option
- func Out(w io.Writer) Option
- func WithLevel(lvl slog.Level) Option
- func WithLogTimeFormat(f string) Option
- func WithMaxKeySize(s int) Option
- func WithReplaceAttrs(r func([]string, slog.Attr) slog.Attr) Option
- func WithSource(srcFormat SourceFormat) Option
- func WithTimeFormat(f string) Option
- type SourceFormat
Constants ¶
const ( // SourceFormatNone is the source format without any source. SourceFormatNone = 0 // SourceFormatPos is the short source format, // e.g. "file:line". SourceFormatPos = 1 // SourceFormatFunc is the short source format, // e.g. "func". SourceFormatFunc = 2 // SourceFormatLong is the long source format, // e.g. "full/file/path:line:func". SourceFormatLong = 3 )
const ( // HeaderKeySize looks for the header size of the log entry and // trims all the attribute keys to fit the header size. HeaderKeySize = 0 // UnlimitedKeySize seeks for a maximum key size of the log entry // and formats the timestamp and level accordingly. UnlimitedKeySize = -1 )
Predefined key size options.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a handler that prints logs in the fblog-like style, i.e. a new line for each attribute.
func NewHandler ¶
NewHandler returns a new Handler. The format of the logs entries will be:
<Timestamp> <Level>: <Message> <Attr1>: <Value1> <Group1>.<Attr2>: <Value2> ...
type Option ¶
type Option func(*Handler)
Option is an option for a Handler.
func WithLogTimeFormat ¶
WithLogTimeFormat returns an Option that sets the log's individual time format of the handler.
func WithMaxKeySize ¶
WithMaxKeySize returns an Option that sets the maximum key size of the handler. By default, the maximum key size is the "timestamp + level" size, if the key is bigger than that it will be trimmed from the left and "..." will be added at the beginning. Minimum length of the key is 7 (length of the level with braces) and any value that falls out of special cases will be set to UnlimitedKeySize.
func WithReplaceAttrs ¶
WithReplaceAttrs returns an Option that sets the function that will replace the attributes.
func WithSource ¶
func WithSource(srcFormat SourceFormat) Option
WithSource returns an Option that sets the source of the handler.
func WithTimeFormat ¶
WithTimeFormat returns an Option that sets the time format of the handler.