luci: go.chromium.org/luci/common/logging/gkelogger Index | Files

package gkelogger

import "go.chromium.org/luci/common/logging/gkelogger"

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 (
  "go.chromium.org/luci/common/logging"
  "go.chromium.org/luci/common/logging/gkelogger"
)

...

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

Index

Package Files

config.go doc.go logger.go

func GetFactory Uses

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

GetFactory creates a goroutine safe gkelogger that writes into out.

func Use Uses

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.

type LogEntry Uses

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

Package gkelogger imports 8 packages (graph) and is imported by 2 packages. Updated 2018-08-20. Refresh now. Tools for package owners.