logger

package
v0.13.4 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 18 Imported by: 5

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). We truncate logs if
	// they are bigger than this size.
	MaxLogEntrySize = 102400
)

Variables

View Source
var EnvVars = struct {
	DisableCloudLogging, DebugLog, GCPLoggingEndpoint string
}{
	"CLOUDPROBER_DISABLE_CLOUD_LOGGING",
	"CLOUDPROBER_DEBUG_LOG",
	"CLOUDPROBER_GCP_LOGGING_ENDPOINT",
}

EnvVars defines environment variables that can be used to modify the logging behavior.

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.

labels is a map which is present in every log entry and all custom metadata about the log entries can be inserted into this map. For example probe id can be inserted into this map.

func New

func New(opts ...Option) *Logger

New returns a new cloudprober Logger.

func NewLegacy added in v0.13.0

func NewLegacy(ctx context.Context, logName string, opts ...Option) (*Logger, error)

NewLegacy returns a new cloudprober Logger. Deprecated: Use New or NewWithAttrs instead.

func NewWithAttrs added in v0.12.9

func NewWithAttrs(attrs ...slog.Attr) *Logger

NewWithAttrs is a shortcut to create a new logger with a set of attributes.

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) CriticalAttrs added in v0.12.9

func (l *Logger) CriticalAttrs(msg string, attrs ...slog.Attr)

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) DebugAttrs added in v0.12.9

func (l *Logger) DebugAttrs(msg string, attrs ...slog.Attr)

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) EnableStackdriverLogging added in v0.11.4

func (l *Logger) EnableStackdriverLogging()

EnableStackdriverLogging enables logging to stackdriver.

func (*Logger) Error

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

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

func (*Logger) ErrorAttrs added in v0.12.9

func (l *Logger) ErrorAttrs(msg string, attrs ...slog.Attr)

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

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) InfoAttrs added in v0.12.9

func (l *Logger) InfoAttrs(msg string, attrs ...slog.Attr)

InfoWithAttrs 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) WarningAttrs added in v0.12.9

func (l *Logger) WarningAttrs(msg string, attrs ...slog.Attr)

WarningAttrs 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".

type Option added in v0.12.3

type Option func(*Logger)

Option can be used for adding additional metadata information in logger.

func WithAttr added in v0.12.9

func WithAttr(attrs ...slog.Attr) Option

WithAttr option can be used to add a set of labels to all logs, e.g. logger.New(ctx, logName, logger.WithAttr(myLabels))

func WithWriter added in v0.13.0

func WithWriter(w io.Writer) Option

Jump to

Keyboard shortcuts

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