View definition

package glog

Defined in


Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. It provides functions Info, Warning, Error, Fatal, plus formatting variants such as Infof. It also provides V-style logging controlled by the -v and -vmodule=file=2 flags.

Basic examples:

glog.Info("Prepare to repel boarders")

glog.Fatalf("Initialization failed: %s", err)

See the documentation for the V function for an explanation of these examples:

if glog.V(2) {
	glog.Info("Starting transaction...")

glog.V(2).Infoln("Processed", nItems, "elements")

Log output is buffered and written periodically using Flush. Programs should call Flush before exiting to guarantee all log output is written.

By default, all log statements write to files in a temporary directory. This package provides several flags that modify this behavior. As a result, flag.Parse must be called before any logging is done.

	Logs are written to standard error instead of to files.
	Logs are written to standard error as well as to files.
	Log events at or above this severity are logged to standard
	error as well as to files.
	Log files will be written to this directory instead of the
	default temporary directory.

Other flags provide aids to debugging.

	When set to a file and line number holding a logging statement,
	such as
	a stack trace will be written to the Info log whenever execution
	hits that statement. (Unlike with -vmodule, the ".go" must be
	Enable V-leveled logging at the specified level.
	The syntax of the argument is a comma-separated list of pattern=N,
	where pattern is a literal file name (minus the ".go" suffix) or
	"glob" pattern and N is a V level. For instance,
	sets the V level to 3 in all Go files whose names begin "gopher".