Documentation ¶
Overview ¶
Package raftlog implements a simple logging package. It defines a type, Logger, with methods for formatting output. It also has a predefined 'standard' Logger accessible through helper functions Info[f], Warning[f], Error[f], Fatal[f], and Panic[f], which are easier to use than creating a Logger manually. That logger writes to standard error and prints the date and time of each logged message. Every log message is output on a separate line: if the message being printed does not end in a newline, the logger will add one. The Fatal functions call os.Exit(1) after writing the log message. The Panic functions call panic after writing the log message.
Index ¶
- Variables
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Warning(v ...interface{})
- func Warningf(format string, v ...interface{})
- type Logger
- type Verbose
Constants ¶
This section is empty.
Variables ¶
DefaultLogger define the standard logger used by the package-level output functions.
Functions ¶
func Error ¶
func Error(v ...interface{})
Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf. A newline is appended if the last character of format is not already a newline.
func Fatal ¶
func Fatal(v ...interface{})
Fatal logs to the FATAL, ERROR, WARNING, and INFO logs followed by a call to os.Exit(1). Arguments are handled in the manner of fmt.Println.
func Fatalf ¶
func Fatalf(format string, v ...interface{})
Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs followed by a call to os.Exit(1). Arguments are handled in the manner of fmt.Printf. A newline is appended if the last character of format is not already a newline.
func Info ¶
func Info(v ...interface{})
Info logs to INFO log. Arguments are handled in the manner of fmt.Println.
func Infof ¶
func Infof(format string, v ...interface{})
Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf. A newline is appended if the last character of format is not already a newline.
func Panic ¶
func Panic(v ...interface{})
Panic logs to the PANIC, FATAL, ERROR, WARNING, and INFO logs followed by a call to panic(). Arguments are handled in the manner of fmt.Println.
func Panicf ¶
func Panicf(format string, v ...interface{})
Panicf logs to the PANIC, ERROR, WARNING, and INFO logs followed by a call to panic(). Arguments are handled in the manner of fmt.Printf. A newline is appended if the last character of format is not already a newline.
Types ¶
type Logger ¶
type Logger interface { // Info logs to INFO log. Arguments are handled in the manner of fmt.Println. Info(...interface{}) // Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf. // A newline is appended if the last character of format is not // already a newline. Infof(string, ...interface{}) // Warning logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Println. Warning(...interface{}) // Warningf logs to the WARNING and INFO logs.. Arguments are handled in the manner of fmt.Printf. // A newline is appended if the last character of format is not // already a newline. Warningf(string, ...interface{}) // Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print. Error(...interface{}) // Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf. // A newline is appended if the last character of format is not // already a newline. Errorf(string, ...interface{}) // Fatal logs to the FATAL, ERROR, WARNING, and INFO logs followed by a call to os.Exit(1). // Arguments are handled in the manner of fmt.Println. Fatal(...interface{}) // Fatal logs to the FATAL, ERROR, WARNING, and INFO logs followed by a call to os.Exit(1). // Arguments are handled in the manner of fmt.Printf. // A newline is appended if the last character of format is not // already a newline. Fatalf(string, ...interface{}) // Panic logs to the PANIC, FATAL, ERROR, WARNING, and INFO logs followed by a call to panic(). // Arguments are handled in the manner of fmt.Println. Panic(...interface{}) // Panic logs to the PANIC, ERROR, WARNING, and INFO logs followed by a call to panic(). // Arguments are handled in the manner of fmt.Printf. // A newline is appended if the last character of format is not // already a newline. Panicf(string, ...interface{}) // V reports whether verbosity at the call site is at least the requested level. // The returned value is a interface of type Verbose, which implements Info, Warning // and Error. These methods will write to the log if called. // Thus, one may write either // if logger.V(2).Enabled() { logger.Info("log this") } // or // logger.V(2).Info("log this"). V(l int) Verbose }
Logger represents an active logging object that generates lines of output to an io.Writer.
func New ¶
New create new logger from the given writers and verbosity. Each severity must have its own writer, if len of writers less than num of severity New will use last writer to fulfill missings. Otherwise, New will use os.Stderr as default.
Use io.Discard to suppress message repetition to all lower writers.
info := os.Stderr warn := io.Discard New(1, "", info, warn)
Use io.Discard in all lower writer's to set desired severity.
info := io.Discard warn := io.Discard err := os.Stderr .... New(1, "", info, warn, err)
Note: a messages of a given severity are logged not only in the writer for that severity, but also in all writer's of lower severity. E.g., a message of severity FATAL will be logged to the writers of severity FATAL, ERROR, WARNING, and INFO.
type Verbose ¶
type Verbose interface { // Enabled will return true if this log level is enabled, guarded by the value // of v. // See the documentation of V for usage. Enabled() bool // Info logs to INFO log. Arguments are handled in the manner of fmt.Println. Info(...interface{}) // Infof logs to INFO log. Arguments are handled in the manner of fmt.Printf. // A newline is appended if the last character of format is not // already a newline. Infof(string, ...interface{}) // Warning logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Println. Warning(...interface{}) // Warningf logs to the WARNING and INFO logs.. Arguments are handled in the manner of fmt.Printf. // A newline is appended if the last character of format is not // already a newline. Warningf(string, ...interface{}) // Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print. Error(...interface{}) // Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf. // A newline is appended if the last character of format is not // already a newline. Errorf(string, ...interface{}) }
Verbose is a boolean type that implements some of logger func (like Infof) etc. See the documentation of V for more information.
func V ¶
V reports whether verbosity at the call site is at least the requested level. The returned value is a interface of type Verbose, which implements Info, Warning and Error. These methods will write to the log if called. Thus, one may write either
if logger.V(2).Enabled() { logger.Info("log this") }
or
logger.V(2).Info("log this").