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.
Example ¶
package main import ( "os" "github.com/grailbio/base/log" ) func main() { log.SetOutput(os.Stdout) log.SetFlags(0) log.Print("hello, world!") log.Error.Print("hello from error") log.Debug.Print("invisible") }
Output: hello, world! hello from error
Index ¶
- Constants
- func AddFlags()
- func At(level Level) bool
- func Errorf(format string, v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Output(calldepth int, level Level, s string) error
- func Outputf(out Outputter, level Level, format string, v ...interface{})
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func SetFlags(flag int)
- func SetLevel(level Level)
- func SetOutput(w io.Writer)
- func SetPrefix(prefix string)
- type Level
- type Logger
- type Outputter
Examples ¶
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) )
Variables ¶
This section is empty.
Functions ¶
func AddFlags ¶
func AddFlags()
AddFlags adds a standard log level flags to the flag.CommandLine flag set.
func Errorf ¶ added in v0.0.11
func Errorf(format string, v ...interface{})
Errorf formats a message in the manner of fmt.Sprintf and outputs it at the Error level to the current outputter.
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 ¶
Output outputs a log message to the current outputter at the provided level and call depth.
func Outputf ¶
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 SetLevel ¶ added in v0.0.5
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.
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 ¶
Printf formats a message in the manner of fmt.Sprintf and outputs it at level l to the current outputter.
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 ¶
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.