logger

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logger provides a simple logging framework that supports log levels.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidLogLevel = errors.New("invalid log level")

ErrInvalidLogLevel is returned when an invalid log level is provided.

Functions

func LevelStrings added in v0.0.1

func LevelStrings() []string

LevelStrings returns a slice of all String values of the enum

Types

type Level

type Level int

Level represents the severity of a log message. It can be one of DEBUG, INFO, WARN, ERROR, ALWAYS, or SILENT.

const (
	// SILENT indicates no logging output.
	SILENT Level = iota - 1
	// DEBUG indicates detailed debug information.
	DEBUG
	// INFO indicates normal operational messages.
	INFO
	// WARN indicates potentially harmful situations.
	WARN
	// ERROR indicates error events.
	ERROR
	// ALWAYS indicates messages always shown regardless of current log level.
	ALWAYS
)

func LevelString added in v0.0.1

func LevelString(s string) (Level, error)

LevelString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func LevelValues added in v0.0.1

func LevelValues() []Level

LevelValues returns all values of the enum

func (Level) IsALevel added in v0.0.1

func (i Level) IsALevel() bool

IsALevel returns "true" if the value is listed in the enum definition. "false" otherwise

func (Level) String added in v0.0.1

func (i Level) String() string

type Logger

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

Logger holds the configuration for logging. It includes the current logging level, the output writer, and color mappings for each log level.

func New

func New(level Level) (*Logger, error)

New creates a new Logger instance with the specified log level and writes to stdout.

func NewCustom

func NewCustom(level Level, output io.Writer) (*Logger, error)

NewCustom creates a new Logger instance with the specified log level and output writer. If an invalid log level is provided, it defaults to INFO.

func (*Logger) Always

func (l *Logger) Always(msg string)

Always logs a message at the ALWAYS level, regardless of the current log level.

func (*Logger) Alwaysf added in v0.0.13

func (l *Logger) Alwaysf(f string, a ...any)

Alwaysf logs a formatted message at the ALWAYS level.

func (*Logger) Debug

func (l *Logger) Debug(msg string)

Debug logs a message at the DEBUG level, if enabled.

func (*Logger) Debugf added in v0.0.13

func (l *Logger) Debugf(f string, a ...any)

Debugf logs a formatted message at the DEBUG level.

func (*Logger) Error

func (l *Logger) Error(msg string)

Error logs a message at the ERROR level, if enabled.

func (*Logger) Errorf added in v0.0.13

func (l *Logger) Errorf(f string, a ...any)

Errorf logs a formatted message at the ERROR level.

func (*Logger) Info

func (l *Logger) Info(msg string)

Info logs a message at the INFO level, if enabled.

func (*Logger) Infof added in v0.0.13

func (l *Logger) Infof(f string, a ...any)

Infof logs a formatted message at the INFO level.

func (*Logger) Level added in v0.0.13

func (l *Logger) Level() Level

Level returns the current log level.

func (*Logger) SetLevel added in v0.0.13

func (l *Logger) SetLevel(level Level)

SetLevel updates the logger's level at runtime.

func (*Logger) Warn

func (l *Logger) Warn(msg string)

Warn logs a message at the WARN level, if enabled.

func (*Logger) Warnf added in v0.0.13

func (l *Logger) Warnf(f string, a ...any)

Warnf logs a formatted message at the WARN level.

Jump to

Keyboard shortcuts

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