Documentation
¶
Index ¶
- func CloseTestLog()
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Log(level LogLevel, v ...interface{})
- func Logf(level LogLevel, format string, v ...interface{})
- func SetDefaultLogger(logger *Logger)
- func SetTestLog(t TestLogInterface)
- func Warning(v ...interface{})
- func Warningf(format string, v ...interface{})
- type AferoHandler
- type ConsoleHandler
- type DiscardHandler
- type FileHandler
- type Handler
- type LevelFilter
- type LogEntry
- type LogLevel
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) GetHandler() Handler
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Log(level LogLevel, v ...interface{})
- func (l *Logger) LogEntry(logEntry LogEntry) error
- func (l *Logger) Logf(level LogLevel, format string, v ...interface{})
- func (l *Logger) SetHandler(handler Handler)
- func (l *Logger) Warning(v ...interface{})
- func (l *Logger) Warningf(format string, v ...interface{})
- type MemoryHandler
- type SafeHandler
- type StandardLogHandler
- type StandardLogger
- func (l *StandardLogger) Fatal(v ...interface{})
- func (l *StandardLogger) Fatalf(format string, v ...interface{})
- func (l *StandardLogger) Fatalln(v ...interface{})
- func (l *StandardLogger) Panic(v ...interface{})
- func (l *StandardLogger) Panicf(format string, v ...interface{})
- func (l *StandardLogger) Panicln(v ...interface{})
- func (l *StandardLogger) Print(v ...interface{})
- func (l *StandardLogger) Printf(format string, v ...interface{})
- func (l *StandardLogger) Println(v ...interface{})
- type TestHandler
- type TestLogInterface
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloseTestLog ¶ added in v0.1.0
func CloseTestLog()
CloseTestLog at the end of the test otherwise the logger will keep a reference on t. For a description on how to use it, see SetTestLog()
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf sends error information to the console
func Log ¶
func Log(level LogLevel, v ...interface{})
Log sends a log entry with the specified level
func SetDefaultLogger ¶
func SetDefaultLogger(logger *Logger)
SetDefaultLogger sets the logger used when using the package methods
func SetTestLog ¶
func SetTestLog(t TestLogInterface)
SetTestLog install a test logger as the default logger. A test logger redirects all logs sent through the package methods to the Log/Logf methods of your test
IMPORTANT: don't forget to CloseTestLog() at the end of the test
Example:
func TestLog(t *testing.T) {
SetTestLog(t)
defer CloseTestLog()
// These two calls are equivalent:
clog.Debug("debug message")
t.Log("debug message")
}
Types ¶
type AferoHandler ¶
type AferoHandler struct {
*StandardLogHandler
// contains filtered or unexported fields
}
AferoHandler logs messages to a file
func NewAferoHandler ¶
NewAferoHandler creates a new file logger through afero Fs.
Remember to Close() the logger at the end
func (*AferoHandler) Close ¶
func (l *AferoHandler) Close()
Close the logfile when no longer needed.
Please note this method reinstate the standard console output as default
type ConsoleHandler ¶
type ConsoleHandler struct {
// contains filtered or unexported fields
}
ConsoleHandler logs messages to the console (in colour)
func NewConsoleHandler ¶
func NewConsoleHandler(prefix string, flag int) *ConsoleHandler
NewConsoleHandler creates a new handler to send logs to the console
func (*ConsoleHandler) Colouring ¶
func (l *ConsoleHandler) Colouring(colouring bool)
Colouring activate of deactivate displaying messages in colour in the console
func (*ConsoleHandler) LogEntry ¶
func (l *ConsoleHandler) LogEntry(logEntry LogEntry) error
LogEntry sends a log entry with the specified level
func (*ConsoleHandler) SetTheme ¶
func (l *ConsoleHandler) SetTheme(theme string)
SetTheme sets the dark or light theme
type DiscardHandler ¶
type DiscardHandler struct{}
DiscardHandler forgets any log message
func (*DiscardHandler) LogEntry ¶
func (l *DiscardHandler) LogEntry(LogEntry) error
LogEntry discards the LogEntry
type FileHandler ¶
type FileHandler struct {
*StandardLogHandler
// contains filtered or unexported fields
}
FileHandler logs messages to a file
func NewFileHandler ¶
func NewFileHandler(filename string, prefix string, flag int) (*FileHandler, error)
NewFileHandler creates a new file logger
Remember to Close() the logger at the end
func (*FileHandler) Close ¶
func (l *FileHandler) Close()
Close the logfile when no longer needed
please note this method reinstate the standard console output as default
type Handler ¶
Handler for a logger.
The LogEntry method should return an error if the handler didn't manage to save the log (file, remote, etc.) It's up to the parent handler to take action on the error: the default Logger is always going to ignore it.
type LevelFilter ¶
type LevelFilter struct {
// contains filtered or unexported fields
}
LevelFilter is a log middleware that is only passing log entries of level >= minimum level
func NewLevelFilter ¶
func NewLevelFilter(minLevel LogLevel, destination Handler) *LevelFilter
NewLevelFilter creates a new LevelFilter handler passing log entries to destination if level >= minimum level
func (*LevelFilter) GetHandler ¶
func (l *LevelFilter) GetHandler() Handler
GetHandler returns the current handler used by the filter
func (*LevelFilter) LogEntry ¶
func (l *LevelFilter) LogEntry(logEntry LogEntry) error
LogEntry the LogEntry
func (*LevelFilter) SetHandler ¶
func (l *LevelFilter) SetHandler(handler Handler)
SetHandler sets a new handler for the filter
func (*LevelFilter) SetLevel ¶
func (l *LevelFilter) SetLevel(minLevel LogLevel)
SetLevel changes the minimum level the log entries are going to be sent to the destination logger
type LogEntry ¶
type LogEntry struct {
Calldepth int // Calldepth is used to calculate the right place where we called the log method
Level LogLevel // Debug, Info, Warning or Error
Format string // Format for *printf (leave blank for *print)
Values []interface{} // Values for *print and *printf
}
LogEntry represents a log entry
func (LogEntry) GetMessage ¶
GetMessage returns the formatted message from Format & Values
func (LogEntry) GetMessageWithLevelPrefix ¶
GetMessageWithLevelPrefix returns the formatted message from Format & Values prefixed with the level name
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger frontend
func GetDefaultLogger ¶
func GetDefaultLogger() *Logger
GetDefaultLogger returns the logger used when using the package methods
func NewConsoleLogger ¶
func NewConsoleLogger() *Logger
NewConsoleLogger is a shortcut to create a Logger with a ConsoleHandler
func NewFilteredConsoleLogger ¶
NewFilteredConsoleLogger is a shortcut to create a Logger with a FilteredHandler sending to a ConsoleHandler
func (*Logger) Error ¶
func (l *Logger) Error(v ...interface{})
Error sends error information to the console
func (*Logger) GetHandler ¶
GetHandler returns the current handler used by the logger
func (*Logger) SetHandler ¶
SetHandler sets a new handler for the logger
type MemoryHandler ¶
type MemoryHandler struct {
// contains filtered or unexported fields
}
MemoryHandler save messages in memory (useful for unit testing).
func NewMemoryHandler ¶
func NewMemoryHandler() *MemoryHandler
NewMemoryHandler creates a new MemoryHandler that keeps logs in memory.
func (*MemoryHandler) LogEntry ¶
func (l *MemoryHandler) LogEntry(logEntry LogEntry) error
LogEntry keep the message in memory.
type SafeHandler ¶
type SafeHandler struct {
// contains filtered or unexported fields
}
SafeHandler sends logs to an alternate destination when the primary destination fails
func NewSafeHandler ¶
func NewSafeHandler(primary, backup Handler) *SafeHandler
NewSafeHandler creates a handler that redirects logs to a backup handler when the primary fails
func (*SafeHandler) LogEntry ¶
func (l *SafeHandler) LogEntry(logEntry LogEntry) error
LogEntry send messages to primaryHandler first, then to backupHandler if it had fail
type StandardLogHandler ¶
type StandardLogHandler struct {
// contains filtered or unexported fields
}
StandardLogHandler send messages to a io.Writer using the standard logger.
func NewStandardLogHandler ¶
func NewStandardLogHandler(out io.Writer, prefix string, flag int) *StandardLogHandler
NewStandardLogHandler creates a handler to send the logs to io.Writer through a standard logger.
func (*StandardLogHandler) LogEntry ¶
func (l *StandardLogHandler) LogEntry(logEntry LogEntry) error
LogEntry sends a log entry with the specified level.
func (*StandardLogHandler) SetOutput ¶
func (l *StandardLogHandler) SetOutput(output io.Writer)
SetOutput sets the output destination for the logger.
type StandardLogger ¶ added in v0.2.0
type StandardLogger struct {
// contains filtered or unexported fields
}
StandardLogger can be used when you need to plug-in a standard library logger (via an interface)
func NewStandardLogger ¶ added in v0.2.0
func NewStandardLogger(level LogLevel, handler Handler) *StandardLogger
NewStandardLogger creates a new logger that can be used in place of a standard library logger (via an interface)
func (*StandardLogger) Fatal ¶ added in v0.2.0
func (l *StandardLogger) Fatal(v ...interface{})
Fatal is equivalent to l.Print() followed by a call to os.Exit(1).
func (*StandardLogger) Fatalf ¶ added in v0.2.0
func (l *StandardLogger) Fatalf(format string, v ...interface{})
Fatalf is equivalent to l.Printf() followed by a call to os.Exit(1).
func (*StandardLogger) Fatalln ¶ added in v0.2.0
func (l *StandardLogger) Fatalln(v ...interface{})
Fatalln is equivalent to l.Println() followed by a call to os.Exit(1).
func (*StandardLogger) Panic ¶ added in v0.2.0
func (l *StandardLogger) Panic(v ...interface{})
Panic is equivalent to l.Print() followed by a call to panic().
func (*StandardLogger) Panicf ¶ added in v0.2.0
func (l *StandardLogger) Panicf(format string, v ...interface{})
Panicf is equivalent to l.Printf() followed by a call to panic().
func (*StandardLogger) Panicln ¶ added in v0.2.0
func (l *StandardLogger) Panicln(v ...interface{})
Panicln is equivalent to l.Println() followed by a call to panic().
func (*StandardLogger) Print ¶ added in v0.2.0
func (l *StandardLogger) Print(v ...interface{})
Print writes the output for a logging event. Arguments are handled in the manner of fmt.Print. A newline is appended if the last character of s is not already a newline.
func (*StandardLogger) Printf ¶ added in v0.2.0
func (l *StandardLogger) Printf(format string, v ...interface{})
Printf writes the output for a logging event. Arguments are handled in the manner of fmt.Printf. A newline is appended if the last character of s is not already a newline.
func (*StandardLogger) Println ¶ added in v0.2.0
func (l *StandardLogger) Println(v ...interface{})
Println writes the output for a logging event. Arguments are handled in the manner of fmt.Println.
type TestHandler ¶
type TestHandler struct {
// contains filtered or unexported fields
}
TestHandler redirects all the logs to the testing framework logger
func NewTestHandler ¶
func NewTestHandler(t TestLogInterface) *TestHandler
NewTestHandler instantiates a new logger redirecting to the test framework logger or any other implementation of TestLogInterface for that matter
func (*TestHandler) LogEntry ¶
func (l *TestHandler) LogEntry(logEntry LogEntry) error
LogEntry sends a log entry with the specified level
type TestLogInterface ¶
type TestLogInterface interface {
Log(args ...interface{})
Logf(format string, args ...interface{})
}
TestLogInterface for use with testing.B or testing.T
