logger

package
v0.10.5 Latest Latest
Warning

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

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

Documentation

Overview

Package logger provides a logger that logs to Google Cloud Logging. It's a thin wrapper around golang/cloud/logging package.

Index

Constants

View Source
const (

	// MaxLogEntrySize Max size of each log entry (100 KB)
	// This limit helps avoid creating very large log lines in case someone
	// accidentally creates a large EventMetric, which in turn is possible due to
	// unbounded nature of "map" metric where keys are created on demand.
	//
	// TODO(manugarg): We can possibly get rid of this check now as the code that
	// could cause a large map metric has been fixed now. Earlier, cloudprober's
	// HTTP server used to respond to all URLs and used to record access to those
	// URLs as a "map" metric. Now, it responds only to pre-configured URLs.
	MaxLogEntrySize = 102400
)

Variables

View Source
var (

	// LogPrefixEnvVar environment variable is used to determine the stackdriver
	// log name prefix. Default prefix is "cloudprober".
	LogPrefixEnvVar = "CLOUDPROBER_LOG_PREFIX"
)

Functions

This section is empty.

Types

type Logger

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

Logger implements a logger that logs messages to Google Cloud Logging. It provides a suite of methods where each method corresponds to a specific logging.Level, e.g. Error(paylod interface{}). Each method takes a payload that has to either be a JSON-encodable object, a string or a []byte slice (all other types of payload will result in error).

It falls back to logging through the traditional logger if:

  • Not running on GCE,
  • Logging client is uninitialized (e.g. for testing),
  • Logging to cloud fails for some reason.

Logger{} is a valid object that will log through the traditional logger.

func New

func New(ctx context.Context, logName string) (*Logger, error)

New returns a new Logger object with cloud logging client initialized if running on GCE.

func NewCloudproberLog added in v0.10.2

func NewCloudproberLog(component string) (*Logger, error)

NewCloudproberLog is a convenient wrapper around New that sets context to context.Background and attaches cloudprober prefix to log names.

func (*Logger) Critical

func (l *Logger) Critical(payload ...string)

Critical logs messages with logging level set to "Critical" and exits the process with error status. The buffer is flushed before exiting.

func (*Logger) Criticalf

func (l *Logger) Criticalf(format string, args ...interface{})

Criticalf logs formatted text messages with logging level "Critical" and exits the process with error status. The buffer is flushed before exiting.

func (*Logger) Debug

func (l *Logger) Debug(payload ...string)

Debug logs messages with logging level set to "Debug".

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

Debugf logs formatted text messages with logging level "Debug".

func (*Logger) Error

func (l *Logger) Error(payload ...string)

Error logs messages with logging level set to "Error".

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

Errorf logs formatted text messages with logging level "Error".

func (*Logger) Info

func (l *Logger) Info(payload ...string)

Info logs messages with logging level set to "Info".

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

Infof logs formatted text messages with logging level "Info".

func (*Logger) Warning

func (l *Logger) Warning(payload ...string)

Warning logs messages with logging level set to "Warning".

func (*Logger) Warningf

func (l *Logger) Warningf(format string, args ...interface{})

Warningf logs formatted text messages with logging level "Warning".

Jump to

Keyboard shortcuts

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