log

package
v4.5.2000+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

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

Alameda'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:

Copyright 2019 The Alameda Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// DefaultScopeName defines the name of the default scope.
	DefaultScopeName = "default"
)

Variables

This section is empty.

Functions

func Configure

func Configure(options *Options) error

Configure initializes Alameda'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.

func DebugEnabled

func DebugEnabled() bool

DebugEnabled returns whether output of messages using this scope is currently enabled for debug-level output.

func Debuga

func Debuga(args ...interface{})

Debuga uses fmt.Sprint to construct and log a message at debug level.

func Debugf

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

Debugf uses fmt.Sprintf to construct and log a message at debug level.

func Error

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

Error outputs a message at error level.

func ErrorEnabled

func ErrorEnabled() bool

ErrorEnabled returns whether output of messages using this scope is currently enabled for error-level output.

func Errora

func Errora(args ...interface{})

Errora uses fmt.Sprint to construct and log a message at error level.

func Errorf

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

Errorf uses fmt.Sprintf to construct and log a message at error level.

func Fatal

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

Fatal outputs a message at fatal level.

func FatalEnabled

func FatalEnabled() bool

FatalEnabled returns whether output of messages using this scope is currently enabled for fatal-level output.

func Fatala

func Fatala(args ...interface{})

Fatala uses fmt.Sprint to construct and log a message at fatal level.

func Fatalf

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

Fatalf uses fmt.Sprintf to construct and log a message at fatal level.

func GetFileLine

func GetFileLine(callerLvl int) string

func GetGID

func GetGID() uint64

func Info

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

Info outputs a message at info level.

func InfoEnabled

func InfoEnabled() bool

InfoEnabled returns whether output of messages using this scope is currently enabled for info-level output.

func Infoa

func Infoa(args ...interface{})

Infoa uses fmt.Sprint to construct and log a message at info level.

func Infof

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

Infof uses fmt.Sprintf to construct and log a message at info level.

func Scopes

func Scopes() map[string]*Scope

Scopes returns a snapshot of the currently defined set of scopes

func Sync

func Sync() error

Sync flushes any buffered log entries. Processes should normally take care to call Sync before exiting.

func Warn

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

Warn outputs a message at warn level.

func WarnEnabled

func WarnEnabled() bool

WarnEnabled returns whether output of messages using this scope is currently enabled for warn-level output.

func Warna

func Warna(args ...interface{})

Warna uses fmt.Sprint to construct and log a message at warn level.

func Warnf

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

Warnf uses fmt.Sprintf to construct and log a message at warn level.

Types

type Config

type Config struct {
	SetLogCallers   bool   `mapstructure:"setLogcallers"`
	StackTraceLevel string `mapstructure:"stacktraceLevel"`
	OutputLevel     string `mapstructure:"outputLevel"`
}

func NewDefaultConfig

func NewDefaultConfig() Config

type Level

type Level int

Level is an enumeration of all supported log levels.

const (
	// NoneLevel disables logging
	NoneLevel Level = iota
	// FatalLevel enables fatal level logging
	FatalLevel
	// ErrorLevel enables error level logging
	ErrorLevel
	// WarnLevel enables warn level logging
	WarnLevel
	// InfoLevel enables info level logging
	InfoLevel
	// DebugLevel enables debug level logging
	DebugLevel
)

func StringToLevel

func StringToLevel(level string) (Level, bool)

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. This defaults to stdout.
	OutputPaths []string

	// ErrorOutputPaths is a list of file system paths to write logger errors to.
	// The special values stdout and stderr can be used to output to the
	// standard I/O streams. This defaults to stderr.
	ErrorOutputPaths []string

	// RotateOutputPath is the path to a rotating log file. This file should
	// be automatically rotated over time, based on the rotation parameters such
	// as RotationMaxSize and RotationMaxAge. The default is to not rotate.
	//
	// This path is used as a foundational path. This is where log output is normally
	// saved. When a rotation needs to take place because the file got too big or too
	// old, then the file is renamed by appending a timestamp to the name. Such renamed
	// files are called backups. Once a backup has been created,
	// output resumes to this path.
	RotateOutputPath string

	// RotationMaxSize is the maximum size in megabytes of a log file before it gets
	// rotated. It defaults to 100 megabytes.
	RotationMaxSize int

	// RotationMaxAge is the maximum number of days to retain old log files based on the
	// timestamp encoded in their filename. Note that a day is defined as 24
	// hours and may not exactly correspond to calendar days due to daylight
	// savings, leap seconds, etc. The default is to remove log files
	// older than 30 days.
	RotationMaxAge int

	// RotationMaxBackups is the maximum number of old log files to retain.  The default
	// is to retain at most 1000 logs.
	RotationMaxBackups int

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

	// LogGrpc indicates that Grpc logs should be captured. The default is true.
	// This is not exposed through the command-line flags, as this flag is mainly useful for testing: Grpc
	// stack will hold on to the logger even though it gets closed. This causes data races.
	LogGrpc bool
	// contains filtered or unexported fields
}

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

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions 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) AttachFlags

func (o *Options) AttachFlags(
	stringArrayVar func(p *[]string, name string, value []string, usage string),
	stringVar func(p *string, name string, value string, usage string),
	intVar func(p *int, name string, value int, usage string),
	boolVar func(p *bool, name string, value bool, usage string))

AttachFlags allows attaching of flags through a set of lambda functions.

func (*Options) GetLogCallers

