logger

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logger provides a simple logging framework that supports different log levels (DEBUG, INFO, WARN, ERROR, ALWAYS, SILENT) and color-coded output.

Index

Constants

This section is empty.

Variables

This section is empty.

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 represents no logging, effectively muting all log messages.
	SILENT Level = iota - 1
	// DEBUG represents debug-level messages, useful for development and troubleshooting.
	DEBUG
	// INFO represents informational messages, typically used for normal operation.
	INFO
	// WARN represents warning messages, which indicate potential issues but not failures.
	WARN
	// ERROR represents error messages, indicating failure in operation.
	ERROR
	// ALWAYS represents messages that should always be logged, regardless of the 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

New creates a new Logger instance with the specified log level and writes to stdout. If an invalid log level is provided, it defaults to INFO.

func NewCustom

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

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(format string, args ...any)

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

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...any)

Debug logs a debug-level message if the current log level allows it.

func (*Logger) Error

func (l *Logger) Error(format string, args ...any)

Error logs an error message if the current log level allows it.

func (*Logger) Info

func (l *Logger) Info(format string, args ...any)

Info logs an informational message if the current log level allows it.

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...any)

Warn logs a warning message if the current log level allows it.

Jump to

Keyboard shortcuts

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