base: github.com/grailbio/base/log Index | Files

package log

import "github.com/grailbio/base/log"

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

Package Files

golog.go log.go

Constants

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
)
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)
)

func AddFlags Uses

func AddFlags()

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

func At Uses

func At(level Level) bool

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

func Fatal Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func SetFlags(flag int)

SetFlags sets the output flags for the Go standard logger.

func SetLevel Uses

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 Uses

func SetOutput(w io.Writer)

SetOutput sets the output destination for the Go standard logger.

func SetPrefix Uses

func SetPrefix(prefix string)

SetPrefix sets the output prefix for the Go standard logger.

type Level Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (l Level) String() string

String returns the string representation of the level l.

type Logger Uses

type Logger = golog.Logger

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

type Outputter Uses

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 Uses

func GetOutputter() Outputter

GetOutputter returns the current outputter used by the log package.

func SetOutputter Uses

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.

Package log imports 7 packages (graph) and is imported by 46 packages. Updated 2019-12-05. Refresh now. Tools for package owners.