Documentation ¶
Overview ¶
Package log implements a simple level logging package. It defines a type, Logger, with methods for formatting output at specific verbosity levels. It maintains API compatibility with the standard library "log" package by embedding a 'log.Logger' struct.
Index ¶
- Constants
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Debugln(v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Errorln(v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Fatalln(v ...interface{})
- func Flags() int
- func FormatLevel(lvl Level) string
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Infoln(v ...interface{})
- func Output(calldepth int, s string) error
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Panicln(v ...interface{})
- func Prefix() string
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func SetFlags(flag int)
- func SetLevel(l Level)
- func SetOutput(w io.Writer)
- func SetPrefix(prefix string)
- func Trace(v ...interface{})
- func Tracef(format string, v ...interface{})
- func Traceln(v ...interface{})
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- func Warnln(v ...interface{})
- func Writer() io.Writer
- type Level
- type Logger
- func (l *Logger) Debug(v ...interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Debugln(v ...interface{})
- func (l *Logger) Error(v ...interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Errorln(v ...interface{})
- func (l *Logger) Info(v ...interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Infoln(v ...interface{})
- func (l *Logger) Trace(v ...interface{})
- func (l *Logger) Tracef(format string, v ...interface{})
- func (l *Logger) Traceln(v ...interface{})
- func (l *Logger) Warn(v ...interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
- func (l *Logger) Warnln(v ...interface{})
- type ParseError
Examples ¶
Constants ¶
const ( Ldate = log.Ldate Ltime = log.Ltime Lmicroseconds = log.Lmicroseconds Llongfile = log.Llongfile Lshortfile = log.Lshortfile LUTC = log.LUTC LstdFlags = log.LstdFlags )
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
These variables are exported in order to maintain package API compatibility.
Variables ¶
This section is empty.
Functions ¶
func Debug ¶
func Debug(v ...interface{})
Debug prints to the standard logger if level is at least LevelDebug. Arguments are handled in the manner of fmt.Print.
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf prints to the standard logger if level is at least LevelDebug. Arguments are handled in the manner of fmt.Printf.
func Debugln ¶
func Debugln(v ...interface{})
Debugln prints to the standard logger if level is at least LevelDebug. Arguments are handled in the manner of fmt.Println.
func Error ¶
func Error(v ...interface{})
Error prints to the standard logger if level is at least LevelError. Arguments are handled in the manner of fmt.Print.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf prints to the standard logger if level is at least LevelError. Arguments are handled in the manner of fmt.Printf.
func Errorln ¶
func Errorln(v ...interface{})
Errorln prints to the standard logger if level is at least LevelError. Arguments are handled in the manner of fmt.Println.
func Fatal ¶
func Fatal(v ...interface{})
Fatal is equivalent to Print() followed by a call to os.Exit(1).
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf is equivalent to Printf() followed by a call to os.Exit(1).
func Fatalln ¶
func Fatalln(v ...interface{})
Fatalln is equivalent to Println() followed by a call to os.Exit(1).
func Info ¶
func Info(v ...interface{})
Info prints to the standard logger if level is at least LevelInfo. Arguments are handled in the manner of fmt.Print.
func Infof ¶
func Infof(format string, v ...interface{})
Infof prints to the standard logger if level is at least LevelInfo. Arguments are handled in the manner of fmt.Printf.
func Infoln ¶
func Infoln(v ...interface{})
Infoln prints to the standard logger if level is at least LevelInfo. Arguments are handled in the manner of fmt.Println.
func Output ¶
Output wraps a call to the standard logger's Output function for API compatibility.
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 the count of the number of frames to skip when computing the file name and line number if Llongfile or Lshortfile is set; a value of 1 will print the details for the caller of Output.
func Panic ¶
func Panic(v ...interface{})
Panic is equivalent to Print() followed by a call to panic().
func Panicf ¶
func Panicf(format string, v ...interface{})
Panicf is equivalent to Printf() followed by a call to panic().
func Panicln ¶
func Panicln(v ...interface{})
Panicln is equivalent to Println() followed by a call to panic().
func Print ¶
func Print(v ...interface{})
Print calls Print to print to the standard logger. Arguments are handled in the manner of fmt.Print.
func Printf ¶
func Printf(format string, v ...interface{})
Printf calls Printf to print to the standard logger. Arguments are handled in the manner of fmt.Printf.
func Println ¶
func Println(v ...interface{})
Println calls Println to print to the standard logger. Arguments are handled in the manner of fmt.Println.
func SetPrefix ¶
func SetPrefix(prefix string)
SetPrefix sets the output prefix for the standard logger.
func Trace ¶
func Trace(v ...interface{})
Trace prints to the standard logger if level is at least LevelTrace. Arguments are handled in the manner of fmt.Print.
func Tracef ¶
func Tracef(format string, v ...interface{})
Tracef prints to the standard logger if level is at least LevelTrace. Arguments are handled in the manner of fmt.Printf.
func Traceln ¶
func Traceln(v ...interface{})
Traceln prints to the standard logger if level is at least LevelTrace. Arguments are handled in the manner of fmt.Println.
func Warn ¶
func Warn(v ...interface{})
Warn prints to the standard logger if level is at least LevelWarn. Arguments are handled in the manner of fmt.Print.
func Warnf ¶
func Warnf(format string, v ...interface{})
Warnf prints to the standard logger if level is at least LevelWarn. Arguments are handled in the manner of fmt.Printf.
Types ¶
type Level ¶
type Level int
Level defines various levels of logging output
LevelError is the default level.
func CurrentLevel ¶
func CurrentLevel() Level
CurrentLevel returns the output level for the standard logger.
func ParseLevel ¶
ParseLevel returns the Level value represented by the string.
type Logger ¶
A Logger represents a standard library Logger, configured for output at a given verbosity level. See standard library log.Logger for detailed usage.
Example ¶
// Set the output to Stdout so it is captured by the example test harness. // Remember the standard library logger output is Stderr by default. log.SetOutput(os.Stdout) // Clear the prefix flags so we aren't dancing around timestamps. log.SetFlags(0) // Log! log.Error("Error messages are always logged") log.Debug("Debug messages are sometimes logged... but not this one...") // Raise the log level log.SetLevel(log.LevelDebug) // Log again! log.Debug("Now that the log level is set to Debug, this message is logged!") log.Trace("But we still have one more level that is not logged at the Debug level.")
Output: Error messages are always logged Now that the log level is set to Debug, this message is logged!
func New ¶
New creates a new Logger. The out, prefix and flag variables are passed directly to the embedded standard library log.New function. The level argument defines a minimum verbosity level.
func (*Logger) Debug ¶
func (l *Logger) Debug(v ...interface{})
Debug prints to the logger if level is at least LevelDebug. Arguments are handled in the manner of fmt.Print.
func (*Logger) Debugf ¶
Debugf prints to the logger if level is at least LevelDebug. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Debugln ¶
func (l *Logger) Debugln(v ...interface{})
Debugln prints to the logger if level is at least LevelDebug. Arguments are handled in the manner of fmt.Println.
func (*Logger) Error ¶
func (l *Logger) Error(v ...interface{})
Error prints to the logger if level is at least LevelError. Arguments are handled in the manner of fmt.Print.
func (*Logger) Errorf ¶
Errorf prints to the logger if level is at least LevelError. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Errorln ¶
func (l *Logger) Errorln(v ...interface{})
Errorln prints to the logger if level is at least LevelError. Arguments are handled in the manner of fmt.Println.
func (*Logger) Info ¶
func (l *Logger) Info(v ...interface{})
Info prints to the logger if level is at least LevelInfo. Arguments are handled in the manner of fmt.Print.
func (*Logger) Infof ¶
Infof prints to the logger if level is at least LevelInfo. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Infoln ¶
func (l *Logger) Infoln(v ...interface{})
Infoln prints to the logger if level is at least LevelInfo. Arguments are handled in the manner of fmt.Println.
func (*Logger) Trace ¶
func (l *Logger) Trace(v ...interface{})
Trace prints to the logger if level is at least LevelTrace. Arguments are handled in the manner of fmt.Print.
func (*Logger) Tracef ¶
Tracef prints to the logger if level is at least LevelTrace. Arguments are handled in the manner of fmt.Printf.
func (*Logger) Traceln ¶
func (l *Logger) Traceln(v ...interface{})
Traceln prints to the logger if level is at least LevelTrace. Arguments are handled in the manner of fmt.Println.
func (*Logger) Warn ¶
func (l *Logger) Warn(v ...interface{})
Warn prints to the logger if level is at least LevelWarn. Arguments are handled in the manner of fmt.Print.
type ParseError ¶
type ParseError string
A ParseError occurs when a string value cannot be parsed to a valid level.
func (ParseError) Error ¶
func (e ParseError) Error() string