log

package
v0.0.0-...-0000b31 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package log provides the canonical logging functionality used by Go-based Istio components.

Istio's logging subsystem is built on top of the [Zap](https://godoc.org/go.uber.org/zap) package. High performance scenarios should use the Error, Warn, Info, and Debug methods. Lower perf scenarios can use the more expensive convenience methods such as Debugf and Warnw.

The package provides direct integration with the Cobra command-line processor which makes it easy to build programs that use a consistent interface for logging. Here's an example of a simple Cobra-based program using this log package:

		func main() {
			// get the default logging options
			options := log.NewOptions()

			rootCmd := &cobra.Command{
				Run: func(cmd *cobra.Command, args []string) {

					// configure the logging system
					if err := log.Configure(options); err != nil {
                     // print an error and quit
                 }

					// output some logs
					log.Info("Hello")
					log.Sync()
				},
			}

			// add logging-specific flags to the cobra command
			options.AttachCobraFlags(rootCmd)
			rootCmd.SetArgs(os.Args[1:])
			rootCmd.Execute()
		}

Once configured, this package intercepts the output of the standard golang "log" package as well as anything sent to the global zap logger (zap.L()).

Index

Constants

View Source
const (
	// None is used to disable logging output as well as to disable stack tracing.
	None zapcore.Level = 100
)

Variables

This section is empty.

Functions

func Configure

func Configure(options *Options) error

Configure initializes Istio's logging subsystem.

You typically call this once at process startup. Once this call returns, the logging system is ready to accept data.

func Debug

func Debug(msg string, fields ...zapcore.Field)

