gcplogrus

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

gcplogrus

logrus integration for Stackdriver.

Features:
Usage:

The logging system can be initialized with a single line of code:

gcplogrus.Setup(gcplogrus.DefaultOpts())

As long as the following ENV variables are set:

  • ERRORREPORTING_PROJECT
  • ERRORREPORTING_SERVICE

Complete example:

  import (
    "github.com/trealtamira/gcplogrus"
    log "github.com/sirupsen/logrus"
  )

  func init() {
    gcplogrus.Setup(gcplogrus.DefaultOpts())
  }

  func main() {
    // The following log will be formatted in a way compatible
    // with Stackdriver Logging
    log.Infof("foobar")

    // The following error will be sent to Stackdriver Error Reporting.
    // By default, only FATAL errors are sent.
    log.Fatalf("this is a test error")
  }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Setup

func Setup(opts Opts)

Setup intializes the Stackdriver error reporting client and add a hook to logrus.

Types

type Opts

type Opts struct {
	Levels []log.Level
	Async  bool

	// Error reporting timeout. This is ignored when Async is true.
	Timeout time.Duration

	// Google Cloud project ID
	Project string

	// The service name for error reports
	Service string

	// Set the logrus formatter to be compatible with Stackdriver Logging
	UseJoonixFormatter bool
}

Opts are the options that must be given to Setup

func DefaultOpts

func DefaultOpts() Opts

DefaultOpts returns the default options to be used when calling Setup

Jump to

Keyboard shortcuts

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