Documentation
¶
Index ¶
- Constants
- Variables
- func ColoredLogWrapper(l LogLevel, s string) string
- func Colorize(color, s any) string
- func FColorize(w io.Writer, color, s any) (n int, err error)
- func Setup(logger Log)
- type Log
- type LogLevel
- type LogWriter
- type Logger
- func (l *Logger) Copy() *Logger
- func (l *Logger) Debug(args ...interface{})
- func (l *Logger) Debugf(format string, args ...interface{})
- func (l *Logger) Error(args ...interface{})
- func (l *Logger) Errorf(format string, args ...interface{})
- func (l *Logger) Fatal(errorcode int, args ...interface{})
- func (l *Logger) Fatalf(errorcode int, format string, args ...interface{})
- func (l *Logger) Info(args ...interface{})
- func (l *Logger) Infof(format string, args ...interface{})
- func (l *Logger) Log(level LogLevel, args ...interface{})
- func (l *Logger) Logf(level LogLevel, format string, args ...interface{})
- func (l *Logger) NameSpace(label string) Log
- func (l *Logger) Output(level LogLevel) io.Writer
- func (l *Logger) PWriter(label string, level LogLevel) io.Writer
- func (l *Logger) SetLevel(level LogLevel)
- func (l *Logger) SetOutput(level LogLevel, w io.Writer)
- func (l *Logger) Warn(args ...interface{})
- func (l *Logger) Warnf(format string, args ...interface{})
- func (l *Logger) WriteString(s string) (n int, err error)
- func (l *Logger) Writer(level LogLevel) io.Writer
Constants ¶
View Source
const ( CMD_Green = "\033[32m" CMD_Cyan = "\033[36m" CMD_Yellow = "\033[33m" CMD_Red = "\033[31m" CMD_Bold = "\033[1m" CMD_Reset = "\033[0m" )
Variables ¶
View Source
var ( Writer = func(level LogLevel) io.Writer { return os.Stdout } PWriter = func(label string, level LogLevel) io.Writer { return os.Stdout } NameSpace = func(label string) Log { return nil } SetOutput func(level LogLevel, w io.Writer) = func(level LogLevel, w io.Writer) {} SetLevel func(level LogLevel) = func(level LogLevel) {} Debug = func(args ...interface{}) {} Info = func(args ...interface{}) {} Warn = func(args ...interface{}) {} Error = func(args ...interface{}) {} Fatal = func(errorcode int, args ...interface{}) {} Debugf = func(format string, args ...interface{}) {} Infof = func(format string, args ...interface{}) {} Warnf = func(format string, args ...interface{}) {} Errorf = func(format string, args ...interface{}) {} Fatalf = func(errorcode int, format string, args ...interface{}) {} Logf = func(level LogLevel, format string, args ...interface{}) {} )
View Source
var (
ErrOutputInvalid = errors.New("output is invalid")
)
Functions ¶
func ColoredLogWrapper ¶
Types ¶
type Log ¶
type Log interface {
// Writer returns a new io.Writer that writes to the log output for the given log level.
Writer(level LogLevel) io.Writer
// PWriter returns a new io.Writer that writes to the log output for the given log level with a prefix.
PWriter(label string, level LogLevel) io.Writer
// NameSpace returns a new Log with the given label as the prefix.
NameSpace(label string) Log
// SetOutput sets the output for the given log level.
SetOutput(level LogLevel, w io.Writer)
// SetLevel sets the current log level.
//
// Log messages with a log level lower than the current log level will not be written.
SetLevel(level LogLevel)
// Log a debug message.
Debug(args ...interface{})
// Log an info message.
Info(args ...interface{})
// Log a warning message.
Warn(args ...interface{})
// Log an error message.
Error(args ...interface{})
// Log a message and exit the program with the given error code.
Fatal(errorcode int, args ...interface{})
// Log a format- and args-based debug message.
Debugf(format string, args ...interface{})
// Log a format- and args-based info message.
Infof(format string, args ...interface{})
// Log a format- and args-based warning message.
Warnf(format string, args ...interface{})
// Log a format- and args-based error message.
Errorf(format string, args ...interface{})
// Log a format- and args-based message and exit the program with the given error code.
Fatalf(errorcode int, format string, args ...interface{})
// Log a message at the given log level.
Log(level LogLevel, args ...interface{})
// Log a format string at the given log level.
Logf(level LogLevel, format string, args ...interface{})
// WriteString writes a string to the log output.
WriteString(s string) (n int, err error)
}
type Logger ¶
type Logger struct {
// Level is the log level.
Level LogLevel
// Prefix is the prefix for each log message.
Prefix string
// Suffix is the suffix for each log message.
Suffix string
// Display a timestamp alongside the log message.
OutputTime bool
// Outputs for the log messages.
OutputDebug io.Writer
OutputInfo io.Writer
OutputWarn io.Writer
OutputError io.Writer
// WrapPrefix determines how the prefix should be wrapped
// based on the LogLevel.
WrapPrefix func(LogLevel, string) string
}
The Logger type is used to log messages at different log levels.
It is possible to set the log level, prefix, suffix, and outputs for the log messages.
When a log message is written, the prefix, log level, and suffix are written to the output provided for that specific loglevel.
func (*Logger) Fatal ¶
Fatal is a convenience function for logging an error and exiting the program.
func (*Logger) Fatalf ¶
Fatalf is a convenience function for logging an error and exiting the program.
func (*Logger) PWriter ¶
PWriter returns a new io.Writer that writes to the log output for the given log level with a prefix.
Click to show internal directories.
Click to hide internal directories.