Documentation
¶
Index ¶
- type Color
- type FileHandler
- type Handler
- type LogLevel
- type Logger
- func (l *Logger) AddHandler(n string, h Handler)
- func (l *Logger) Alert(m string)
- func (l *Logger) Alertf(m string, v ...interface{})
- func (l *Logger) Close()
- func (l *Logger) Critical(m string)
- func (l *Logger) Criticalf(m string, v ...interface{})
- func (l *Logger) Debug(m string)
- func (l *Logger) Debugf(m string, v ...interface{})
- func (l *Logger) Emergency(m string)
- func (l *Logger) Emergencyf(m string, v ...interface{})
- func (l *Logger) Error(m string)
- func (l *Logger) Errorf(m string, v ...interface{})
- func (l *Logger) Fatal(m string)
- func (l *Logger) Fatalf(m string, v ...interface{})
- func (l *Logger) GetHandler(n string) Handler
- func (l *Logger) Info(m string)
- func (l *Logger) Infof(m string, v ...interface{})
- func (l *Logger) Log(level LogLevel, msg string)
- func (l *Logger) Name() string
- func (l *Logger) Notice(m string)
- func (l *Logger) Noticef(m string, v ...interface{})
- func (l *Logger) RemoveHandler(n string)
- func (l *Logger) Warning(m string)
- func (l *Logger) Warningf(m string, v ...interface{})
- type StdoutHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileHandler ¶
type FileHandler struct {
// contains filtered or unexported fields
}
FileHandler writes log messages to a file to a directory
func NewFileHandler ¶
func NewFileHandler(path string) (*FileHandler, error)
NewFileHandler takes the path and returns a FileHandler. If the path exists, file or directory mode will be Determined by what path is. If it doesn't exist, the mode will be file if path has an extension, otherwise it will be directory. In file mode, all log messages are written to a single file. In directory mode, each level is written to it's own file.
func (*FileHandler) Handles ¶
func (f *FileHandler) Handles(l LogLevel) bool
Handles returns whether the handler handles log level l.
func (*FileHandler) SetLevel ¶
func (f *FileHandler) SetLevel(l LogLevel)
SetLevel will set both the minimum and maximum log levels to l. This makes the handler only respond to the single level l.
func (*FileHandler) SetMaxLevel ¶
func (f *FileHandler) SetMaxLevel(l LogLevel)
SetMaxLevel will set the maximum log level the handler will handle.
func (*FileHandler) SetMinLevel ¶
func (f *FileHandler) SetMinLevel(l LogLevel)
SetMinLevel will set the minimum log level the handler will handle.
func (*FileHandler) WriteLog ¶
func (f *FileHandler) WriteLog(l LogLevel, name, msg string)
WriteLog will write the log message to a file.
type Handler ¶
type Handler interface {
// Handles returns if it wants to handle a particular log level
// This can be used to suppress the higher log levels in production
Handles(level LogLevel) bool
// WriteLog actually logs the message using any system the Handler wishes.
// The Handler must accept a LogLevel l which can be used for furthur processing
// of specific levels, the name of the logger, and the log message.
WriteLog(l LogLevel, name, message string)
// Close is used to give a handler a chance to close any open resources
Close()
}
A Handler is an object that can be used by the Logger to log a message
type LogLevel ¶
type LogLevel int
LogLevel is used to compare levels in a consistant manner
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
A Logger takes a message and writes it to as many handlers as possible
func Classic ¶
Classic creates a logger with both the StdoutHandler and FileHandlers already added. If path is "", the FileHandler is not added. This is meant for convenience. The handlers use their default min and max levels. The StdoutHandler is named "stdout" and the FileHandler is named "file"
func Get ¶
Get returns an existing logger with name n or a new Logger if one doesn't exist. To ensure Loggers are never overwritten, it may be safer to always use this method.
func New ¶
New will create a new Logger with name n. If with the same name already exists, it will be replaced with the new logger.
func (*Logger) AddHandler ¶
AddHandler will add Handler h to the logger named n. If a handler with the same name already exists, it will be overwritten.
func (*Logger) Close ¶
func (l *Logger) Close()
Close calls Close() on all the handlers then removes itself from the logger registry
func (*Logger) Emergencyf ¶
Emergencyf - Log formatted Emergency message
func (*Logger) GetHandler ¶
GetHandler will return handler with name n or nil if it doesn't exist.
func (*Logger) Log ¶
Log is the generic function to log a message with the handlers. All other logging functions are simply wrappers around this.
func (*Logger) RemoveHandler ¶
RemoveHandler will remove the handler named n.
type StdoutHandler ¶
type StdoutHandler struct {
// contains filtered or unexported fields
}
StdoutHandler writes log message to standard out It even uses color!
func NewStdoutHandler ¶
func NewStdoutHandler() *StdoutHandler
NewStdoutHandler creates a new StdoutHandler, surprise!
func (*StdoutHandler) Handles ¶
func (s *StdoutHandler) Handles(l LogLevel) bool
Handles returns whether the handler handles log level l.
func (*StdoutHandler) SetLevel ¶
func (s *StdoutHandler) SetLevel(l LogLevel)
SetLevel will set both the minimum and maximum log levels to l. This makes the handler only respond to the single level l.
func (*StdoutHandler) SetMaxLevel ¶
func (s *StdoutHandler) SetMaxLevel(l LogLevel)
SetMaxLevel will set the maximum log level the handler will handle.
func (*StdoutHandler) SetMinLevel ¶
func (s *StdoutHandler) SetMinLevel(l LogLevel)
SetMinLevel will set the minimum log level the handler will handle.
func (*StdoutHandler) WriteLog ¶
func (s *StdoutHandler) WriteLog(l LogLevel, name, msg string)
WriteLog writes the log message to standard output