Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func IsLevelEnabled(lvl LogLevel) bool
- func Print(lvl LogLevel, v ...interface{})
- func Printf(lvl LogLevel, format string, v ...interface{})
- func SetLevel(lvl LogLevel)
- func SetRoot(lg Logger)
- func Verbose(v ...interface{})
- func Verbosef(format string, v ...interface{})
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- type ColoredLogger
- func (s *ColoredLogger) Debug(v ...interface{})
- func (s *ColoredLogger) Debugf(format string, v ...interface{})
- func (s *ColoredLogger) Error(v ...interface{})
- func (s *ColoredLogger) Errorf(format string, v ...interface{})
- func (s *ColoredLogger) Fatal(v ...interface{})
- func (s *ColoredLogger) Fatalf(format string, v ...interface{})
- func (s *ColoredLogger) Info(v ...interface{})
- func (s *ColoredLogger) Infof(format string, v ...interface{})
- func (s *ColoredLogger) IsLevelEnabled(lvl LogLevel) bool
- func (s *ColoredLogger) Out() io.Writer
- func (s *ColoredLogger) Print(lvl LogLevel, v ...interface{})
- func (s *ColoredLogger) Printf(lvl LogLevel, format string, v ...interface{})
- func (s *ColoredLogger) SetLevel(lvl LogLevel)
- func (s *ColoredLogger) SetLevelString(level string)
- func (s *ColoredLogger) SetOut(out io.Writer)
- func (s *ColoredLogger) Verbose(v ...interface{})
- func (s *ColoredLogger) Verbosef(format string, v ...interface{})
- func (s *ColoredLogger) Warn(v ...interface{})
- func (s *ColoredLogger) Warnf(format string, v ...interface{})
- type CustomPatternLogger
- func (l *CustomPatternLogger) Debug(v ...interface{})
- func (l *CustomPatternLogger) Debugf(format string, v ...interface{})
- func (l *CustomPatternLogger) Error(v ...interface{})
- func (l *CustomPatternLogger) Errorf(format string, v ...interface{})
- func (l *CustomPatternLogger) Fatal(v ...interface{})
- func (l *CustomPatternLogger) Fatalf(format string, v ...interface{})
- func (l *CustomPatternLogger) Info(v ...interface{})
- func (l *CustomPatternLogger) Infof(format string, v ...interface{})
- func (l *CustomPatternLogger) IsLevelEnabled(lvl LogLevel) bool
- func (l *CustomPatternLogger) Level() LogLevel
- func (l *CustomPatternLogger) Out() io.Writer
- func (l *CustomPatternLogger) Print(lvl LogLevel, v ...interface{})
- func (l *CustomPatternLogger) Printf(lvl LogLevel, format string, v ...interface{})
- func (l *CustomPatternLogger) SetClock(clk clock)
- func (l *CustomPatternLogger) SetLevel(lvl LogLevel)
- func (s *CustomPatternLogger) SetLevelString(level string)
- func (l *CustomPatternLogger) SetOut(out io.Writer)
- func (l *CustomPatternLogger) Verbose(v ...interface{})
- func (l *CustomPatternLogger) Verbosef(format string, v ...interface{})
- func (l *CustomPatternLogger) Warn(v ...interface{})
- func (l *CustomPatternLogger) Warnf(format string, v ...interface{})
- type LogLevel
- type Logger
- type NamedLogger
- func (l *NamedLogger) Debug(v ...interface{})
- func (l *NamedLogger) Debugf(format string, v ...interface{})
- func (l *NamedLogger) Error(v ...interface{})
- func (l *NamedLogger) Errorf(format string, v ...interface{})
- func (l *NamedLogger) Fatal(v ...interface{})
- func (l *NamedLogger) Fatalf(format string, v ...interface{})
- func (l *NamedLogger) Info(v ...interface{})
- func (l *NamedLogger) Infof(format string, v ...interface{})
- func (l *NamedLogger) IsLevelEnabled(lvl LogLevel) bool
- func (l *NamedLogger) Level() LogLevel
- func (l *NamedLogger) Name() string
- func (l *NamedLogger) Out() io.Writer
- func (l *NamedLogger) Print(lvl LogLevel, v ...interface{})
- func (l *NamedLogger) Printf(lvl LogLevel, format string, v ...interface{})
- func (l *NamedLogger) SetClock(clk clock)
- func (l *NamedLogger) SetLevel(lvl LogLevel)
- func (s *NamedLogger) SetLevelString(level string)
- func (l *NamedLogger) SetName(name string)
- func (l *NamedLogger) SetOut(out io.Writer)
- func (l *NamedLogger) Verbose(v ...interface{})
- func (l *NamedLogger) Verbosef(format string, v ...interface{})
- func (l *NamedLogger) Warn(v ...interface{})
- func (l *NamedLogger) Warnf(format string, v ...interface{})
- type SimpleLogger
- func (s *SimpleLogger) Debug(v ...interface{})
- func (s *SimpleLogger) Debugf(format string, v ...interface{})
- func (s *SimpleLogger) Error(v ...interface{})
- func (s *SimpleLogger) Errorf(format string, v ...interface{})
- func (s *SimpleLogger) Fatal(v ...interface{})
- func (s *SimpleLogger) Fatalf(format string, v ...interface{})
- func (s *SimpleLogger) Info(v ...interface{})
- func (s *SimpleLogger) Infof(format string, v ...interface{})
- func (s *SimpleLogger) IsLevelEnabled(lvl LogLevel) bool
- func (s *SimpleLogger) Level() LogLevel
- func (s *SimpleLogger) Out() io.Writer
- func (s *SimpleLogger) Print(lvl LogLevel, v ...interface{})
- func (s *SimpleLogger) Printf(lvl LogLevel, format string, v ...interface{})
- func (s *SimpleLogger) SetClock(clk clock)
- func (s *SimpleLogger) SetLevel(lvl LogLevel)
- func (s *SimpleLogger) SetLevelString(level string)
- func (s *SimpleLogger) SetOut(out io.Writer)
- func (s *SimpleLogger) Verbose(v ...interface{})
- func (s *SimpleLogger) Verbosef(format string, v ...interface{})
- func (s *SimpleLogger) Warn(v ...interface{})
- func (s *SimpleLogger) Warnf(format string, v ...interface{})
- type WriterLogger
Constants ¶
const ( // TimeLayoutCustomPatternLogger is the time layout that the simple logger // uses for its messages if no formatting pattern is given. TimeLayoutCustomPatternLogger = "2006-01-02 15:04:05.000" // CustomPatternLoggerDefaultPattern is the fallback pattern that is used // if the pattern compilation or template execution fails. CustomPatternLoggerDefaultPattern = "{{.Timestamp}} [{{.Level}}] - {{.Message}}\n" )
const ( // TimeLayoutNamedLogger is the time layout that the named logger // uses for its messages. TimeLayoutNamedLogger = "2006-01-02 15:04:05.000" )
const ( // TimeLayoutSimpleLogger is the time layout that the simple logger // uses for its messages. TimeLayoutSimpleLogger = "2006-01-02 15:04:05.000" )
Variables ¶
var ( ColorGray = color("\u001b[30;1m") ColorGreen = color("\u001b[32;1m") ColorNone = ColorReset ColorRed = color("\u001b[31m") ColorReset = color("\u001b[0m") ColorYellow = color("\u001b[33m") )
Available colors (16 bit ANSI color codes)
Functions ¶
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf formats and prints the given values with log level DEBG.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf formats and prints the given values with log level ERR.
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf formats and prints the given values with log level FATAL.
func Infof ¶
func Infof(format string, v ...interface{})
Infof formats and prints the given values with log level INFO.
func IsLevelEnabled ¶
IsLevelEnabled returns true if and only if the root logger would print messages with the given log level. False otherwise.
func Print ¶
func Print(lvl LogLevel, v ...interface{})
Print delegates to the root logger, if and only if the given level is enabled by the root logger.
func Printf ¶
Printf delegates to the root logger, if and only if the given level is enabled by the root logger.
func SetRoot ¶
func SetRoot(lg Logger)
SetRoot changes the globally used root logger. This function is safe for concurrent use.
func Verbose ¶
func Verbose(v ...interface{})
Verbose prints the given values with log level DEBG, but the root logger must have verbose log levels enabled to show any output.
Types ¶
type ColoredLogger ¶
type ColoredLogger struct {
// contains filtered or unexported fields
}
ColoredLogger is a wrapper for any WriterLogger. Depending on the level that should be printed, this wrapper will prepend an ANSI-color code to the wrapped loggers output writer and will then call the respective output method. Please notice that this is not add a decorator for a given logger, but a wrapper, which must be used for colors to show up.
The color codes are written to the wrapped loggers output writer. An output call will trigger three writes on the wrapped loggers output writer.
1. color code
2. output from wrapped logger
3. color code reset
The second call will not originate from the wrapper, as, after the color code was written, Print (or respectively Printf) will be called on the wrapped logger.
func (*ColoredLogger) Debug ¶
func (s *ColoredLogger) Debug(v ...interface{})
Debug delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) Debugf ¶
func (s *ColoredLogger) Debugf(format string, v ...interface{})
Debugf delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) Error ¶
func (s *ColoredLogger) Error(v ...interface{})
Error delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) Errorf ¶
func (s *ColoredLogger) Errorf(format string, v ...interface{})
Errorf delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) Fatal ¶
func (s *ColoredLogger) Fatal(v ...interface{})
Fatal delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
THIS WRAPPER DOES NOT TERMINATE THE APPLICATION AFTER A FATAL CALL.
func (*ColoredLogger) Fatalf ¶
func (s *ColoredLogger) Fatalf(format string, v ...interface{})
Fatalf delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
THIS WRAPPER DOES NOT TERMINATE THE APPLICATION AFTER A FATAL CALL.
func (*ColoredLogger) Info ¶
func (s *ColoredLogger) Info(v ...interface{})
Info delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) Infof ¶
func (s *ColoredLogger) Infof(format string, v ...interface{})
Infof delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) IsLevelEnabled ¶
func (s *ColoredLogger) IsLevelEnabled(lvl LogLevel) bool
IsLevelEnabled delegates to the wrapped loggers IsLevelEnabled method.
func (*ColoredLogger) Out ¶
func (s *ColoredLogger) Out() io.Writer
Out returns the writer of the wrapped logger.
func (*ColoredLogger) Print ¶
func (s *ColoredLogger) Print(lvl LogLevel, v ...interface{})
Print delegates the values with the given log level to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) Printf ¶
func (s *ColoredLogger) Printf(lvl LogLevel, format string, v ...interface{})
Printf delegates the format string and values with the given log level to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) SetLevel ¶
func (s *ColoredLogger) SetLevel(lvl LogLevel)
SetLevel delegates the given log level to the wrapped logger.
func (*ColoredLogger) SetLevelString ¶
func (s *ColoredLogger) SetLevelString(level string)
func (*ColoredLogger) SetOut ¶
func (s *ColoredLogger) SetOut(out io.Writer)
SetOut sets a new writer for the wrapped logger.
func (*ColoredLogger) Verbose ¶
func (s *ColoredLogger) Verbose(v ...interface{})
Verbose delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) Verbosef ¶
func (s *ColoredLogger) Verbosef(format string, v ...interface{})
Verbosef delegates the given values and format string to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) Warn ¶
func (s *ColoredLogger) Warn(v ...interface{})
Warn delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
func (*ColoredLogger) Warnf ¶
func (s *ColoredLogger) Warnf(format string, v ...interface{})
Warnf delegates the given values to the wrapped logger while writing ansi color codes to the wrapped loggers output writer.
type CustomPatternLogger ¶
type CustomPatternLogger struct {
// contains filtered or unexported fields
}
CustomPatternLogger is a logger that supports a custom log pattern. The pattern is a go template text. If its compilation or execution fails at any point, the CustomPatternLoggerDefaultPattern will be used. It supports the following operations:
{{.Level}} // the level of the message
Level prints the level of the log message, at least 4 characters.
{{.Message}} // the message to be printed
Message prints the log message that should be printed. If the message or the pattern doesn't end with a line break, no line break will be printed.
{{.Timestamp}} or {{.Timestampf "2006-01-02 03:04:05PM"}} // time.Time.Format's layout is used
Timestampf takes a string argument, which will be used for formatting the timestamp in the log message. The reference time is the same as in time.Time's function "Format". Timestamp uses the layout "2006-01-02 15:04:05.000".
{{.File}} or {{.Filef "short"}} // one of "short", "full" (anything different will be interpreted as "full")
Filef "short" prints only the filename, while Filef "full" prints the file's absolute path.
{{.Line}} // prints the line of the output call
Line only prints the line number.
{{.Function}} or {{.Functionf "package"}} // one of "short", "package", "full" (anything different will be interpreted as "full")
Functionf "short" prints only the function name, while Functionf "package" will print <package>.<function>. Functionf "full" will print <full_package>.<function>, e.g. "github.com/TimSatke/abc.main".
Example:
{{.Timestamp}} {{.Filef "short"}}:{{.Line}} {{.Functionf "package"}} [{{.Level}}] - {{.Message}}\n
will print something like
2018-11-24 15:26:44.453 main.go:16 main.main [INFO] - Hello World! <line break>
func (*CustomPatternLogger) Debug ¶
func (l *CustomPatternLogger) Debug(v ...interface{})
Debug prints the given values with log level DEBG.
func (*CustomPatternLogger) Debugf ¶
func (l *CustomPatternLogger) Debugf(format string, v ...interface{})
Debugf formats and prints the given values with log level DEBG.
func (*CustomPatternLogger) Error ¶
func (l *CustomPatternLogger) Error(v ...interface{})
Error prints the given values with log level ERR.
func (*CustomPatternLogger) Errorf ¶
func (l *CustomPatternLogger) Errorf(format string, v ...interface{})
Errorf formats and prints the given values with log level ERR.
func (*CustomPatternLogger) Fatal ¶
func (l *CustomPatternLogger) Fatal(v ...interface{})
Fatal prints the given values with log level FATAL. IT DOES NOT TERMINATE THE APPLICATION.
func (*CustomPatternLogger) Fatalf ¶
func (l *CustomPatternLogger) Fatalf(format string, v ...interface{})
Fatalf formats and prints the given values with log level FATAL. IT DOES NOT TERMINATE THE APPLICATION.
func (*CustomPatternLogger) Info ¶
func (l *CustomPatternLogger) Info(v ...interface{})
Info prints the given values with log level INFO.
func (*CustomPatternLogger) Infof ¶
func (l *CustomPatternLogger) Infof(format string, v ...interface{})
Infof formats and prints the given values with log level INFO.
func (*CustomPatternLogger) IsLevelEnabled ¶
func (l *CustomPatternLogger) IsLevelEnabled(lvl LogLevel) bool
IsLevelEnabled returns true if and only if this logger would print messages with the given log level. False otherwise.
func (*CustomPatternLogger) Level ¶
func (l *CustomPatternLogger) Level() LogLevel
Level returns the current level of this logger.
func (*CustomPatternLogger) Out ¶
func (l *CustomPatternLogger) Out() io.Writer
Out returns the writer of this logger.
func (*CustomPatternLogger) Print ¶
func (l *CustomPatternLogger) Print(lvl LogLevel, v ...interface{})
Print prints the given values with the given log level, if and only if the given log level is higher than or equal to the one of this logger.
func (*CustomPatternLogger) Printf ¶
func (l *CustomPatternLogger) Printf(lvl LogLevel, format string, v ...interface{})
Printf formats and prints the given values with the given log level, if and only if the given log level is higher than or equal to the one of this logger.
func (*CustomPatternLogger) SetClock ¶
func (l *CustomPatternLogger) SetClock(clk clock)
SetClock sets a new clock for this logger.
func (*CustomPatternLogger) SetLevel ¶
func (l *CustomPatternLogger) SetLevel(lvl LogLevel)
SetLevel changes the log level of this logger.
func (*CustomPatternLogger) SetLevelString ¶
func (s *CustomPatternLogger) SetLevelString(level string)
func (*CustomPatternLogger) SetOut ¶
func (l *CustomPatternLogger) SetOut(out io.Writer)
SetOut sets a new writer for this logger.
func (*CustomPatternLogger) Verbose ¶
func (l *CustomPatternLogger) Verbose(v ...interface{})
Verbose prints the given values with log level DEBG, if and only if this logger has the verbose log level enabled.
func (*CustomPatternLogger) Verbosef ¶
func (l *CustomPatternLogger) Verbosef(format string, v ...interface{})
Verbosef formats and prints the given values with log level DEBG, if and only if this logger has the verbose log level enabled.
func (*CustomPatternLogger) Warn ¶
func (l *CustomPatternLogger) Warn(v ...interface{})
Warn prints the given values with log level WARN.
func (*CustomPatternLogger) Warnf ¶
func (l *CustomPatternLogger) Warnf(format string, v ...interface{})
Warnf formats and prints the given values with log level WARN.
type LogLevel ¶
type LogLevel uint8
LogLevel is an alias and represents a log level.
Available log levels.
LevelVerbose LogLevel = iota LevelDebug LevelInfo LevelWarn LevelError LevelFatal
func ToLogLevel ¶
type Logger ¶
type Logger interface { // Print prints the given values with the given log level, // if and only if the given log level is higher than or // equal to the one of this logger. Print(LogLevel, ...interface{}) // Printf formats and prints the given values with the given log level, // if and only if the given log level is higher than or // equal to the one of this logger. Printf(LogLevel, string, ...interface{}) // Verbose prints the given values with log level DEBG, // if and only if this logger has the verbose log level enabled. Verbose(...interface{}) // Verbosef formats and prints the given values with log level DEBG, // if and only if this logger has the verbose log level enabled. Verbosef(string, ...interface{}) // Debug prints the given values with log level DEBG. Debug(...interface{}) // Debugf formats and prints the given values with log level DEBG. Debugf(string, ...interface{}) // Info prints the given values with log level INFO. Info(...interface{}) // Infof formats and prints the given values with log level INFO. Infof(string, ...interface{}) // Warn prints the given values with log level WARN. Warn(...interface{}) // Warnf formats and prints the given values with log level WARN. Warnf(string, ...interface{}) // Error prints the given values with log level ERR. Error(...interface{}) // Errorf formats and prints the given values with log level ERR. Errorf(string, ...interface{}) // Fatal prints the given values with log level FATAL. // IT DOES NOT TERMINATE THE APPLICATION. Fatal(...interface{}) // Fatalf formats and prints the given values with log level FATAL. // IT DOES NOT TERMINATE THE APPLICATION. Fatalf(string, ...interface{}) // SetLevel changes the log level of this logger. SetLevel(LogLevel) // SetLevelString changes to log level of this logger. // The string is case-insensitive and can be one of // // [verbose,debug,info,warn,error,fatal] SetLevelString(string) // IsLevelEnabled returns true if and only if this logger would print // messages with the given log level. // False otherwise. IsLevelEnabled(LogLevel) bool }
Logger describes objects that can log messages. It can differentiate between several log levels, and provides methods for each one.
type NamedLogger ¶
type NamedLogger struct {
// contains filtered or unexported fields
}
NamedLogger is a logger that has and prints a name in its log messages. NamedLoggers are completely safe for concurrent use.
func (*NamedLogger) Debug ¶
func (l *NamedLogger) Debug(v ...interface{})
Debug prints the given values with log level DEBG.
func (*NamedLogger) Debugf ¶
func (l *NamedLogger) Debugf(format string, v ...interface{})
Debugf formats and prints the given values with log level DEBG.
func (*NamedLogger) Error ¶
func (l *NamedLogger) Error(v ...interface{})
Error prints the given values with log level ERR.
func (*NamedLogger) Errorf ¶
func (l *NamedLogger) Errorf(format string, v ...interface{})
Errorf formats and prints the given values with log level ERR.
func (*NamedLogger) Fatal ¶
func (l *NamedLogger) Fatal(v ...interface{})
Fatal prints the given values with log level FATAL. IT DOES NOT TERMINATE THE APPLICATION.
func (*NamedLogger) Fatalf ¶
func (l *NamedLogger) Fatalf(format string, v ...interface{})
Fatalf formats and prints the given values with log level FATAL. IT DOES NOT TERMINATE THE APPLICATION.
func (*NamedLogger) Info ¶
func (l *NamedLogger) Info(v ...interface{})
Info prints the given values with log level INFO.
func (*NamedLogger) Infof ¶
func (l *NamedLogger) Infof(format string, v ...interface{})
Infof formats and prints the given values with log level INFO.
func (*NamedLogger) IsLevelEnabled ¶
func (l *NamedLogger) IsLevelEnabled(lvl LogLevel) bool
IsLevelEnabled returns true if and only if this logger would print messages with the given log level. False otherwise.
func (*NamedLogger) Level ¶
func (l *NamedLogger) Level() LogLevel
Level returns the current level of this logger.
func (*NamedLogger) Name ¶
func (l *NamedLogger) Name() string
Name returns the name of this logger.
func (*NamedLogger) Out ¶
func (l *NamedLogger) Out() io.Writer
Out returns the writer of this logger.
func (*NamedLogger) Print ¶
func (l *NamedLogger) Print(lvl LogLevel, v ...interface{})
Print prints the given values with the given log level, if and only if the given log level is higher than or equal to the one of this logger.
func (*NamedLogger) Printf ¶
func (l *NamedLogger) Printf(lvl LogLevel, format string, v ...interface{})
Printf formats and prints the given values with the given log level, if and only if the given log level is higher than or equal to the one of this logger.
func (*NamedLogger) SetClock ¶
func (l *NamedLogger) SetClock(clk clock)
SetClock sets a new clock for this logger.
func (*NamedLogger) SetLevel ¶
func (l *NamedLogger) SetLevel(lvl LogLevel)
SetLevel changes the log level of this logger.
func (*NamedLogger) SetLevelString ¶
func (s *NamedLogger) SetLevelString(level string)
func (*NamedLogger) SetName ¶
func (l *NamedLogger) SetName(name string)
SetName sets a new name for this logger.
func (*NamedLogger) SetOut ¶
func (l *NamedLogger) SetOut(out io.Writer)
SetOut sets a new writer for this logger.
func (*NamedLogger) Verbose ¶
func (l *NamedLogger) Verbose(v ...interface{})
Verbose prints the given values with log level DEBG, if and only if this logger has the verbose log level enabled.
func (*NamedLogger) Verbosef ¶
func (l *NamedLogger) Verbosef(format string, v ...interface{})
Verbosef formats and prints the given values with log level DEBG, if and only if this logger has the verbose log level enabled.
func (*NamedLogger) Warn ¶
func (l *NamedLogger) Warn(v ...interface{})
Warn prints the given values with log level WARN.
func (*NamedLogger) Warnf ¶
func (l *NamedLogger) Warnf(format string, v ...interface{})
Warnf formats and prints the given values with log level WARN.
type SimpleLogger ¶
type SimpleLogger struct {
// contains filtered or unexported fields
}
SimpleLogger is a logger that prints log messages. SimpleLoggers are completely safe for concurrent use.
func (*SimpleLogger) Debug ¶
func (s *SimpleLogger) Debug(v ...interface{})
Debug prints the given values with log level DEBG.
func (*SimpleLogger) Debugf ¶
func (s *SimpleLogger) Debugf(format string, v ...interface{})
Debugf formats and prints the given values with log level DEBG.
func (*SimpleLogger) Error ¶
func (s *SimpleLogger) Error(v ...interface{})
Error prints the given values with log level ERR.
func (*SimpleLogger) Errorf ¶
func (s *SimpleLogger) Errorf(format string, v ...interface{})
Errorf formats and prints the given values with log level ERR.
func (*SimpleLogger) Fatal ¶
func (s *SimpleLogger) Fatal(v ...interface{})
Fatal prints the given values with log level FATAL. IT DOES NOT TERMINATE THE APPLICATION.
func (*SimpleLogger) Fatalf ¶
func (s *SimpleLogger) Fatalf(format string, v ...interface{})
Fatalf formats and prints the given values with log level FATAL. IT DOES NOT TERMINATE THE APPLICATION.
func (*SimpleLogger) Info ¶
func (s *SimpleLogger) Info(v ...interface{})
Info prints the given values with log level INFO.
func (*SimpleLogger) Infof ¶
func (s *SimpleLogger) Infof(format string, v ...interface{})
Infof formats and prints the given values with log level INFO.
func (*SimpleLogger) IsLevelEnabled ¶
func (s *SimpleLogger) IsLevelEnabled(lvl LogLevel) bool
IsLevelEnabled returns true if and only if this logger would print messages with the given log level. False otherwise.
func (*SimpleLogger) Level ¶
func (s *SimpleLogger) Level() LogLevel
Level returns the current level of this logger.
func (*SimpleLogger) Out ¶
func (s *SimpleLogger) Out() io.Writer
Out returns the writer of this logger.
func (*SimpleLogger) Print ¶
func (s *SimpleLogger) Print(lvl LogLevel, v ...interface{})
Print prints the given values with the given log level, if and only if the given log level is higher than or equal to the one of this logger.
func (*SimpleLogger) Printf ¶
func (s *SimpleLogger) Printf(lvl LogLevel, format string, v ...interface{})
Printf formats and prints the given values with the given log level, if and only if the given log level is higher than or equal to the one of this logger.
func (*SimpleLogger) SetClock ¶
func (s *SimpleLogger) SetClock(clk clock)
SetClock sets a new clock for this logger.
func (*SimpleLogger) SetLevel ¶
func (s *SimpleLogger) SetLevel(lvl LogLevel)
SetLevel changes the log level of this logger.
func (*SimpleLogger) SetLevelString ¶
func (s *SimpleLogger) SetLevelString(level string)
func (*SimpleLogger) SetOut ¶
func (s *SimpleLogger) SetOut(out io.Writer)
SetOut sets a new writer for this logger.
func (*SimpleLogger) Verbose ¶
func (s *SimpleLogger) Verbose(v ...interface{})
Verbose prints the given values with log level DEBG, if and only if this logger has the verbose log level enabled.
func (*SimpleLogger) Verbosef ¶
func (s *SimpleLogger) Verbosef(format string, v ...interface{})
Verbosef formats and prints the given values with log level DEBG, if and only if this logger has the verbose log level enabled.
func (*SimpleLogger) Warn ¶
func (s *SimpleLogger) Warn(v ...interface{})
Warn prints the given values with log level WARN.
func (*SimpleLogger) Warnf ¶
func (s *SimpleLogger) Warnf(format string, v ...interface{})
Warnf formats and prints the given values with log level WARN.
type WriterLogger ¶
type WriterLogger interface { Logger // Out returns the writer to which the output // is printed. Out() io.Writer // SetOut changes the writer to which the output // is printed. SetOut(io.Writer) }
WriterLogger is an interface that embeds abc.Logger. It describes loggers that write their output to an io.Writer, and provides methods for retrieving and changing that writer.
func NewColoredLogger ¶
func NewColoredLogger(wrapped WriterLogger) WriterLogger
NewColoredLogger creates a wrapper for a given WriterLogger. Depending on the level that should be printed, this wrapper will prepend an ANSI-color code to the wrapped loggers output writer and will then call the respective output method. Please notice that this function does not add a decorator to the given logger, but creates a wrapper, which must be used for colors to show up.
func NewCustomPatternLogger ¶
func NewCustomPatternLogger(pattern string) (WriterLogger, error)
NewCustomPatternLogger returns a new abc.CustomPatternLogger, which was initialized and thus is ready to use. If an error occurs during the initialization, that error is returned.
The given pattern is a go template text and supports the following operations:
{{.Level}} // the level of the message
Level prints the level of the log message, at least 4 characters.
{{.Message}} // the message to be printed
Message prints the log message that should be printed. If the message or the pattern doesn't end with a line break, no line break will be printed.
{{.Timestamp}} or {{.Timestampf "2006-01-02 03:04:05PM"}} // time.Time.Format's layout is used
Timestampf takes a string argument, which will be used for formatting the timestamp in the log message. The reference time is the same as in time.Time's function "Format". Timestamp uses the layout "2006-01-02 15:04:05.000".
{{.File}} or {{.Filef "short"}} // one of "short", "full" (anything different will be interpreted as "full")
Filef "short" prints only the filename, while Filef "full" prints the file's absolute path.
{{.Line}} // prints the line of the output call
Line only prints the line number.
{{.Function}} or {{.Functionf "package"}} // one of "short", "package", "full" (anything different will be interpreted as "full")
Functionf "short" prints only the function name, while Functionf "package" will print <package>.<function>. Functionf "full" will print <full_package>.<function>, e.g. "github.com/TimSatke/abc.main".
Example:
{{.Timestamp}} {{.Filef "short"}}:{{.Line}} {{.Functionf "package"}} [{{.Level}}] - {{.Message}}\n
will print something like
2018-11-24 15:26:44.453 main.go:16 main.main [INFO] - Hello World! <line break>
func NewNamedLogger ¶
func NewNamedLogger(name string) WriterLogger
NewNamedLogger returns a new abc.NamedLogger, which is ready to use. The default log level is INFO and can be changed with
logger.SetLevel(abc.LevelInfo)
The logger prints to os.Stdout by default. The output writer can be changed with
logger.SetOut(os.Stdout)
func NewSimpleLogger ¶
func NewSimpleLogger() WriterLogger
NewSimpleLogger returns a new abc.SimpleLogger, which is ready to use. The default log level is INFO and can be changed with
logger.SetLevel(abc.LevelInfo)
The logger prints to os.Stdout by default. The output writer can be changed with
logger.SetOut(os.Stdout)