Documentation ¶
Index ¶
- Constants
- func Debug(message string, args ...any)
- func Error(message string, args ...any)
- func Format(level string, message string, formatStr string) (string, error)
- func GetValues(ascTime string, level string, message string, formatStr string) (map[string]string, error)
- func Info(message string, args ...any)
- func Verbose(message string, args ...any)
- func Warn(message string, args ...any)
- type LogConf
- type LogLevel
- type Logger
- func (l *Logger) Close()
- func (l *Logger) Debug(message string, args ...any)
- func (l *Logger) Error(message string, args ...any)
- func (l *Logger) Info(message string, args ...any)
- func (l *Logger) SetConsole(disableConsole bool)
- func (l *Logger) SetLevel(level LogLevel)
- func (l *Logger) Verbose(message string, args ...any)
- func (l *Logger) Warn(message string, args ...any)
- func (l *Logger) Write(level string, message string) error
Constants ¶
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 ¶
Debug is a wrapper function that re-creates the logger instance from config and writes to it.
func Error ¶
Error is a wrapper function that re-creates the logger instance from config and writes to it.
func Format ¶
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 ¶
Info is a wrapper function that re-creates the logger instance from config and writes to it.
Types ¶
type LogConf ¶
LogConf is a middleware that stores the log configuration. Maintains the data that it needs for Logger to reconstruct itself.
func ConfRead ¶
ConfRead reads the configuration from `/tmp/resetti.json` and returns a LogConf instance.
func (*LogConf) UpdateLevel ¶
Update is used to update a configuration to `/tmp/resetti.json`
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 ¶
DefaultLogger creates a pre-defined instance of Logger with a default formatter.
func NewLogger ¶
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 ¶
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) Info ¶
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 ¶
SetConsole sets the output type for the Logger instance.
func (*Logger) Verbose ¶
Verbose prints out the message passed to the Sinks. It also checks if the log level allows for the log to be printed.