Documentation ¶
Index ¶
- type BasicLogger
- func (l *BasicLogger) Debug(format string, args ...interface{})
- func (l *BasicLogger) Error(format string, args ...interface{})
- func (l *BasicLogger) Fatal(format string, args ...interface{})
- func (l *BasicLogger) Info(format string, args ...interface{})
- func (l *BasicLogger) Warn(format string, args ...interface{})
- type Level
- type Logger
- type NullLogger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BasicLogger ¶
type BasicLogger struct {
// contains filtered or unexported fields
}
BasicLogger implements the Logger interface using the defined Level constants. The provided level is treated as the minimum. Any messages passed to a level that is at least the defined level will be printed.
Every log message is treated as a single line. If there is no newline at the end of the message, then one will be added.
func NewBasicLogger ¶
func NewBasicLogger(level Level, out io.Writer) (*BasicLogger, error)
NewBasicLogger constructs a new logger. An error will be returned if an invalid level is provided. If no output writer is provided, then os.Stdout will be used.
func (*BasicLogger) Debug ¶
func (l *BasicLogger) Debug(format string, args ...interface{})
Logs at the Debug level.
func (*BasicLogger) Error ¶
func (l *BasicLogger) Error(format string, args ...interface{})
Logs at the Error level.
func (*BasicLogger) Fatal ¶
func (l *BasicLogger) Fatal(format string, args ...interface{})
Logs at the Fatal level then calls os.Exit(1).
func (*BasicLogger) Info ¶
func (l *BasicLogger) Info(format string, args ...interface{})
Logs at the Info level.
func (*BasicLogger) Warn ¶
func (l *BasicLogger) Warn(format string, args ...interface{})
Logs at the Warn level.
type Level ¶
type Level int
Level represents a logging level. This restricts the logger to print only messages with at least this level.
func ParseLevel ¶
ParseLevel converts a string to the corresponding Level. Comparisons are case insensitive. If an unknown level is provided, then an error will be returned.
type Logger ¶
type Logger interface { // Logs at the Debug level. Debug(format string, args ...interface{}) // Logs at the Info level. Info(format string, args ...interface{}) // Logs at the Warn level. Warn(format string, args ...interface{}) // Logs at the Error level. Error(format string, args ...interface{}) // Logs at the Fatal level then calls os.Exit(1). Fatal(format string, args ...interface{}) }
Logger represents a standard level logging interface. Every method logs the provided message using fmt.Printf with a timestamp and level prefix. Fatal logs the message like the other methods, but calls os.Exit(1) afterwards.
type NullLogger ¶ added in v0.2.0
type NullLogger struct{}
NullLogger is a logger that does nothing. All log statements, regardless of level, will be ignored. Note that calling Fatal will still cause the process to exit.
func NewNullLogger ¶ added in v0.2.0
func NewNullLogger() NullLogger
func (NullLogger) Debug ¶ added in v0.2.0
func (NullLogger) Debug(format string, args ...interface{})
Logs at the Debug level.
func (NullLogger) Error ¶ added in v0.2.0
func (NullLogger) Error(format string, args ...interface{})
Logs at the Error level.
func (NullLogger) Fatal ¶ added in v0.2.0
func (NullLogger) Fatal(format string, args ...interface{})
Logs at the Fatal level then calls os.Exit(1).
func (NullLogger) Info ¶ added in v0.2.0
func (NullLogger) Info(format string, args ...interface{})
Logs at the Info level.
func (NullLogger) Warn ¶ added in v0.2.0
func (NullLogger) Warn(format string, args ...interface{})
Logs at the Warn level.