logger

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: GPL-3.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

View Source
const (
	LOG_SUFFIX    = "\n\n"
	LOG_PERMS     = 0644 // rw-r--r--
	LOG_THRESHOLD = 15 * 24 * time.Hour
)
View Source
const (
	// Log levels
	TRACE = iota
	DEBUG
	INFO
	WARNING
	ERROR
	FATAL
)

Variables

This section is empty.

Functions

func DeleteEmptyAndOldLogs

func DeleteEmptyAndOldLogs() error

Delete all empty log files and log files older than the log threshold except for the current day's log file.

func DeleteLogsOnCond added in v1.1.2

func DeleteLogsOnCond(condToSkip func(os.FileInfo) bool) error

func LogChanErrors

func LogChanErrors(level int, errChan chan error) (bool, []error)

Uses the thread-safe LogError() function to log a channel of errors

Also returns if any errors were due to context.Canceled which is caused by Ctrl + C.

func LogError

func LogError(err error, level int)

Thread-safe logging function that logs to "cultured_downloader.log" in the logs directory

func LogErrors

func LogErrors(level int, errs ...error) bool

Uses the thread-safe LogError() function to log multiple errors

Also returns if any errors were due to context.Canceled which is caused by Ctrl + C.

func LogMessageToPath

func LogMessageToPath(message, filePath string, level int)

Thread-safe logging function that logs to the provided file path

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}
var (
	MainLogger Logger
)

func NewLogger

func NewLogger(out io.Writer) Logger

func (Logger) Debug

func (l Logger) Debug(message string)

func (Logger) Debugf

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

func (Logger) Error

func (l Logger) Error(message string)

func (Logger) Errorf

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

func (Logger) Fatal added in v1.1.0

func (l Logger) Fatal(message string)

func (Logger) Fatalf added in v1.1.0

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

func (Logger) Info

func (l Logger) Info(message string)

func (Logger) Infof

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

func (Logger) LogBasedOnLvl

func (l Logger) LogBasedOnLvl(lvl int, msg string)

LogBasedOnLvl is a wrapper for LogBasedOnLvlf() that takes a string instead of a format string

However, please ensure that the lvl passed in is valid (i.e. INFO, ERROR, or DEBUG), otherwise this function will panic

func (Logger) LogBasedOnLvlf

func (l Logger) LogBasedOnLvlf(lvl int, format string, args ...any)

LogBasedOnLvlf logs a message based on the log level passed in

You can use this function to log a message with a format string

However, please ensure that the lvl passed in is valid (i.e. TRACE, DEBUG, etc.), otherwise this function will panic

func (Logger) Print added in v1.1.0

func (l Logger) Print(message string)

func (Logger) Printf added in v1.1.0

func (l Logger) Printf(format string, args ...any)

func (Logger) SetOutput

func (l Logger) SetOutput(w io.Writer)

func (Logger) Trace added in v1.1.0

func (l Logger) Trace(message string)

func (Logger) Tracef added in v1.1.0

func (l Logger) Tracef(format string, args ...any)

func (Logger) Warning added in v1.1.0

func (l Logger) Warning(message string)

func (Logger) Warningf added in v1.1.0

func (l Logger) Warningf(format string, args ...any)

Jump to

Keyboard shortcuts

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