log

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Reset  string = "\033[0m"
	White  string = "\033[97m"
	Red    string = "\033[31m"
	Cyan   string = "\033[36m"
	Blue   string = "\033[34m"
	Yellow string = "\033[33m"
)

Color constants for logging.

Variables

This section is empty.

Functions

func Debug

func Debug(message string, args ...any)

Debug is a wrapper function that re-creates the logger instance from config and writes to it.

func Error

func Error(message string, args ...any)

Error is a wrapper function that re-creates the logger instance from config and writes to it.

func Format

func Format(level string, message string, formatStr string) (string, error)

Format is used to get a fully formatted string from `formatStr`. It replaces all variables with their values in `formatStr`.

func GetValues

func GetValues(ascTime string, level string, message string, formatStr string) (map[string]string, error)

GetValues makes an array of strings containing all the format fields with their respective values. Used internally to get the recognized format variables in `formatStr`.

func Info

func Info(message string, args ...any)

Info is a wrapper function that re-creates the logger instance from config and writes to it.

func Verbose

func Verbose(message string, args ...any)

Verbose is a wrapper function that re-creates the logger instance from config and writes to it.

func Warn

func Warn(message string, args ...any)

Warn is a wrapper function that re-creates the logger instance from config and writes to it.

Types

type LogConf

type LogConf struct {
	LogLevel LogLevel `json:"log_level"`
	FilePath string   `json:"file_path"`
}

LogConf is a middleware that stores the log configuration. Maintains the data that it needs for Logger to reconstruct itself.

func ConfRead

func ConfRead() (LogConf, error)

ConfRead reads the configuration from `/tmp/resetti.json` and returns a LogConf instance.

func (*LogConf) UpdateLevel

func (c *LogConf) UpdateLevel(level LogLevel) error

Update is used to update a configuration to `/tmp/resetti.json`

func (*LogConf) Write

func (c *LogConf) Write() error

Write is used to write a configuration to `/tmp/resetti.json`.

type LogLevel

type LogLevel int
const (
	ERROR LogLevel = iota
	WARN
	INFO
	DEBUG
	VERBOSE
)

The level of visibility of the log output. ERROR is the lowest level, VERBOSE is the highest and it increases in the order that it is written.

type Logger

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

Logger is exposed to the user and all logging is done through it. It handles its internal errors, so the user doesn't have to catch any. It maintains LogLevel data, a Formatter instance and a Writer instance. Has functions like Error(), Warn() etc. to print the corresponding log message. Logs are printed out to console as well as the log file.

func DefaultLogger

func DefaultLogger(level LogLevel, filePath string, disableConsole bool) Logger

DefaultLogger creates a pre-defined instance of Logger with a default formatter.

func NewLogger

func NewLogger(level LogLevel, filePath string, disableConsole bool) Logger

NewLogger creates a fresh instance of Logger with a user-defined Formatter. It opens the log file in `filePath` with write-only, truncate and create flags and with mode 0644 (before umask). Passing filePath as a blank string makes it go to `/dev/null`. disableConsole disables console output.

func Rebuild

func Rebuild() Logger

Rebuild loads an existing Logger instance from disk. It parses the conf file in `/tmp/resetti.json` and builds a new Logger instance.

func (*Logger) Close

func (l *Logger) Close()

Close is used to close the file pointer and deletes the conf file.

func (*Logger) Debug

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

Debug prints out the debug message passed to the Sinks. It also checks if the log level allows for the log to be printed.

func (*Logger) Error

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

Error prints out the error message passed to the Sinks.

func (*Logger) Info

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

Info prints out the information passed to the Sinks. It also checks if the log level allows for the log to be printed.

func (*Logger) SetConsole

func (l *Logger) SetConsole(disableConsole bool)

SetConsole sets the output type for the Logger instance.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel)

SetLevel sets the log visibility level of the Logger instance.

func (*Logger) Verbose

func (l *Logger) Verbose(message string, args ...any)

Verbose prints out the message passed to the Sinks. It also checks if the log level allows for the log to be printed.

func (*Logger) Warn

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

Warn prints out the warning message passed to the Sinks. It also checks if the log level allows for the log to be printed.

func (*Logger) Write

func (l *Logger) Write(level string, message string) error

Write formats the message and flushes it to the Sinks using io.Writer

Jump to

Keyboard shortcuts

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