Documentation ¶
Index ¶
- Constants
- type AttrHook
- type AttrPrinter
- type ColorMap
- type HandleAttr
- type Handler
- type Log
- type Option
- func WithAttrHook(hook AttrHook) Option
- func WithColor(color bool) Option
- func WithColorMap(colors *ColorMap) Option
- func WithLevel(level slog.Leveler) Option
- func WithPrinter(printer func(io.Writer, *config) AttrPrinter) Option
- func WithReplaceAttr(replaceAttr func(groups []string, a slog.Attr) slog.Attr) Option
- func WithSource(addSource bool) Option
- func WithTemplate(tmpl *template.Template) Option
- func WithTimeFmt(timeFmt string) Option
- func WithWriter(w io.Writer) Option
Constants ¶
const ( TemplateStandardWithElapsed = `{{.Elapsed | printf "%8.3f" }} {{.Level}} {{ if .FileName }}[{{.FileName}}:{{.FileLine}}] {{ end }}{{.Message}} ` TemplateStandardWithTime = `{{.Timestamp}} {{.Level}} {{ if .FileName }}[{{.FileName}}:{{.FileLine}}] {{ end }}{{.Message}} ` TemplateStandard = `{{.Level}} {{ if .FileName }}[{{.FileName}}:{{.FileLine}}] {{ end }}{{.Message}} ` DefaultTemplate = TemplateStandardWithTime )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttrHook ¶ added in v0.0.5
type AttrHook func(groups []string, attr slog.Attr) *HandleAttr
AttrHook is a function that hooks attribute printing. When the function returns nil, the attribute is printed as usual. When the function returns a non-nil value, the attribute is handled according to the content of HandleAttr.
type AttrPrinter ¶
func IndentPrinter ¶
func IndentPrinter(w io.Writer, cfg *config) AttrPrinter
IndentPrinter is a printer that prints attributes in a indented format.
func LinearPrinter ¶
func LinearPrinter(w io.Writer, cfg *config) AttrPrinter
LinearPrinter is a printer that prints attributes in a linear format.
func PrettyPrinter ¶
func PrettyPrinter(w io.Writer, cfg *config) AttrPrinter
PrettyPrinter is a printer that prints attributes in a pretty format.
type HandleAttr ¶ added in v0.0.5
type HandleAttr struct { // NewAttr is a new attribute that replaces the original attribute. When this field is not nil, the original attribute is printed. NewAttr *slog.Attr // Defer is a function that is called after the all attributes are printed. Defer func(w io.Writer) }
HandleAttr is a struct that describes how to handle an attribute. NOTE: This feature is experimental and may be changed in the future. NOTE: This feature is available only in the LinearPrinter for now.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a slog handler that writes logs to an io.Writer.
type Log ¶
type Log struct { // Timestamp is a time when the log is recorded. Format can be specified by WithTimeFmt. Timestamp string // Elapsed is duration from the start of the program. Elapsed float64 // Level is a log level. It is one of "DEBUG", "INFO", "WARN", "ERROR", "FATAL". Level string // Message is a log message. Message string // FileName is a file name of the source code that calls logger. It is empty if WithSource is not specified. FileName string // FilePath is a full file path of the source code that calls logger. It is empty if WithSource is not specified. FilePath string // FileLine is a line number of the source code that calls logger. It is empty if WithSource is not specified. FileLine int // FuncName is a function name of the source code that calls logger. It is empty if WithSource is not specified. FuncName string // contains filtered or unexported fields }
type Option ¶
type Option func(*config)
func WithAttrHook ¶ added in v0.0.5
WithAttrHook adds an attribute hook to the handler. This option can be used with only LinearPrinter.
func WithColorMap ¶
WithColorMap sets the color set for the handler.
func WithPrinter ¶
func WithPrinter(printer func(io.Writer, *config) AttrPrinter) Option
WithPrinter sets the printer for printing attributes. The default is LinearPrinter.
func WithReplaceAttr ¶
WithReplaceAttr sets the function for replacing attributes. The default is nil.
func WithSource ¶
WithSource enables or disables adding the source attribute. The default is disable.
func WithTemplate ¶
WithTemplate sets the template for the handler. The default is DefaultTemplate. This option executes dry run and panics if the template is invalid.
func WithTimeFmt ¶
WithTimeFmt sets the time format for the time attribute. The default is "2006-01-02 15:04:05".
func WithWriter ¶
WithWriter sets the writer for the handler. The default is os.Stdout.