Categorygithub.com/yext/glog
modulepackage
0.0.0-20250304212833-098864078be8
Repository: https://github.com/yext/glog.git
Documentation: pkg.go.dev

# README

glog

Leveled execution logs for Go.

This is an efficient pure Go implementation of leveled logs in the manner of the open source C++ package http://code.google.com/p/google-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 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")

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

ContextWithData creates a context as extension of the parent context, with the provided data stored as a value.
ContextWithPrefix creates a context as extension of the parent context, with the provided prefix stored as a value.
Data tags an item to be ignored by glog when logging but to pass it to any registered backends.
Error logs to the ERROR, WARNING, and INFO logs.
Errorf logs to the ERROR, WARNING, and INFO logs.
ErrorfIf logs to the ERROR, WARNING, and INFO logs.
ErrorfWithDepth is equivalent to Errorf but with a specified extra depth (on the call stack).
ErrorIf logs to the ERROR, WARNING, and INFO logs.
Errorln logs to the ERROR, WARNING, and INFO logs.
ErrorlnWithDepth is equivalent to Errorln but with a specified extra depth (on the call stack).
ErrorWithDepth is equivalent to Error but with a specified extra depth (on the call stack).
Exit logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1).
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).
ExitWithDepth acts as Exit but uses depth to determine which call frame to log.
Fatal logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255).
Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255).
FatalfWithDepth is equivalent to Fatalf but with a specified extra depth (on the call stack).
FatalIf logs to the FATAL, ERROR, WARNING, and INFO, including a stack trace of all running goroutines, then calls os.Exit(255).
Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls os.Exit(255).
FatallnWithDepth is equivalent to Fatalln but with a specified extra depth (on the call stack).
FatalWithDepth is equivalent to Fatal but with a specified extra depth (on the call stack).
Flush flushes all pending log I/O.
GetErrorEvent returns an ERROR level Event of args.
Info logs to the INFO log.
Infof logs to the INFO log.
InfofWithDepth is equivalent to Infof but with a specified extra depth (on the call stack).
Infoln logs to the INFO log.
InfolnWithDepth is equivalent to Infoln but with a specified extra depth (on the call stack).
InfoWithDepth is equivalent to Info but with a specified extra depth (on the call stack).
NewEvent creates a glog.Event from the logged event's severity, format string (if Infof, Warnf, Errorf or Fatalf were called) and any other arguments passed to the log call.
NewLogger creates a Logger instance with no additional data.
RegisterBackend returns a channel on which Event's will be passed when they are logged.
SetOutput overrides the logging output writer.
V reports whether verbosity at the call site is at least the requested level.
Warning logs to the WARNING and INFO logs.
Warningf logs to the WARNING and INFO logs.
WarningfIf logs to the WARNING, and INFO logs.
WarningfWithDepth is equivalent to Warningf but with a specified extra depth (on the call stack).
WarningIf logs to the WARNING, and INFO logs.
Warningln logs to the WARNING and INFO logs.
WarninglnWithDepth is equivalent to Warningln but with a specified extra depth (on the call stack).
WarningWithDepth is equivalent to Warning but with a specified extra depth (on the call stack).
WithContext creates a logger from a context.Context.
WithData creates a Logger with a given set of backend data.
WithPrefix creates a Logger with a given prefix.

# Variables

This ExternalOutput is to be used only for external logs.
Stats tracks the number of lines of output and number of bytes per severity level.

# Structs

ErrorArg captures information about an error passed as an argument.
An Event contains a logged event's severity (INFO, WARN, ERROR, FATAL), a format string (if Infof, Warnf, Errorf or Fatalf were used) and a slice of everything else passed to the log call.
FormatStringArg is used to capture the raw format string passed to glog, which often contains an error message without identifying details that can be used to help group the message.
Logger provides logging functionality with additional data and prefixing.
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.