Debug outputs a message at debug level. This call is a wrapper around [Logger.Debug](https://godoc.org/go.uber.org/zap#Logger.Debug)

func DebugEnabled

func DebugEnabled() bool

DebugEnabled returns whether output of messages at the debug level is currently enabled.

func Debuga

func Debuga(args ...interface{})

Debuga uses fmt.Sprint to construct and log a message at debug level. This call is a wrapper around [Sugaredlogger.Debug](https://godoc.org/go.uber.org/zap#Sugaredlogger.Debug)

func Debugf

func Debugf(template string, args ...interface{})

Debugf uses fmt.Sprintf to construct and log a message at debug level. This call is a wrapper around [Sugaredlogger.Debugf](https://godoc.org/go.uber.org/zap#Sugaredlogger.Debugf)

func Debugw

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

Debugw logs a message at debug level with some additional context. This call is a wrapper around [Sugaredlogger.Debugw](https://godoc.org/go.uber.org/zap#Sugaredlogger.Debugw)

func Error

func Error(msg string, fields ...zapcore.Field)

Error outputs a message at error level. This call is a wrapper around [logger.Error](https://godoc.org/go.uber.org/zap#logger.Error)

func ErrorEnabled

func ErrorEnabled() bool

ErrorEnabled returns whether output of messages at the error level is currently enabled.

func Errora

func Errora(args ...interface{})

Errora uses fmt.Sprint to construct and log a message at error level. This call is a wrapper around [Sugaredlogger.Error](https://godoc.org/go.uber.org/zap#Sugaredlogger.Error)

func Errorf

func Errorf(template string, args ...interface{})

Errorf uses fmt.Sprintf to construct and log a message at error level. This call is a wrapper around [Sugaredlogger.Errorf](https://godoc.org/go.uber.org/zap#Sugaredlogger.Errorf)

func Errorw

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

Errorw logs a message at error level with some additional context. This call is a wrapper around [Sugaredlogger.Errorw](https://godoc.org/go.uber.org/zap#Sugaredlogger.Errorw)

func Info

func Info(msg string, fields ...zapcore.Field)

Info outputs a message at information level. This call is a wrapper around [logger.Info](https://godoc.org/go.uber.org/zap#logger.Info)

func InfoEnabled

func InfoEnabled() bool

InfoEnabled returns whether output of messages at the info level is currently enabled.

func Infoa

func Infoa(args ...interface{})

Infoa uses fmt.Sprint to construct and log a message at info level. This call is a wrapper around [Sugaredlogger.Info](https://godoc.org/go.uber.org/zap#Sugaredlogger.Info)

func Infof

func Infof(template string, args ...interface{})

Infof uses fmt.Sprintf to construct and log a message at info level. This call is a wrapper around [Sugaredlogger.Infof](https://godoc.org/go.uber.org/zap#Sugaredlogger.Infof)

func Infow

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

Infow logs a message at info level with some additional context. This call is a wrapper around [Sugaredlogger.Infow](https://godoc.org/go.uber.org/zap#Sugaredlogger.Infow)

func Sync

func Sync()

Sync flushes any buffered log entries. Processes should normally take care to call Sync before exiting. This call is a wrapper around [logger.Sync](https://godoc.org/go.uber.org/zap#logger.Sync)

func Warn

func Warn(msg string, fields ...zapcore.Field)

Warn outputs a message at warn level. This call is a wrapper around [logger.Warn](https://godoc.org/go.uber.org/zap#logger.Warn)

func WarnEnabled

func WarnEnabled() bool

WarnEnabled returns whether output of messages at the warn level is currently enabled.

func Warna

func Warna(args ...interface{})

Warna uses fmt.Sprint to construct and log a message at warn level. This call is a wrapper around [Sugaredlogger.Warn](https://godoc.org/go.uber.org/zap#Sugaredlogger.Warn)

func Warnf

func Warnf(template string, args ...interface{})

Warnf uses fmt.Sprintf to construct and log a message at warn level. This call is a wrapper around [Sugaredlogger.Warnf](https://godoc.org/go.uber.org/zap#Sugaredlogger.Warnf)

func Warnw

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

Warnw logs a message at warn level with some additional context. This call is a wrapper around [Sugaredlogger.Warnw](https://godoc.org/go.uber.org/zap#Sugaredlogger.Warnw)

func With

func With(fields ...zapcore.Field) *zap.Logger

With creates a child logger and adds structured context to it. Fields added to the child don't affect the parent, and vice versa. This call is a wrapper around [logger.With](https://godoc.org/go.uber.org/zap#logger.With)

Types

type Options

type Options struct {
	// OutputPaths is a list of file system paths to write the log data to.
	// The special values stdout and stderr can be used to output to the
	// standard I/O streams.
	OutputPaths []string

	// JSONEncoding controls whether the log is formatted as JSON.
	JSONEncoding bool

	// IncludeCallerSourceLocation determines whether log messages include the source location of the caller.
	IncludeCallerSourceLocation bool
	// contains filtered or unexported fields
}

Options defines the set of options supported by Istio's component logging package.

func NewOptions

func NewOptions() *Options

NewOptions returns a new set of options, initialized to the defaults

func (*Options) AttachCobraFlags

func (o *Options) AttachCobraFlags(cmd *cobra.Command)

AttachCobraFlags attaches a set of Cobra flags to the given Cobra command.

Cobra is the command-line processor that Istio uses. This command attaches the necessary set of flags to expose a CLI to let the user control all logging options.

func (*Options) GetOutputLevel

func (o *Options) GetOutputLevel() (zapcore.Level, error)

GetOutputLevel returns the minimum log output level.

func (*Options) GetStackTraceLevel

func (o *Options) GetStackTraceLevel() (zapcore.Level, error)

GetStackTraceLevel returns the current stack trace level.

func (*Options) SetOutputLevel

func (o *Options) SetOutputLevel(level zapcore.Level) error

SetOutputLevel sets the minimum log output level.

The level can be one of zapcore.DebugLevel, zapcore.InfoLevel, zapcore.WarnLevel, zapcore.ErrorLevel, or None. The default is zapcore.InfoLevel.

func (*Options) SetStackTraceLevel

func (o *Options) SetStackTraceLevel(level zapcore.Level) error

SetStackTraceLevel sets the minimum stack trace capture level.

The level can be one of zapcore.DebugLevel, zapcore.InfoLevel, zapcore.WarnLevel, zapcore.ErrorLevel, or None. The default is None.

Jump to

Keyboard shortcuts

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