Documentation

Overview

    Package log provides simple level logging. Log output is implemented by an outputter, which by default outputs to Go's logging package. Alternative implementations (e.g., vlog, glog) can provide their own outputter implementation so that logging output is unified.

    The package can be used as a replacement for Go's standard logging package; the behavior of its toplevel functions are identical with the default configuration.

    If the application wishes to configure logging levels by standard flags, it should call log.AddFlags before flag.Parse. log.AddFlags.

    Note that this package is intended to bridge Go's standard log package with Vanadium's (vlog). As we transition away from vlog, we can simplify this package by removing the Outputter interface.

    Index

    Constants

    View Source
    const (
    	Ldate         = golog.Ldate         // the date in the local time zone: 2009/01/23
    	Ltime         = golog.Ltime         // the time in the local time zone: 01:23:23
    	Lmicroseconds = golog.Lmicroseconds // microsecond resolution: 01:23:23.123123.  assumes Ltime.
    	Llongfile     = golog.Llongfile     // full file name and line number: /a/b/c/d.go:23
    	Lshortfile    = golog.Lshortfile    // final file name element and line number: d.go:23. overrides Llongfile
    	LUTC          = golog.LUTC          // if Ldate or Ltime is set, use UTC rather than the local time zone
    	LstdFlags     = Ldate | Ltime       // initial values for the standard logger
    )
    View Source
    const (
    	// Off never outputs messages.
    	Off = Level(-3)
    	// Error outputs error messages.
    	Error = Level(-2)
    	// Info outputs informational messages. This is the standard
    	// logging level.
    	Info = Level(0)
    	// Debug outputs messages intended for debugging and development,
    	// not for regular users.
    	Debug = Level(1)
    )

    Variables

    This section is empty.

    Functions

    func AddFlags

    func AddFlags()

      AddFlags adds a standard log level flags to the flag.CommandLine flag set.

      func At

      func At(level Level) bool

        At returns whether the logger is currently logging at the provided level.

        func Fatal

        func Fatal(v ...interface{})

          Fatal formats a message in the manner of fmt.Sprint, outputs it at the error level to the current outputter and then calls os.Exit(1).

          func Fatalf

          func Fatalf(format string, v ...interface{})

            Fatalf formats a message in the manner of fmt.Sprintf, outputs it at the error level to the current outputter and then calls os.Exit(1).

            func Output

            func Output(calldepth int, level Level, s string) error

              Output outputs a log message to the current outputter at the provided level and call depth.

              func Outputf

              func Outputf(out Outputter, level Level, format string, v ...interface{})

                Outputf is formats a message using fmt.Sprintf and outputs it to the provided logger at the provided level.

                func Panic

                func Panic(v ...interface{})

                  Panic formats a message in the manner of fmt.Sprint, outputs it at the error level to the current outputter and then panics.

                  func Panicf

                  func Panicf(format string, v ...interface{})

                    Panicf formats a message in the manner of fmt.Sprintf, outputs it at the error level to the current outputter and then panics.

                    func Print

                    func Print(v ...interface{})

                      Print formats a message in the manner of fmt.Sprint and outputs it at the Info level to the current outputter.

                      func Printf

                      func Printf(format string, v ...interface{})

                        Printf formats a message in the manner of fmt.Sprintf and outputs it at the Info level to the current outputter.

                        func SetFlags

                        func SetFlags(flag int)

                          SetFlags sets the output flags for the Go standard logger.

                          func SetLevel

                          func SetLevel(level Level)

                            SetLevel sets the log level for the Go standard logger. It should be called once at the beginning of a program's main.

                            func SetOutput

                            func SetOutput(w io.Writer)

                              SetOutput sets the output destination for the Go standard logger.

                              func SetPrefix

                              func SetPrefix(prefix string)

                                SetPrefix sets the output prefix for the Go standard logger.

                                Types

                                type Level

                                type Level int

                                  A Level is a log verbosity level. Increasing levels decrease in priority and (usually) increase in verbosity: if the outputter is logging at level L, then all messages with level M <= L are outputted.

                                  func (Level) Print

                                  func (l Level) Print(v ...interface{})

                                    Print formats a message in the manner of fmt.Sprint and outputs it at level l to the current outputter.

                                    func (Level) Printf

                                    func (l Level) Printf(format string, v ...interface{})

                                      Printf formats a message in the manner of fmt.Sprintf and outputs it at level l to the current outputter.

                                      func (Level) Println

                                      func (l Level) Println(v ...interface{})

                                        Printkln formats a message in the manner of fmt.Sprintln and outputs it at level l to the current outputter.

                                        func (Level) String

                                        func (l Level) String() string

                                          String returns the string representation of the level l.

                                          type Logger

                                          type Logger = golog.Logger

                                            Logger is an alternative spelling of "log".Logger.

                                            type Outputter

                                            type Outputter interface {
                                            	// Level returns the level at which the outputter is accepting
                                            	// messages.
                                            	Level() Level
                                            
                                            	// Output writes the provided message to the outputter at the
                                            	// provided calldepth and level. The message is dropped by
                                            	// the outputter if it is not logging at the desired level.
                                            	Output(calldepth int, level Level, s string) error
                                            }

                                              An Outputter provides a destination for leveled log output.

                                              func GetOutputter

                                              func GetOutputter() Outputter

                                                GetOutputter returns the current outputter used by the log package.

                                                func SetOutputter

                                                func SetOutputter(newOut Outputter) Outputter

                                                  SetOutputter provides a new outputter for use in the log package. SetOutputter should not be called concurrently with any log output, and is thus suitable to be called only upon program initialization. SetOutputter returns the old outputter.

                                                  Source Files