logger

package
v0.0.0-...-44afebf Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogEntry

type LogEntry struct {
	Indent     int
	Group      string
	Message    string
	IndentText string
	ShowGroups bool
}

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is a tool for optionally logging messages.

func New

func New() *Logger

New creates a new logger that writes to the standard out.

func NewFunc

func NewFunc(handle func(entry LogEntry)) *Logger

NewFunc will create a logger that calls the given function to handle logging a message.

func NewWriter

func NewWriter(out io.Writer) *Logger

NewWriter creates a logger that writes logs to the given writer.

If the writer returns an error on any log, that error will be panicked from the call to create the log.

func Null

func Null() *Logger

Null is a nil logger that is always disabled. This can be used to prevent logging.

func (*Logger) Disabled

func (log *Logger) Disabled() bool

Disabled indicates that the current group is disabled.

func (*Logger) Group

func (log *Logger) Group(name string) *Logger

Group indicates that all the logs to the returned logger will be part of this group until another group is called. Only shown groups will be logged. If the group is an empty name, then it is shown.

func (*Logger) Hide

func (log *Logger) Hide(groups ...string) *Logger

Hide indicates which groups will not be logged. The receiver is not modified, the returned logger will have the still shown groups in it. This will update if the Logger is disabled or not.

func (*Logger) Indent

func (log *Logger) Indent() *Logger

Indent will add to the current indent for the message. The returned logger will be further indented. If the logger is disabled, this will have no effect.

func (*Logger) IndentWith

func (log *Logger) IndentWith(indent string) *Logger

IndentWith will add to the current indent for the message with the given text to add at the rightmost part of the indent. The returned logger will be further indented. If the logger is disabled, this will have no effect.

func (*Logger) Log

func (log *Logger) Log(args ...any) *Logger

Log will write a log if this logger is enabled based on visible groups.

func (*Logger) Logf

func (log *Logger) Logf(format string, args ...any) *Logger

Logf will write a log if this logger is enabled based on visible groups.

func (*Logger) Show

func (log *Logger) Show(groups ...string) *Logger

Show indicates which groups will be logged. The receiver is not modified, the returned logger will have the shown groups in it. This will update if the Logger is disabled or not.

Jump to

Keyboard shortcuts

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