Documentation ¶
Overview ¶
Package golog provides a customizable logging class which can be used as a standalone or as a building block for other loggers.
Basic example:
logger := golog.New(os.Stdout, log.Info) logger.Info("Connecting to the server...") logger.Errorf("Connection failed: %q", err)
Will output:
2014-04-02 18:09:15.862 INFO Connecting to the API... 2014-04-02 18:10:14.347 ERROR Connection failed (Server is unavailable).
Log*() functions can be used to avoid evaluating arguments when it is expensive and unnecessary:
logger.Debug("Memory usage: %s", getMemoryUsage()) if logger.LogDebug() { logger.Debug("Memory usage: %s", getMemoryUsage()) }
If debug logging is off getMemoryUsage() will be executed on the first line while it will not be executed on the second line.
Index ¶
- type Logger
- func (logger *Logger) Alert(args ...interface{})
- func (logger *Logger) Alertf(format string, args ...interface{})
- func (logger *Logger) Close() error
- func (logger *Logger) Critical(args ...interface{})
- func (logger *Logger) Criticalf(format string, args ...interface{})
- func (logger *Logger) Debug(args ...interface{})
- func (logger *Logger) Debugf(format string, args ...interface{})
- func (logger *Logger) Emergency(args ...interface{})
- func (logger *Logger) Emergencyf(format string, args ...interface{})
- func (logger *Logger) Error(args ...interface{})
- func (logger *Logger) Errorf(format string, args ...interface{})
- func (logger *Logger) Info(args ...interface{})
- func (logger *Logger) Infof(format string, args ...interface{})
- func (logger *Logger) Log(level log.Level, args ...interface{})
- func (logger *Logger) LogAlert() bool
- func (logger *Logger) LogCritical() bool
- func (logger *Logger) LogDebug() bool
- func (logger *Logger) LogEmergency() bool
- func (logger *Logger) LogError() bool
- func (logger *Logger) LogInfo() bool
- func (logger *Logger) LogLevel(level log.Level) bool
- func (logger *Logger) LogNotice() bool
- func (logger *Logger) LogWarning() bool
- func (logger *Logger) Logf(level log.Level, format string, args ...interface{})
- func (logger *Logger) Notice(args ...interface{})
- func (logger *Logger) Noticef(format string, args ...interface{})
- func (logger *Logger) Warning(args ...interface{})
- func (logger *Logger) Warningf(format string, args ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Logger ¶
type Logger struct { Formatter func(*bytes.Buffer, log.Level, ...interface{}) Writer func(io.Writer, []byte, log.Level) // contains filtered or unexported fields }
A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.
func New ¶
New creates a new Logger. The out variable sets the destination to which log data will be written. The threshold variable defines the level under which logging will be ignored.
func (*Logger) Alert ¶
func (logger *Logger) Alert(args ...interface{})
Alert logs with an alert level.
func (*Logger) Alertf ¶
Alertf logs with an alert level. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Close ¶
Close does nothing and is just here so that Logger satisfies the log.Logger interface.
func (*Logger) Critical ¶
func (logger *Logger) Critical(args ...interface{})
Critical logs with a critical level.
func (*Logger) Criticalf ¶
Criticalf logs with a critical level. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Debug ¶
func (logger *Logger) Debug(args ...interface{})
Debug logs with a debug level.
func (*Logger) Debugf ¶
Debugf logs with a debug level. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Emergency ¶
func (logger *Logger) Emergency(args ...interface{})
Emergency logs with an emergency level.
func (*Logger) Emergencyf ¶
Emergencyf logs with an emergency level. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Error ¶
func (logger *Logger) Error(args ...interface{})
Error logs with an error level.
func (*Logger) Errorf ¶
Errorf logs with an error level. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Infof ¶
Infof logs with an info level. Arguments are handled in the manner of fmt.Printf.
func (*Logger) LogCritical ¶
LogCritical returns true if the log level is at critical or lower.
func (*Logger) LogEmergency ¶
LogEmergency returns true if the log level is at emergency or lower.
func (*Logger) LogWarning ¶
LogWarning returns true if the log level is at warning or lower.
func (*Logger) Logf ¶
Logf logs at the level passed in argument. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Notice ¶
func (logger *Logger) Notice(args ...interface{})
Notice logs with a notice level.
func (*Logger) Noticef ¶
Noticef logs with a notice level. Arguments are handled in the manner of fmt.Printf.