logr

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 5 Imported by: 14

README

logr

Go logging library with levels.

Usage

go get -u github.com/TwiN/logr
import "github.com/TwiN/logr"

func main() {
    logr.Debug("This is a debug message")
    logr.Infof("This is an %s message", "info")
    logr.Warn("This is a warn message")
    logr.Error("This is an error message")
    logr.Fatal("This is a fatal message") // Exits with code 1
}

You can set the default logger's threshold like so:

logr.SetThreshold(logr.LevelWarn)

The above would make it so only WARN, ERROR and FATAL messages are logged, while DEBUG and INFO messages are ignored.

TODO: Finish documentation

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLevelString = errors.New("invalid level, must be one of DEBUG, INFO, WARN, ERROR or FATAL")
)

Functions

func Debug

func Debug(message string)

func Debugf

func Debugf(format string, args ...any)

func Error

func Error(message string)

func Errorf

func Errorf(format string, args ...any)

func Fatal added in v0.3.1

func Fatal(message string)

func Fatalf added in v0.3.1

func Fatalf(format string, args ...any)

func Info

func Info(message string)

func Infof

func Infof(format string, args ...any)

func Log

func Log(level Level, message string)

func Logf

func Logf(level Level, message string, args ...any)

func SetOutput

func SetOutput(output io.Writer)

SetOutput sets the output of the default logger

func SetThreshold

func SetThreshold(threshold Level)

SetThreshold sets the minimum level output by the default logger

func Warn

func Warn(message string)

func Warnf

func Warnf(format string, args ...any)

Types

type Level

type Level string
const (
	LevelDebug Level = "DEBUG"
	LevelInfo  Level = "INFO"
	LevelWarn  Level = "WARN"
	LevelError Level = "ERROR"
	LevelFatal Level = "FATAL"
)

func GetThreshold added in v0.0.2

func GetThreshold() Level

func LevelFromString added in v0.1.0

func LevelFromString(level string) (Level, error)

func (Level) IsValid added in v0.2.1

func (level Level) IsValid() bool

func (Level) Value added in v0.2.0

func (level Level) Value() int

type Logger

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

func New

func New(threshold Level, shouldPrefixMessageWithLevel bool, output io.Writer) *Logger

New creates a new logger with the given threshold and output.

func (*Logger) Debug

func (logger *Logger) Debug(message string)

func (*Logger) Debugf

func (logger *Logger) Debugf(format string, args ...any)

func (*Logger) Error

func (logger *Logger) Error(message string)

func (*Logger) Errorf

func (logger *Logger) Errorf(format string, args ...any)

func (*Logger) Fatal added in v0.3.0

func (logger *Logger) Fatal(message string)

func (*Logger) Fatalf added in v0.3.0

func (logger *Logger) Fatalf(format string, args ...any)

func (*Logger) GetThreshold added in v0.0.2

func (logger *Logger) GetThreshold() Level

func (*Logger) Info

func (logger *Logger) Info(message string)

func (*Logger) Infof

func (logger *Logger) Infof(format string, args ...any)

func (*Logger) Log

func (logger *Logger) Log(level Level, message string)

func (*Logger) Logf

func (logger *Logger) Logf(level Level, format string, args ...any)

func (*Logger) SetOutput

func (logger *Logger) SetOutput(output io.Writer)

func (*Logger) SetThreshold

func (logger *Logger) SetThreshold(threshold Level)

func (*Logger) Warn

func (logger *Logger) Warn(message string)

func (*Logger) Warnf

func (logger *Logger) Warnf(format string, args ...any)

Jump to

Keyboard shortcuts

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