logos

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

README

Logos

Logos is a colorful Go log/slog.Logger.

go get -u github.com/nyttikord/logos

Create a new logger to stdout:

log := logos.New(io.Stdout, nil)

Documentation

Index

Constants

View Source
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

func FromContext(ctx context.Context) (caller int, stackTrace, marshalJSON, ok bool)

FromContext returns data stored in the given context.Context.

See NewContext to create a context.Context.

func NewContext

func NewContext(ctx context.Context, callerSkip int, stackTrace, marshalJSON bool) context.Context

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.

func (ColorHandler) Write added in v0.2.0

func (c ColorHandler) Write(opts Options, level slog.Level, time, file, content, arg string, stack []byte)

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 New

func New(h Handler, opts *Options) *Logos

New creates a new Logos with Handler.

See NewColor. See NewSyslog.

func NewColor added in v0.2.0

func NewColor(out io.Writer, opts *Options) *Logos

NewColor creates a new Logos with ColorHandler.

See New. See NewSyslog.

func NewSyslog added in v0.2.0

func NewSyslog(tag string, facility syslog.Priority, opts *Options) (*Logos, error)

NewSyslog creates a new Logos with SyslogHandler.

See New. See NewColor.

func (*Logos) Enabled

func (l *Logos) Enabled(ctx context.Context, level slog.Level) bool

Enabled indicates if the given slog.Level is enabled.

func (*Logos) Handle

func (l *Logos) Handle(ctx context.Context, r slog.Record) error

Handle a slog.Record.

func (*Logos) WithAttrs

func (l *Logos) WithAttrs(attrs []slog.Attr) slog.Handler

func (*Logos) WithGroup

func (l *Logos) WithGroup(name string) slog.Handler

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
}

func (SyslogHandler) Write added in v0.2.0

func (s SyslogHandler) Write(opts Options, level slog.Level, time, file, content, arg string, stack []byte)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL