logger

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package logger implements a simple way to init a global logger and access it through a logr.Logger interface.

Message:

All messages should start with a capital letter.

Log level:

The loggers only support verbosity levels (V-levels) instead of semantic levels. Level zero, the default, is important for the end user.

  • 0: You always want to see this.
  • 1: Common logging that you don't want to show by default.
  • 2: Useful steady state information about the operation and important log messages that may correlate to significant changes in the system.
  • 3: Extended information about changes. Somehow useful information to the user that is not important enough for level 2.
  • 4: Debugging information. Starting from this level, all logs are oriented to developers and troubleshooting.
  • 5: Traces. Information to follow the code path.
  • 6: Information about interaction with external resources. External binary commands, api calls.
  • 7: Extra information passed to external systems. Configuration files, kubernetes manifests, etc.
  • 8: Truncated external binaries and clients output/responses.
  • 9: Full external binaries and clients output/responses.

Logging WithValues:

Logging WithValues should be preferred to embedding values into log messages because it allows machine readability.

Variables name should start with a capital letter.

Logging WithNames:

Logging WithNames should be used carefully. Please consider that practices like prefixing the logs with something indicating which part of code is generating the log entry might be useful for developers, but it can create confusion for the end users because it increases the verbosity without providing information the user can understand/take benefit from.

Logging errors:

A proper error management should always be preferred to the usage of log.Error.

Index

Constants

View Source
const MaxLogLevel = 9

MaxLogLevel denotes the maximum log level supported by the logger package.

Variables

This section is empty.

Functions

func Error

func Error(err error, msg string, keysAndValues ...interface{})

Error logs an error message using the package logger.

func Fatal

func Fatal(err error, msg string)

Fatal is equivalent to Get().Error() followed by a call to os.Exit(1).

func Get

func Get() logr.Logger

Get returns the logger instance that has been previously set. If no logger has been set, it returns a null logger.

func GetOutputFilePath deprecated added in v0.13.0

func GetOutputFilePath() string

GetOutputFilePath returns the path to the file where high verbosity logs are written to. If the logger hasn't been configured to output to a file, it returns an empty string.

Deprecated: The function will be removed to avoid using package state.

func Info

func Info(msg string, keysAndValues ...interface{})

Info logs a non-error message with the given key/value pairs as context.

The msg argument should be used to add some constant description to the log line. The key/value pairs can then be used to add additional variable information. The key/value pairs should alternate string keys and arbitrary values.

func Init added in v0.15.0

func Init(opts Options) error

Init initializes the package logger. Repeat calls will overwrite the package logger which may result in unexpected behavior.

func MarkFail

func MarkFail(msg string, keysAndValues ...interface{})

MarkFail logs a message prefixed with a cross emoji.

func MarkPass

func MarkPass(msg string, keysAndValues ...interface{})

MarkPass logs a message prefixed with a green check emoji.

func MarkSuccess

func MarkSuccess(msg string, keysAndValues ...interface{})

MarkSuccess logs a message prefixed with a popper emoji.

func MarkWarning added in v0.11.2

func MarkWarning(msg string, keysAndValues ...interface{})

MarkWarning logs a message prefixed with a warning mark.

func MaxLogging

func MaxLogging() bool

MaxLogging determines if the package logger is configured to log at MaxLogLevel.

func V

func V(level int) logr.Logger

V returns an Logger value for a specific verbosity level, relative to this Logger. In other words, V values are additive. V higher verbosity level means a log message is less important. It's illegal to pass a log level less than zero.

Types

type Options added in v0.15.0

type Options struct {
	// Level is the log level at which to configure the logger from 0 to 9.
	Level int

	// OutputFilePath is an absolute file path. The file will be created if it doesn't exist.
	// All logs available at level 9 will be written to the file.
	OutputFilePath string
}

Options represents a set of arguments for initializing the zap logger.

Jump to

Keyboard shortcuts

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