log

package module
v0.0.0-...-3cf86ab Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 6 Imported by: 1

README

go-log

Notice: This package is deprecated and no longer maintained. Instead go-utils logging package should be used, which adds helper functions to log/slog.

A simple logging library in Go which supports log levels.

It is implemented as a wrapper around the standard library's log package.

Documentation

Overview

Package log is a simple wrapper around the standard library's log package and mainly adds log level support.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidLevel = errors.New("cannot parse log-level from string")

ErrInvalidLevel is returned when no valid logging level can be parsed by SetLevelFromString.

Functions

This section is empty.

Types

type Level

type Level int

Level is the logging level.

const (
	// Error logging level
	Error Level = iota
	// Warning logging level
	Warning
	// Info logging level
	Info
	// Debug logging level
	Debug
)

func ParseLevelFromString

func ParseLevelFromString(level string) (Level, error)

ParseLevelFromString parses the level from a string and returns it. If it cannot parse a legitimate level from the level string, it will return ErrInvalidLevel.

type Logger

type Logger struct {
	*log.Logger
	// contains filtered or unexported fields
}

Logger contains the current logging level and the standard library's logger.

func New

func New(out io.Writer, level Level) *Logger

New creates a new logger. The out variable sets the log destination and level sets the logging level.

func NewDefaultLogger

func NewDefaultLogger() *Logger

NewDefaultLogger creates a new logger with the default settings. The logging level is Info and it logs to standard error.

func (*Logger) Debug

func (l *Logger) Debug(v ...interface{})

Debug prints to the logger when the logging level is at least Debug. Arguments are handled in the manner of fmt.Print.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

Debugf prints to the logger when the logging level is at least Debug. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Error

func (l *Logger) Error(v ...interface{})

Error prints to the logger when the logging level is at least Error. Arguments are handled in the manner of fmt.Print.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

Errorf prints to the logger when the logging level is at least Error. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Fatal

func (l *Logger) Fatal(v ...interface{})

Fatal prints to the logger and calls os.Exit(1). Arguments are handled in the manner of fmt.Print.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf prints to the logger and calls os.Exit(1). Arguments are handled in the manner of fmt.Printf.

func (*Logger) Info

func (l *Logger) Info(v ...interface{})

Info prints to the logger when the logging level is at least Info. Arguments are handled in the manner of fmt.Print.

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

Infof prints to the logger when the logging level is at least Info. Arguments are handled in the manner of fmt.Printf.

func (*Logger) Level

func (l *Logger) Level() Level

Level returns the current logging level of a logger.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel sets the logging level of a logger.

func (*Logger) SetLevelFromString

func (l *Logger) SetLevelFromString(level string) error

SetLevelFromString parses the level from a string and sets the logging level. If it cannot parse a legitimate level from the level string, it will return ErrInvalidLevel.

func (*Logger) Warning

func (l *Logger) Warning(v ...interface{})

Warning prints to the logger when the logging level is at least Warning. Arguments are handled in the manner of fmt.Print.

func (*Logger) Warningf

func (l *Logger) Warningf(format string, v ...interface{})

Warningf prints to the logger when the logging level is at least Warning. Arguments are handled in the manner of fmt.Printf.

Jump to

Keyboard shortcuts

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