gkelogger

package
v0.0.0-...-1643519 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Overview

Package gkelogger is a simple logger that outputs all log entries as single- line JSON objects to stdout. The JSON format is defined by the Google Cloud Logging plugin for fluentd, which is mainly used by The Google Kubernetes Engine + Stackdriver stack. See https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud

Default usage (logging to stderr):

import (
  "github.com/TriggerMail/luci-go/common/logging"
  "github.com/TriggerMail/luci-go/common/logging/gkelogger"
)

...

ctx := context.Background()
ctx = gkelogger.Use(ctx)
logging.Infof(ctx, "Hello %s", "world")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFactory

func GetFactory(out io.Writer) func(context.Context) logging.Logger

GetFactory creates a goroutine safe gkelogger that writes into out.

func Use

func Use(c context.Context, out io.Writer) context.Context

Use registers a JSON based logger as default logger of the context that emits line to out.

Types

type LogEntry

type LogEntry struct {
	// Severity is a string denoting the logging level of the entry.
	Severity string `json:"severity"`
	// Message is a single line human readable string of the log message.
	Message string `json:"message"`
	// Time is a RFC3389Nano formatted string of the timestamp of the log.
	Time string `json:"time"`
	// Fields are extra structured data that may be tagged in the log entry.
	Fields logging.Fields `json:"fields"`
}

LogEntry is created from a single log entry, and is formatted in such a way that the GKE stack expects. The "severity", "message", and "time" fields below are recognized by the Google Cloud Fluentd Plugin. See: https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud/blob/api_v2/lib/fluent/plugin/out_google_cloud.rb

Jump to

Keyboard shortcuts

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