log

package
v0.0.0-...-0611383 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package log defines the contract for the xds-relay logger. It also contains an implementation of the contract using the Zap logging framework.

Index

Constants

This section is empty.

Variables

View Source
var MockLogger = New("debug", os.Stderr)

MockLogger mocks a very basic debug logger.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	// Named adds a sub-scope to the logger.
	Named(name string) Logger

	// With adds a variadic number of fields to the logging context.
	// When processing pairs, the first element of the pair is used as the
	// field key and the second as the field value.
	//
	// For example,
	//
	//   Log.With(
	//     "hello", "world",
	//     "failure", errors.New("oh no"),
	//     "count", 42,
	//     "user", User{Name: "alice"},
	//  ).Info("this is an error message")
	With(args ...interface{}) Logger

	// Debug logs a message at level Debug with support for string formatting, annotated with
	// fields provided through With().
	Debug(ctx context.Context, template string, msg ...interface{})

	// Info logs a message at level Info with support for string formatting, annotated with fields
	// provided through With().
	Info(ctx context.Context, template string, msg ...interface{})

	// Warn logs a message at level Warn with support for string formatting, annotated with fields
	// provided through With().
	Warn(ctx context.Context, template string, msg ...interface{})

	// Error logs a message at level Error with support for string formatting, annotated with
	// fields provided through With().
	Error(ctx context.Context, template string, msg ...interface{})

	// Panic logs a message at level Panic with support for string formatting, annotated with
	// fields provided through With(), and immediately panics.
	Panic(ctx context.Context, template string, msg ...interface{})

	// Fatal logs a message at level Fatal with support for string formatting, annotated with
	// fields provided through With(), and immediately calls os.Exit.
	Fatal(ctx context.Context, template string, msg ...interface{})

	// Sync flushes any buffered log entries.
	Sync() error

	// UpdateLogLevel reinitializes the logger at the given level.
	UpdateLogLevel(logLevel string)

	// GetLevel returns the logger's level as a human-readable string.
	GetLevel() string
}

Logger is the contract for xds-relay's logging implementation.

A self-contained usage example looks as follows:

Log.Named("foo-component").With(
    "field1", "value1",
    "field2", "value2",
 ).Error("my error message")

func New

func New(logLevel string, writeTo io.Writer) Logger

New returns an instance of Logger implemented using the Zap logging framework.

logLevel is mandatory, can be one of DEBUG, INFO, WARN, ERROR, FATAL. writeTo is mandatory. This is the writer where logs should be outputted to. Use os.Stderr if unsure.

func NewMock

func NewMock(logLevel string, writeTo io.Writer) Logger

NewMock returns an instance of Logger implemented using the Zap logging framework.

Directories

Path Synopsis
Package zap sets up a zap.Logger using the Zap logging framework.
Package zap sets up a zap.Logger using the Zap logging framework.

Jump to

Keyboard shortcuts

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