Documentation ¶
Overview ¶
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.
-logtostderr=false Logs are written to standard error instead of to files. -alsologtostderr=false Logs are written to standard error as well as to files. -stderrthreshold=ERROR Log events at or above this severity are logged to standard error as well as to files. Other flags provide aids to debugging. -log_backtrace_at="" When set to a file and line number holding a logging statement, such as -log_backtrace_at=gopherflakes.go:234 a stack trace will be written to the Info log whenever execution hits that statement. (Unlike with -vmodule, the ".go" must be present.) -v=0 Enable V-leveled logging at the specified level. -vmodule="" 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, -vmodule=gopher*=3 sets the V level to 3 in all Go files whose names begin "gopher".
Index ¶
- Constants
- Variables
- func CopyStandardLogTo(name string)
- func ErrLogName() string
- func Error(args ...any)
- func ErrorDepth(depth int, args ...any)
- func Errorf(format string, args ...any)
- func Errorln(args ...any)
- func Flush()
- func Info(args ...any)
- func InfoDepth(depth int, args ...any)
- func InfoLogName() string
- func Infof(format string, args ...any)
- func Infoln(args ...any)
- func SetLogDir(dir string)
- func SetV(smodule uint8, level Level)
- func WarnLogName() string
- func Warning(args ...any)
- func WarningDepth(depth int, args ...any)
- func Warningf(format string, args ...any)
- func Warningln(args ...any)
- type Level
- type OutputStats
- type Verbose
Constants ¶
const ( SmoduleTransport = iota SmoduleAIS SmoduleMemsys SmoduleCluster SmoduleFS SmoduleReb SmoduleEC SmoduleStats SmoduleIOS SmoduleXs SmoduleBackend SmoduleSpace )
NOTE: for module names mapped to these constants, see cmn/debug/debug_on.go
Variables ¶
var FileHeaderCB func() string
var MaxSize uint64 = 1024 * 1024 * 1800
MaxSize is the maximum size of a log file in bytes.
var ( // Stats tracks the number of lines of output and number of bytes // per severity level. Values must be read with atomic.LoadInt64. Stats struct { Info, Warning, Error OutputStats } )
Functions ¶
func CopyStandardLogTo ¶
func CopyStandardLogTo(name string)
CopyStandardLogTo arranges for messages written to the Go "log" package's default logs to also appear in the Google logs for the named and lower severities. Subsequent changes to the standard log's default output location or format may break this behavior.
Valid names are "INFO", "WARNING", "ERROR", and "FATAL". If the name is not recognized, CopyStandardLogTo panics.
func ErrLogName ¶
func ErrLogName() string
func Error ¶
func Error(args ...any)
Error logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
func ErrorDepth ¶
ErrorDepth acts as Error but uses depth to determine which call frame to log. ErrorDepth(0, "msg") is the same as Error("msg").
func Errorf ¶
Errorf logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
func Errorln ¶
func Errorln(args ...any)
Errorln logs to the ERROR, WARNING, and INFO logs. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
func Info ¶
func Info(args ...any)
Info logs to the INFO log. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
func InfoDepth ¶
InfoDepth acts as Info but uses depth to determine which call frame to log. InfoDepth(0, "msg") is the same as Info("msg").
func InfoLogName ¶
func InfoLogName() string
func Infof ¶
Infof logs to the INFO log. Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
func Infoln ¶
func Infoln(args ...any)
Infoln logs to the INFO log. Arguments are handled in the manner of fmt.Println; a newline is appended if missing.
func SetV ¶
SetV sets verbosity level for static module.
NOTE: SetV should be set in the init. Bugs are expected when SetV is called in-flight since no locks are taken.
func WarnLogName ¶
func WarnLogName() string
func Warning ¶
func Warning(args ...any)
Warning logs to the WARNING and INFO logs. Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
func WarningDepth ¶
WarningDepth acts as Warning but uses depth to determine which call frame to log. WarningDepth(0, "msg") is the same as Warning("msg").
Types ¶
type Level ¶
type Level int32
Level is exported because it appears in the arguments to V and is the type of the v flag, which can be set programmatically. It's a distinct type because we want to discriminate it from logType. Variables of type level are only changed under logging.mu. The -v flag is read only with atomic ops, so the state of the logging module is consistent. Level is treated as a sync/atomic int32. Level specifies a level of verbosity for V logs. *Level implements flag.Value; the -v flag is of type Level and should be modified only through the flag.Value interface.
type OutputStats ¶
type OutputStats struct {
// contains filtered or unexported fields
}
OutputStats tracks the number of output lines and bytes written.
func (*OutputStats) Bytes ¶
func (s *OutputStats) Bytes() int64
Bytes returns the number of bytes written.
func (*OutputStats) Lines ¶
func (s *OutputStats) Lines() int64
Lines returns the number of lines written.
type Verbose ¶
type Verbose bool
Verbose is a boolean type that implements Infof (like Printf) etc. See the documentation of V for more information.
func FastV ¶
FastV similarly to V checks if verbosity level is enough to print the log message. It is a fast inline function that doesn't take vmodule into account. As such, it is intended to be used for the datapath, primarily.
func V ¶
V reports whether verbosity at the call site is at least the requested level. The returned value is a boolean of type Verbose, which implements Info, Infoln and Infof. These methods will write to the Info log if called. Thus, one may write either if glog.V(2) { glog.Info("log this") } or glog.V(2).Info("log this") The second form is shorter but the first is cheaper if logging is off because it does not evaluate its arguments.
Whether an individual call to V generates a log record depends on the setting of the -v and --vmodule flags; both are off by default. If the level in the call to V is at least the value of -v, or of -vmodule for the source file containing the call, the V call will log.
func (Verbose) Info ¶
Info is equivalent to the global Info function, guarded by the value of v. See the documentation of V for usage.