Categorygithub.com/golang/glog
modulepackage
1.2.4
Repository: https://github.com/golang/glog.git
Documentation: pkg.go.dev

# README

glog

PkgGoDev

Leveled execution logs for Go.

This is an efficient pure Go implementation of leveled logs in the manner of the open source C++ package glog.

By binding methods to booleans it is possible to use the log package without paying the expense of evaluating the arguments to the log. Through the -vmodule flag, the package also provides fine-grained control over logging at the file level.

The comment from glog.go introduces the ideas:

Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. It provides the functions Info, Warning, Error, Fatal, plus formatting variants such as Infof. It also provides V-style loggingcontrolled 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")

The repository contains an open source version of the log package used inside Google. The master copy of the source lives inside Google, not here. The code in this repo is for export only and is not itself under development. Feature requests will be ignored.

Send bug reports to [email protected].

# Functions

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.
Error logs to the ERROR, WARNING, and INFO logs.
ErrorContext is like [Error], but with an extra [context.Context] parameter.
ErrorContextDepth is like [ErrorDepth], but with an extra [context.Context] parameter.
ErrorContextDepthf is like [ErrorDepthf], but with an extra [context.Context] parameter.
ErrorContextf is like [Errorf], but with an extra [context.Context] parameter.
ErrorDepth acts as Error but uses depth to determine which call frame to log.
ErrorDepthf acts as Errorf but uses depth to determine which call frame to log.
Errorf logs to the ERROR, WARNING, and INFO logs.
Errorln logs to the ERROR, WARNING, and INFO logs.
Exit logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
ExitContext is like [Exit], but with an extra [context.Context] parameter.
ExitContextDepth is like [ExitDepth], but with an extra [context.Context] parameter.
ExitContextDepthf is like [ExitDepthf], but with an extra [context.Context] parameter.
ExitContextf is like [Exitf], but with an extra [context.Context] parameter.
ExitDepth acts as Exit but uses depth to determine which call frame to log.
ExitDepthf acts as Exitf but uses depth to determine which call frame to log.
Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
Fatal logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(2).
FatalContext is like [Fatal], but with an extra [context.Context] parameter.
FatalContextDepth is like [FatalDepth], but with an extra [context.Context] parameter.
FatalContextDepthf is like [FatalDepthf], but with an extra [context.Context] parameter.
FatalContextf is like [Fatalf], but with an extra [context.Context] parameter.
FatalDepth acts as Fatal but uses depth to determine which call frame to log.
FatalDepthf acts as Fatalf but uses depth to determine which call frame to log.
Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(2).
Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(2).
Flush flushes all pending log I/O.
Info logs to the INFO log.
InfoContext is like [Info], but with an extra [context.Context] parameter.
InfoContextDepth is like [InfoDepth], but with an extra [context.Context] parameter.
InfoContextDepthf is like [InfoDepthf], but with an extra [context.Context] parameter.
InfoContextf is like [Infof], but with an extra [context.Context] parameter.
InfoDepth calls Info from a different depth in the call stack.
InfoDepthf acts as InfoDepth but with format string.
Infof logs to the INFO log.
Infoln logs to the INFO log.
Names returns the names of the log files holding the FATAL, ERROR, WARNING, or INFO logs.
NewStandardLogger returns a Logger that writes to the Google logs for the named and lower severities.
V reports whether verbosity at the call site is at least the requested level.
VDepth acts as V but uses depth to determine which call frame to check vmodule for.
Warning logs to the WARNING and INFO logs.
WarningContext is like [Warning], but with an extra [context.Context] parameter.
WarningContextDepth is like [WarningDepth], but with an extra [context.Context] parameter.
WarningContextDepthf is like [WarningDepthf], but with an extra [context.Context] parameter.
WarningContextf is like [Warningf], but with an extra [context.Context] parameter.
WarningDepth acts as Warning but uses depth to determine which call frame to log.
WarningDepthf acts as Warningf but uses depth to determine which call frame to log.
Warningf logs to the WARNING and INFO logs.
Warningln logs to the WARNING and INFO logs.

# Variables

ErrNoLog is the error we return if no log file has yet been created for the specified log type.
MaxSize is the maximum size of a log file in bytes.
Stats tracks the number of lines of output and number of bytes per severity level.

# Structs

OutputStats tracks the number of output lines and bytes written.

# Type aliases

Level specifies a level of verbosity for V logs.
Verbose is a boolean type that implements Infof (like Printf) etc.