logging

package
v0.0.0-...-c6693c8 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Scheme        = "gcplogs"
	SeverityField = "severity"
	TimeField     = "time"
	MessageField  = "message"

	// TraceField is the field Google Cloud Logging looks for the
	// trace https://cloud.google.com/logging/docs/structured-logging
	TraceField = "logging.googleapis.com/trace"
)

Variables

This section is empty.

Functions

func GetLink(project string, labels map[string]string) string

GetLink returns a link to the Cloud Logging console that shows logs matching the given labels. The link isn't stable because it doesn't pin the time.

func GetLinkAroundTime

func GetLinkAroundTime(project string, labels map[string]string, t time.Time, duration time.Duration) string

GetLinkAroundTime returns a link to the logs query pinned at the specified time. It will show a time window specified by the duration around the time. Duration is rounded to the nearest second, minute or hour depending on its size

func ParseURI

func ParseURI(uri string) (string, string, bool)

ParseURI parses a URI of the form gcplogs:///projects/${PROJECT}/logs/${LOGNAME} and returns project, logname, bool. If the URI is not of the expected form false is returned. If the scheme doesn't match the expected scheme empty values are returned.

func RegisterSink

func RegisterSink(project string, name string, labels map[string]string) error

RegisterSink registers Sink as a zap sink; this allows zap to send logs to Cloud Logging.

project is the GCP project name is the name of the log to use labels are labels to add to every log entry

Types

type Sink

type Sink struct {
	// Set client if you want the sink to take ownership of the client and call close
	// If you don't then you must call Client.Close to flush the logs
	Client *logging.Client
	Logger *logging.Logger
}

Sink implements zap.Sink interface. This lets zap send logs to Cloud Logging.

To use the sink:

  1. Call RegisterSink; this will register register the sink with zap

  2. Create a zap logger configuration in which the output path uses the URL gcplogs:///projects/${PROJECT}/logs/${LOGNAME}

    For example: c. := zap.NewProductionConfig() c.OutputPaths = []string{"gcplogs:///projects/${PROJECT}/logs/${LOGNAME}", "stdout"}

func (*Sink) Close

func (s *Sink) Close() error

func (*Sink) Sync

func (s *Sink) Sync() error

Sync flushes any buffers in the logger.

func (*Sink) Write

func (s *Sink) Write(in []byte) (n int, err error)

Jump to

Keyboard shortcuts

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