Documentation ¶
Overview ¶
Package basic provides a basic text/terminal log entry handler for slog. It allows to define the format of the output string (via Go templates), the format of date and time, the colouring of entries in case of terminal output as well as the writer to redirect the output to. The handler synchronises on write to allow the same handler to be used from concurrent routines.
Index ¶
Constants ¶
const ( // StandardTermTemplate represents a standard template for terminal output (default). StandardTermTemplate = "" /* 174-byte string literal not displayed */ // StandardTextTemplate represents a standard template for text file output or any other writers // not supporting terminal colouring. StandardTextTemplate = "" /* 136-byte string literal not displayed */ // StandardTimeFormat represents the time format used in the handler by default. StandardTimeFormat = "15:04:05.000" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct { Time string Level string Context string Message string Error error Caller string Fields string Color int }
Data supplies log data to the template formatter for outputting into the log string. This structure defines all the fields that can be used in the template.
type Handler ¶
Handler represents a log entry handler capable of formatting structured log data into a text format (text files, stderr with or without colouring etc).
func New ¶
func New() *Handler
New constructs a new handler with default template, time formatting, colours and stderr as output.
func (*Handler) Handle ¶
Handle outputs a textual representation of the log entry into a text writer (stderr, file etc.).
func (*Handler) SetColors ¶
SetColors overwrites the level-colour mapping. Every missing mapping will be replaced by gray.
func (*Handler) SetTemplate ¶
SetTemplate defines the formatting of the log string using the standard Go template syntax. See the Data structure for the definition of all supported template fields.
func (*Handler) SetTimeFormat ¶
SetTimeFormat defines the formatting of time used for output into the template.