Documentation
¶
Index ¶
Constants ¶
const ( AnsiReset = "\033[0m" AnsiRed = "\033[38;5;9m" AnsiGrey = "\033[38;5;244m" AnsiGreen = "\033[38;5;2m" AnsiYellow = "\033[38;5;11m" AnsiBlue = "\033[38;5;6m" AnsiMagenta = "\033[38;5;13m" AnsiCyan = "\033[38;5;14m" AnsiWhite = "\033[37m" AnsiBlueBold = "\033[34;1m" AnsiMagentaBold = "\033[35;1m" AnsiRedBold = "\033[31;1m" AnsiYellowBold = "\033[33;1m" AnsiNotImportant = AnsiGrey )
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶
FromContext returns data stored in the given context.Context.
See NewContext to create a context.Context.
func NewContext ¶
NewContext returns a new context.Context with the callerSkip given.
callerSkip is the number of runtime calls to log before this one. 0 is for the current. 1 is for the precedent call. n is for the n times precedent call. The calls to the log is already skipped.
stackTrace and marshalJSON overrides [Options.MarshalJSON] and [Options.PrintStackTrace] for the current call.
See FromContext to extract the caller from a context.Context.
Types ¶
type ColorHandler ¶ added in v0.2.0
type ColorHandler struct {
// contains filtered or unexported fields
}
ColorHandler is the previous default Handler of Logos. It produces a colorful output to an io.Writer.
type Handler ¶ added in v0.2.0
type Handler interface {
Write(opts Options, level slog.Level, time, file, content, arg string, stack []byte)
}
Handler writes the content of Logos.
type Logos ¶
type Logos struct {
// contains filtered or unexported fields
}
Logos represents the slog.Handler.
See New to create a new Logos with the given Options.
func NewColor ¶ added in v0.2.0
NewColor creates a new Logos with ColorHandler.
func NewSyslog ¶ added in v0.2.0
NewSyslog creates a new Logos with SyslogHandler.
func (*Logos) Enabled ¶
Enabled indicates if the given slog.Level is enabled.
func (*Logos) Handle ¶
Handle a slog.Record.
type Options ¶
type Options struct {
// Level reports the minimum level to log.
// Levels with lower levels are discarded.
// If nil, the Handler uses [slog.LevelInfo].
Level slog.Leveler
// MaxFileLineLength is the maximum length of the caller part.
// Default value is 25.
MaxFileLineLength int
// If Align, everything logged will be aligned dynamically.
Align bool
// If ArgsAreImportant, args are in default terminal color.
// If not, they are in [AnsiNotImportant] (default).
ArgsAreImportant bool
// If TrimVersion, package versions are removed from the caller part.
TrimVersion bool
// If DisableColor, removes every color from logging
DisableColor bool
// If PrintStackTrace, error log always contains a stack trace
PrintStackTrace bool
// If MarshalJSON, types implementing [json.Marshaler] will be marshaled into JSON.
MarshalJSON bool
}
Options of Logos.
type SyslogHandler ¶ added in v0.2.0
type SyslogHandler struct {
// contains filtered or unexported fields
}