gcpcore

package
v0.0.0-...-2895439 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gcpcore is a custom zap.Core that formats Error logs for GCP Error Reporting

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloudRunServiceAndVersion

func CloudRunServiceAndVersion() (string, string)

CloudRunServiceAndVersion returns a service name and version based on the predefined env vars K_SERVICE & K_REVISION. Also works for GCP App Engine. See: https://cloud.google.com/run/docs/container-contract

func SourceLocation

func SourceLocation(pc uintptr, file string, line int, ok bool) zap.Field

SourceLocation adds the correct Stackdriver "SourceLocation" field.

see: https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation

func WrapCore

func WrapCore(name, version string) zap.Option

WrapCore returns a zap.Option that wraps the current core with the error reporting core. Any ErrorLogs will now be reported in a format that can ingest into GCP Error Reporting.

Example:

core := zap.Must(golog.NewLoggerConfigForGCP().Build(
		gcpcore.WrapCore(gcpcore.CloudRunServiceAndVersion()),
	))
logger := core.Sugar().Named("web_server")

Types

This section is empty.

Jump to

Keyboard shortcuts

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