logging

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APITestingLogComponent

type APITestingLogComponent string

APITestingLogComponent defines a make up part that supports a configured logging level.

const (
	// LogComponentAPITestingDefault defines the "default"-wide logging component. When specified,
	// all other logging components are ignored.
	LogComponentAPITestingDefault APITestingLogComponent = "default"

	// LogComponentAPITestingTesting represents the logging component for testing.
	LogComponentAPITestingTesting APITestingLogComponent = "testing"
)

type APITestingLogging

type APITestingLogging struct {
	// Level is the logging level. If unspecified, defaults to "info".
	Level map[APITestingLogComponent]LogLevel
}

APITestingLogging defines logging for api-testing.

func DefaultAPITestingLogging

func DefaultAPITestingLogging() *APITestingLogging

DefaultAPITestingLogging returns a new APITestingLogging with default configuration parameters.

func (*APITestingLogging) DefaultAPITestingLoggingLevel

func (logging *APITestingLogging) DefaultAPITestingLoggingLevel(level LogLevel) LogLevel

DefaultAPITestingLoggingLevel returns a new APITestingLogging with default configuration parameters. When LogComponentAPITestingDefault specified, all other logging components are ignored.

type LogLevel

type LogLevel string

LogLevel defines a log level for api-testing logs.

const (
	// LogLevelDebug defines the "debug" logging level.
	LogLevelDebug LogLevel = "debug"

	// LogLevelInfo defines the "Info" logging level.
	LogLevelInfo LogLevel = "info"

	// LogLevelWarn defines the "Warn" logging level.
	LogLevelWarn LogLevel = "warn"

	// LogLevelError defines the "Error" logging level.
	LogLevelError LogLevel = "error"
)

Log level const.

type Logger

type Logger struct {
	// Embedded Logger interface
	logr.Logger
	// contains filtered or unexported fields
}

Logger represents a logger.

func DefaultLogger

func DefaultLogger(level LogLevel) Logger

func FileLogger

func FileLogger(file string, name string, level LogLevel) Logger

FileLogger returns a file logger. file is the path of the log file. name is the name of the logger. level is the log level of the logger. The returned logger can write logs to the specified file.

func NewLogger

func NewLogger(logging *APITestingLogging) Logger

func (Logger) Sugar

func (l Logger) Sugar() *zap.SugaredLogger

A Sugar wraps the base Logger functionality in a slower, but less verbose, API. Any Logger can be converted to a SugaredLogger with its Sugar method.

Unlike the Logger, the SugaredLogger doesn't insist on structured logging. For each log level, it exposes four methods:

  • methods named after the log level for log.Print-style logging
  • methods ending in "w" for loosely-typed structured logging
  • methods ending in "f" for log.Printf-style logging
  • methods ending in "ln" for log.Println-style logging

Used:

Info(...any)           Print-style logging
Infow(...any)          Structured logging (read as "info with")
Infof(string, ...any)  Printf-style logging
Infoln(...any)         Println-style logging

func (Logger) WithName

func (l Logger) WithName(name string) Logger

WithName returns a new Logger instance with the specified name element added to the Logger's name. Successive calls with WithName append additional suffixes to the Logger's name. It's strongly recommended that name segments contain only letters, digits, and hyphens (see the package documentation for more information).

func (Logger) WithValues

func (l Logger) WithValues(keysAndValues ...interface{}) Logger

WithValues returns a new Logger instance with additional key/value pairs. See Info for documentation on how key/value pairs work.

Jump to

Keyboard shortcuts

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