logawl

package
v0.6.12 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package logawl is a package for custom logging needs

LogAwl extends the standard log library with support for log levels This is _different_ from the syslog package in the standard library because you do not define a file because awl is a cli utility it writes directly to std err.

Use the New() function to init logawl

logger := logawl.New()

You can call specific logging levels from your new logger using

logger.Debug("Message to log")
logger.Warning("Message to log")
logger.Info("Message to log")
logger.Error("Message to log")

You may also set the log level on the fly with

Logger.SetLevel(3)

This allows you to change the default level (Info) and prevent log messages from being posted at higher verbosity levels for example if

Logger.SetLevel(3)

is not called and you call

Logger.Debug()

this runs through

IsLevel(level)

to verify if the debug log should be sent to std.Err or not based on the current expected log level

Index

Constants

This section is empty.

Variables

AllLevels is an array of all valid log levels.

Functions

This section is empty.

Types

type Level

type Level int32

Level is the logging level.

const (
	// ErrLevel is the fatal (error) log level.
	ErrLevel Level = iota

	// WarnLevel is for warning logs.
	//
	// Example: when one setting implies another, when a request fails but is retried.
	WarnLevel

	// InfoLevel is for saying what is going on when.
	// This is essentially the "verbose" option.
	//
	// When in doubt, use info.
	InfoLevel

	// DebugLevel is for spewing debug structs/interfaces.
	DebugLevel
)

type Logger

type Logger struct {
	Out    io.Writer
	Prefix string

	Mu    sync.Mutex
	Level Level
	// contains filtered or unexported fields
}

Logger is the overall logger.

func New

func New() *Logger

New instantiates Logger

Level can be changed to one of the other log levels (ErrorLevel, WarnLevel, InfoLevel, DebugLevel).

func (*Logger) Debug

func (logger *Logger) Debug(in ...any)

Debug calls print directly with Debug level.

func (*Logger) Debugf

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

Debugf calls print after formatting the string with Debug level.

func (*Logger) Error

func (logger *Logger) Error(in ...any)

Error calls print directly with Error level.

func (*Logger) Errorf

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

Errorf calls print after formatting the string with Error level.

func (*Logger) FormatHeader

func (logger *Logger) FormatHeader(buf *[]byte, t time.Time, line int, level Level) error

FormatHeader formats the log header as such <LogLevel> YYYY/MM/DD HH:MM:SS (local time) <the message to log>.

func (*Logger) GetLevel

func (logger *Logger) GetLevel() Level

GetLevel gets the logger level.

func (*Logger) Info

func (logger *Logger) Info(in ...any)

Info calls print directly with Info level.

func (*Logger) Infof

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

Infof calls print after formatting the string with Info level.

func (*Logger) IsLevel

func (logger *Logger) IsLevel(level Level) bool

IsLevel returns true if the logger level is above the level given.

func (*Logger) Printer

func (logger *Logger) Printer(level Level, s string) error

Printer prints the formatted message directly to stdErr.

func (*Logger) Println

func (logger *Logger) Println(level Level, in ...any)

Println takes any and prints it out to Logger -> Out (io.Writer (default is std.Err)).

func (*Logger) SetLevel

func (logger *Logger) SetLevel(level Level)

SetLevel stores whatever input value is in mem address of l.level.

func (*Logger) UnMarshalLevel

func (logger *Logger) UnMarshalLevel(lv Level) (string, error)

UnMarshalLevel unmarshalls the int value of level for writing the header.

func (*Logger) Warn

func (logger *Logger) Warn(in ...any)

Warn calls print directly with Warn level.

func (*Logger) Warnf

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

Warnf calls print after formatting the string with Warn level.

Jump to

Keyboard shortcuts

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