Documentation
¶
Index ¶
- Constants
- Variables
- func FormatterHuman(now time.Time, level string, msg string, fields Fields) string
- func FormatterJSON(now time.Time, level string, msg string, fields Fields) string
- type Fields
- type Log
- type Logger
- func (logger *Logger) AddLog(log *Log)
- func (logger *Logger) AddLogs(logs []*Log)
- func (logger *Logger) Debug(msg string)
- func (logger *Logger) DebugFields(msg string, fields Fields)
- func (logger *Logger) DebugFieldsf(msg string, fields Fields, format ...any)
- func (logger *Logger) Debugf(msg string, format ...any)
- func (logger *Logger) Error(msg string)
- func (logger *Logger) ErrorFields(msg string, fields Fields)
- func (logger *Logger) ErrorFieldsf(msg string, fields Fields, format ...any)
- func (logger *Logger) Errorf(msg string, format ...any)
- func (logger *Logger) Fatal(msg string)
- func (logger *Logger) FatalFields(msg string, fields Fields)
- func (logger *Logger) FatalFieldsf(msg string, fields Fields, format ...any)
- func (logger *Logger) Fatalf(msg string, format ...any)
- func (logger *Logger) Info(msg string)
- func (logger *Logger) InfoFields(msg string, fields Fields)
- func (logger *Logger) InfoFieldsf(msg string, fields Fields, format ...any)
- func (logger *Logger) Infof(msg string, format ...any)
- func (logger *Logger) Panic(err error)
- func (logger *Logger) PanicFields(err error, fields Fields)
- func (logger *Logger) PanicFieldsf(msg string, fields Fields, format ...any)
- func (logger *Logger) Panicf(msg string, format ...any)
- func (logger *Logger) RemoveLog(log *Log)
- func (logger *Logger) RemoveLogs(logs []*Log)
- func (logger *Logger) Warning(msg string)
- func (logger *Logger) WarningFields(msg string, fields Fields)
- func (logger *Logger) WarningFieldsf(msg string, fields Fields, format ...any)
- func (logger *Logger) Warningf(msg string, format ...any)
Constants ¶
const ( FATAL levelIndexes = iota ERROR WARNING INFO DEBUG )
Enum to represent a level's index.
Variables ¶
var LevelColours = map[string]string{
"FATAL": "\u001b[35m",
"ERROR": "\u001b[31m",
"WARNING": "\u001b[33m",
"INFO": "\u001b[34m",
"DEBUG": "",
"RESET": "\u001b[0m",
}
var Levels = []string{
"FATAL",
"ERROR",
"WARNING",
"INFO",
"DEBUG",
}
Level names.
var LongestLevel = func() int { longestLevelLength := 0 for _, levelName := range Levels { levelLength := len(levelName) if levelLength > longestLevelLength { longestLevelLength = levelLength } } return longestLevelLength }()
Functions ¶
func FormatterHuman ¶
An example formatter for humans. Returns a human-readable representation of the log.
Types ¶
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Represents a log output. The zero value for Log is not ready for use, and must be populated.
func NewLog ¶
Creates a new log output, and returns it. The formatter must follow the signature found in [formatterType].
func (*Log) AddWriters ¶
Adds multiple writers to the log. Also see Log.AddWriter.
func (*Log) RemoveWriter ¶
Removes a writer from the log. It will remove as many instances of it as it can find.
func (*Log) RemoveWriters ¶
Removes a writer from the log. It will remove as many instances of it as it can find. Also see Log.RemoveWriter.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Represents a logger. The zero value for Logger is ready for use.
func (*Logger) AddLogs ¶
Adds multiple logs to the logger. Also see Logger.AddLog
func (*Logger) DebugFields ¶ added in v1.1.0
Logs a message with the specified fields, using DEBUG as the log level.
func (*Logger) DebugFieldsf ¶ added in v1.1.0
Formats the message, and then logs it with the specified fields, using DEBUG as the log level.
func (*Logger) ErrorFields ¶ added in v1.1.0
Logs a message with the specified fields, using ERROR as the log level.
func (*Logger) ErrorFieldsf ¶ added in v1.1.0
Formats the message, and then logs it with the specified fields, using ERROR as the log level.
func (*Logger) FatalFields ¶ added in v1.1.0
Logs a message with the specified fields, using FATAL as the log level. Then calls 'os.Exit(1)'.
func (*Logger) FatalFieldsf ¶ added in v1.1.0
Formats the message, and then logs it with the specified fields, using FATAL as the log level. Then calls 'os.Exit(1)'.
func (*Logger) InfoFields ¶ added in v1.1.0
Logs a message with the specified fields, using INFO as the log level.
func (*Logger) InfoFieldsf ¶ added in v1.1.0
Formats the message, and then logs it with the specified fields, using INFO as the log level.
func (*Logger) PanicFields ¶ added in v1.1.0
Logs the error with the specified fields, using ERROR as the log level. Then calls 'panic(err)'.
func (*Logger) PanicFieldsf ¶ added in v1.1.0
Formats the message, and then logs it with the specified fields, using ERROR as the log level. Then calls 'panic(err)'.
func (*Logger) RemoveLog ¶
Removes a log from the logger. It will remove as many instances of it as it can find.
func (*Logger) RemoveLogs ¶
Removes multiple logs from the logger. It will remove as many instances of it as it can find. Also see Logger.RemoveLog.
func (*Logger) WarningFields ¶ added in v1.1.0
Logs a message with the specified fields, using WARNING as the log level.
func (*Logger) WarningFieldsf ¶ added in v1.1.0
Formats the message, and then logs it with the specified fields, using WARNING as the log level.