stackrus

package module
v0.0.0-...-ea56a1a Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

stackrus

Stackdriver logging plugin for logrus

See the example for usage

Note - to fully flush the hook's buffer, you need to be sure Close is called on the hook before exiting.

Logrus data field values are all converted to string label values in Stackdriver log entries per the Stackdriver API.

Levels are mapped between Logrus levels and Stackdriver severity:

{logrus.DebugLevel, logging.Debug},
{logrus.InfoLevel, logging.Info},
{logrus.WarnLevel, logging.Warning},
{logrus.ErrorLevel, logging.Error},
{logrus.FatalLevel, logging.Critical},
{logrus.PanicLevel, logging.Emergency},

You can set the logs as being related to a cloud resource by setting special logrus fields of resource.type and resource.labels.*

The resource type must match a valid stackdriver monitored resource. eg: cloud_run_revision.

This hook specifically uses "cloud.google.com/go/logging" while many other related projects are only using the deprecated "google.golang.org/api/logging/v2".

Not an official Google product.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook provides a Logrus logging hook that sends logs to Stackdriver Logging

func NewHook

func NewHook(ctx context.Context, projectID, logName string, level logrus.Level, opts ...option.ClientOption) *Hook

NewHook create a new Hook with project and logname configuration

func (Hook) Close

func (l Hook) Close() error

Close flushes any log entries before closing the hook

func (*Hook) Fire

func (l *Hook) Fire(e *logrus.Entry) error

Fire logs entry to Stackdriver

func (*Hook) Flush

func (l *Hook) Flush()

Flush clears any pending logs to the network

func (*Hook) Levels

func (l *Hook) Levels() []logrus.Level

Levels returns the available logging levels

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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