func (o *Options) GetLogCallers(scope string) bool

GetLogCallers returns whether the caller's source code location is output for a given scope.

func (*Options) GetOutputLevel

func (o *Options) GetOutputLevel(scope string) (Level, error)

GetOutputLevel returns the minimum log output level for a given scope.

func (*Options) GetStackTraceLevel

func (o *Options) GetStackTraceLevel(scope string) (Level, error)

GetStackTraceLevel returns the minimum stack tracing level for a given scope.

func (*Options) SetLogCallers

func (o *Options) SetLogCallers(scope string, include bool)

SetLogCallers sets whether to output the caller's source code location for a given scope.

func (*Options) SetOutputLevel

func (o *Options) SetOutputLevel(scope string, level Level)

SetOutputLevel sets the minimum log output level for a given scope.

func (*Options) SetStackTraceLevel

func (o *Options) SetStackTraceLevel(scope string, level Level)

SetStackTraceLevel sets the minimum stack tracing level for a given scope.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope let's you log data for an area of code, enabling the user full control over the level of logging output produced.

func FindScope

func FindScope(scope string) *Scope

FindScope returns a previously registered scope, or nil if the named scope wasn't previously registered

func RegisterScope

func RegisterScope(name string, description string, callerSkip int) *Scope

RegisterScope registers a new logging scope. If the same name is used multiple times for a single process, the same Scope struct is returned.

Scope names cannot include colons, commas, or periods.

func (*Scope) Debug

func (s *Scope) Debug(msg string, fields ...zapcore.Field)

Debug outputs a message at debug level.

func (*Scope) DebugEnabled

func (s *Scope) DebugEnabled() bool

DebugEnabled returns whether output of messages using this scope is currently enabled for debug-level output.

func (*Scope) Debuga

func (s *Scope) Debuga(args ...interface{})

Debuga uses fmt.Sprint to construct and log a message at debug level.

func (*Scope) Debugf

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

Debugf uses fmt.Sprintf to construct and log a message at debug level.

func (*Scope) Description

func (s *Scope) Description() string

Description returns this scope's description

func (*Scope) Error

func (s *Scope) Error(msg string, fields ...zapcore.Field)

Error outputs a message at error level.

func (*Scope) ErrorEnabled

func (s *Scope) ErrorEnabled() bool

ErrorEnabled returns whether output of messages using this scope is currently enabled for error-level output.

func (*Scope) Errora

func (s *Scope) Errora(args ...interface{})

Errora uses fmt.Sprint to construct and log a message at error level.

func (*Scope) Errorf

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

Errorf uses fmt.Sprintf to construct and log a message at error level.

func (*Scope) Fatal

func (s *Scope) Fatal(msg string, fields ...zapcore.Field)

Fatal outputs a message at fatal level.

func (*Scope) FatalEnabled

func (s *Scope) FatalEnabled() bool

FatalEnabled returns whether output of messages using this scope is currently enabled for fatal-level output.

func (*Scope) Fatala

func (s *Scope) Fatala(args ...interface{})

Fatala uses fmt.Sprint to construct and log a message at fatal level.

func (*Scope) Fatalf

func (s *Scope) Fatalf(template string, args ...interface{})

Fatalf uses fmt.Sprintf to construct and log a message at fatal level.

func (*Scope) GetLogCallers

func (s *Scope) GetLogCallers() bool

GetLogCallers returns the output level associated with the scope.

func (*Scope) GetOutputLevel

func (s *Scope) GetOutputLevel() Level

GetOutputLevel returns the output level associated with the scope.

func (*Scope) GetStackTraceLevel

func (s *Scope) GetStackTraceLevel() Level

GetStackTraceLevel returns the stack tracing level associated with the scope.

func (*Scope) Info

func (s *Scope) Info(msg string, fields ...zapcore.Field)

Info outputs a message at info level.

func (*Scope) InfoEnabled

func (s *Scope) InfoEnabled() bool

InfoEnabled returns whether output of messages using this scope is currently enabled for info-level output.

func (*Scope) Infoa

func (s *Scope) Infoa(args ...interface{})

Infoa uses fmt.Sprint to construct and log a message at info level.

func (*Scope) Infof

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

Infof uses fmt.Sprintf to construct and log a message at info level.

func (*Scope) Name

func (s *Scope) Name() string

Name returns this scope's name.

func (*Scope) SetLogCallers

func (s *Scope) SetLogCallers(logCallers bool)

SetLogCallers adjusts the output level associated with the scope.

func (*Scope) SetOutputLevel

func (s *Scope) SetOutputLevel(l Level)

SetOutputLevel adjusts the output level associated with the scope.

func (*Scope) SetStackTraceLevel

func (s *Scope) SetStackTraceLevel(l Level)

SetStackTraceLevel adjusts the stack tracing level associated with the scope.

func (*Scope) Warn

func (s *Scope) Warn(msg string, fields ...zapcore.Field)

Warn outputs a message at warn level.

func (*Scope) WarnEnabled

func (s *Scope) WarnEnabled() bool

WarnEnabled returns whether output of messages using this scope is currently enabled for warn-level output.

func (*Scope) Warna

func (s *Scope) Warna(args ...interface{})

Warna uses fmt.Sprint to construct and log a message at warn level.

func (*Scope) Warnf

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

Warnf uses fmt.Sprintf to construct and log a message at warn level.

Jump to

Keyboard shortcuts

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