logger

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: MIT Imports: 9 Imported by: 6

README

logger

this is just a wrapper on zap

Integration

either you can import default config and edit it out according to your needs or you can use Config struct to create your own config. for example:

  • importing default config and then edit out the values according to your needs
lOptions := logger.ConfigDefault

// edit it according to your needs
  • creating your own config
lOptions := logger.Options{
	JSONEncoding: true,
}
  • pass those options inside Configure function to initialize the logger.
err := logger.Configure(lOptions)

and then you can use that logger according to your needs.

Example

below are the examples which gonna help you to get started with the the integration.

example

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{

	Output:    os.Stdout,
	ErrOutput: os.Stderr,
	LogGrpc:   true,
	// contains filtered or unexported fields
}

ConfigDefault it is the set of default configs

Functions

func Configure

func Configure(config ...Config) 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(args ...interface{})

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 Error

func Error(msg string, fields ...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 Info

func Info(msg string, fields ...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 Sync

func Sync() error

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 ...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 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 Config added in v0.0.2

type Config struct {

	// 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

	// 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

	// Output is a writer where logs are written
	//
	// Default: os.Stdout
	Output io.Writer

	// ErrOutput is a writer where logs are written
	//
	// Default: os.Stderr
	ErrOutput io.Writer

	// IsEncoding enables encoding in logging
	//
	// Default: false
	IsEncoding bool

	// EncoderConfig has encoder config which helps in encoding
	EncoderConfig EncoderConfig
	// contains filtered or unexported fields
}

Config defines the set of cfg supported by Istio's component logging package.

func (*Config) GetOutputLevel added in v0.0.2

func (o *Config) GetOutputLevel() (Level, error)

GetOutputLevel returns the minimum log output level.

func (*Config) GetStackTraceLevel added in v0.0.2

func (o *Config) GetStackTraceLevel() (Level, error)

GetStackTraceLevel returns the current stack trace level.

func (*Config) SetOutputLevel added in v0.0.2

func (o *Config) SetOutputLevel(level Level) error

SetOutputLevel sets the minimum log output level.

func (*Config) SetStackTraceLevel added in v0.0.2

func (o *Config) SetStackTraceLevel(level Level) error

SetStackTraceLevel sets the minimum stack trace capture level.

type EncoderConfig

type EncoderConfig struct {
	// Path is array consists of all the json path.
	Path []string

	// EncoderFunc function which helps in encoding the string.
	EncoderFunc func(string) string
}

type Field

type Field struct {
	Key   string
	Value interface{}
}

type Level

type Level string

Level is an enumeration of all supported log levels.

const (
	// DebugLevel enables debug level logging
	DebugLevel Level = "debug"
	// InfoLevel enables info level logging
	InfoLevel Level = "info"
	// WarnLevel enables warn level logging
	WarnLevel Level = "warn"
	// ErrorLevel enables error level logging
	ErrorLevel Level = "error"
	// NoneLevel disables logging
	NoneLevel Level = "none"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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