logging

package
v0.0.0-...-fa94ed0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RedirectGlobalLogsToUser

func RedirectGlobalLogsToUser(logger Logger)

RedirectGlobalLogsToUser redirects the standard library's static logger. All messages are written to logger's User level.

Types

type Logger

type Logger interface {
	// User messages appear in the following places:
	//  1. Web UI and gcloud.
	//  2. Standard output of the CLI tool.
	//  3. Backend trace logs (all debug and user logs are combined to a single trace log).
	User(message string)
	// Debug messages appear in the following places:
	//  1. Standard output of the CLI tool.
	//  2. Backend trace logs (all debug and user logs are combined to a single trace log).
	Debug(message string)
	// Trace messages are saved to the logging backend (OutputInfo.serial_outputs).
	Trace(message string)
	// Metric merges all non-default fields into a single OutputInfo instance.
	Metric(metric *pb.OutputInfo)
}

Logger is a logger for CLI tools. It supports string messages and structured metrics.

Structured metrics are accumulated over the lifespan of the logger.

To rebuild the mock, run `go generate ./...`

type OutputInfoReader

type OutputInfoReader interface {
	ReadOutputInfo() *pb.OutputInfo
}

OutputInfoReader exposes pb.OutputInfo to a consumer.

type ToolLogger

type ToolLogger interface {
	// NewLogger creates a new logger that writes to this ToolLogger, but with a
	// different User prefix.
	NewLogger(userPrefix string) Logger
	Logger
	OutputInfoReader
}

ToolLogger implements Logger and OutputInfoReader. Create an instance at the start of a CLI tool's invocation, and pass that instance to dependencies that require logging.

func NewToolLogger

func NewToolLogger(userPrefix string) ToolLogger

NewToolLogger returns a ToolLogger that writes user and debug messages to stdout. The userPrefix string is prepended to User messages. Specify the string that gcloud and the web console uses to find its matches.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL