logging
v0.0.0-20180629182703-207764b19fe8
Documentation
pkg.go.dev ↗Constants
INVALID (7 declarations)
const ( INVALID = -1 // not a valid logging level, returned by LevelFromString DEBUG = iota // messages printed with this level have a "DEBUG:" prefix INFO // messages printed with this level have a "INFO:" prefix WARNING // messages printed with this level have a "WARNING:" prefix ERROR // messages printed with this level have a "ERROR:" prefix FATAL // messages printed with this level have a "FATAL:" prefix, calls os.Exit(1) NOTSET // prints nothing from the logger )
These constants define the level of logging
Ldate (9 declarations)
const ( Ldate = 1 << iota // the date in the local time zone: 2009/01/23 Ltime // the time in the local time zone: 01:23:23 Lmicroseconds // microsecond resolution: 01:23:23.123123. assumes Ltime. Llongfile // full file name and line number: /a/b/c/d.go:23 Lshortfile // final file name element and line number: d.go:23. overrides Llongfile LUTC // if Ldate or Ltime is set, use UTC rather than the local time zone Ltruncate // truncate up to logger.maxmsglength Llevel // write logging level LstdFlags = Ldate | Ltime // initial values for the standard logger )
These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. There is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,
2009/01/23 01:23:23 message
while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,
2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message
Functions
Debug
func Debug(v ...interface{})
Debug calls Debug on the default logger
Debugf
func Debugf(format string, v ...interface{})
Debugf calls Debug on the default logger
Error
func Error(v ...interface{})
Error calls Debug on the default logger
Errorf
func Errorf(format string, v ...interface{})
Errorf calls Debug on the default logger
Fatal
func Fatal(v ...interface{})
Fatal calls Debug on the default logger
Fatalf
func Fatalf(format string, v ...interface{})
Fatalf calls Debug on the default logger
Info
func Info(v ...interface{})
Info calls Debug on the default logger
Infof
func Infof(format string, v ...interface{})
Infof calls Debug on the default logger
LevelFromString
func LevelFromString(name string) int
LevelFromString returns the level value for the given level name
SetFlags
func SetFlags(flags int)
SetFlags set the default logger flags
SetLevel
func SetLevel(level int)
SetLevel set the level of the default logger
SetOutput
func SetOutput(w io.Writer)
SetOutput set the output of the default logger
SetPrefix
func SetPrefix(prefix string)
SetPrefix set the prefix of the default logger
Warning
func Warning(v ...interface{})
Warning calls Debug on the default logger
Warningf
func Warningf(format string, v ...interface{})
Warningf calls Debug on the default logger
Types
Logger
type Logger struct {
// contains filtered or unexported fields
}
Logger redefine log.Logger and adds leveling
New
func New(out io.Writer, prefix string, flags, level int) *Logger
New creates a new Logger. The out variable sets the destination to which log data will be written. The prefix appears at the beginning of each generated log line. The flag argument defines the logging properties. The level argument defines the logger level of logging
Logger.Debug
func (l *Logger) Debug(v ...interface{})
Debug calls logger.Output to print to the logger if logging level is inferior or equal to INFO. Arguments are handled in the manner of fmt.Print with DEBUG: as message prefix
Logger.Debugf
func (l *Logger) Debugf(format string, v ...interface{})
Debugf calls logger.Output to print to the logger if logging level is inferior or equal to DEBUG. Arguments are handled in the manner of fmt.Printf with DEBUG: as message prefix
Logger.Error
func (l *Logger) Error(v ...interface{})
Error calls logger.Output to print to the logger if logging level is inferior or equal to ERROR. Arguments are handled in the manner of fmt.Print with ERROR: as message prefix
Logger.Errorf
func (l *Logger) Errorf(format string, v ...interface{})
Errorf calls logger.Output to print to the logger if logging level is inferior or equal to ERROR. Arguments are handled in the manner of fmt.Printf with ERROR: as message prefix
Logger.Fatal
func (l *Logger) Fatal(v ...interface{})
Fatal calls logger.Output to print to the logger if logging level is inferior or equal to FATAL. Arguments are handled in the manner of fmt.Print with FATAL: as message prefix
Logger.Fatalf
func (l *Logger) Fatalf(format string, v ...interface{})
Fatalf calls logger.Output to print to the logger if logging level is inferior or equal to FATAL. Arguments are handled in the manner of fmt.Printf with FATAL: as message prefix and followed by a call to os.Exit(1)
Logger.Info
func (l *Logger) Info(v ...interface{})
Info calls logger.Output to print to the logger if logging level is inferior or equal to INFO. Arguments are handled in the manner of fmt.Print with INFO: as message prefix
Logger.Infof
func (l *Logger) Infof(format string, v ...interface{})
Infof calls logger.Output to print to the logger if logging level is inferior or equal to INFO. Arguments are handled in the manner of fmt.Printf with INFO: as message prefix
Logger.Output
func (l *Logger) Output(calldepth int, s string, level int) error
Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.
Logger.SetFlags
func (l *Logger) SetFlags(flags int)
SetFlags sets the logger properties
Logger.SetLevel
func (l *Logger) SetLevel(level int)
SetLevel checks for level value and sets the logging level
Logger.SetOutput
func (l *Logger) SetOutput(w io.Writer)
SetOutput sets the output destination for the logger.
Logger.SetPrefix
func (l *Logger) SetPrefix(prefix string)
SetPrefix sets the output destination for the logger.
Logger.Warning
func (l *Logger) Warning(v ...interface{})
Warning calls logger.Output to print to the logger if logging level is inferior or equal to WARNING. Arguments are handled in the manner of fmt.Print with WARNING: as message prefix
Logger.Warningf
func (l *Logger) Warningf(format string, v ...interface{})
Warningf calls logger.Output to print to the logger if logging level is inferior or equal to WARNING. Arguments are handled in the manner of fmt.Printf with WARNING: as message prefix