Documentation ¶
Index ¶
- Constants
- type AttrPrinter
- type ColorMap
- type Handler
- type Log
- type 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 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 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 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.