ezdbg

package
v2.14.8 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const FilterRuleEnvName = "EZDBG_FILTER_RULE"

Variables

This section is empty.

Functions

func Config

func Config(cfg Cfg)

Config configures the behavior of functions in this package.

func DEBUG

func DEBUG(args ...any)

DEBUG is debug message logger which do nothing if debug level is not enabled (the default). It has good performance for production deployment by eliminating unnecessary parameter evaluation and control flows.

DEBUG accepts very flexible arguments to help development, see the following examples:

// func()
DEBUG(func() {
	logrus.Debug(something)
	for _, item := range someSlice {
		logrus.Debug(item)
	}
})

// logger from context with or without format
DEBUG(ctx, 1, 2, 3)
DEBUG(ctx, "a=%v b=%v c=%v", 1, 2, 3)

// log variables with or without format
DEBUG(1, 2, 3)
DEBUG("a=%v b=%v c=%v", 1, 2, 3)

// optionally a DebugLogger can be provided as the first parameter
logger := logrus.WithField("key", "dummy")
DEBUG(logger, "aa", 2, 3)
DEBUG(logger, "a=%v b=%v c=%v", "aa", 2, 3)

// or a function which returns a logger implements DebugLogger
logger := func() *logrus.Entry { ... }
DEBUG(logger, "aa", 2, 3)
DEBUG(logger, "a=%v b=%v c=%v", "aa", 2, 3)

// or a print function to print the log message
logger := logrus.Debugf
DEBUG(logger, "aa", 2, 3)
DEBUG(logger, "a=%v b=%v c=%v", "aa", 2, 3)

// non-basic-type values will be formatted using json
obj := &SomeStructType{Field1: "blah", Field2: 1234567, Field3: true}
DEBUG(logger, "obj=%v", obj)

func DEBUGSkip

func DEBUGSkip(skip int, args ...any)

DEBUGSkip is similar to DEBUG, but it has an extra skip param to skip stacktrace to get correct caller information. When you wrap functions in this package, you always want to use the functions which end with "Skip".

func PRETTY

func PRETTY(args ...any)

PRETTY is similar to DEBUG, but it calls Pretty to format non-basic-type data.

func PRETTYSkip

func PRETTYSkip(skip int, args ...any)

PRETTYSkip is similar to PRETTY, but it has an extra skip param to skip stacktrace to get correct caller information. When you wrap functions in this package, you always want to use the functions which end with "Skip".

Types

type Cfg

type Cfg struct {

	// EnableDebug determines whether debug log is enabled, it may use
	// the given context.Context to enable or disable request-level debug log.
	// If EnableDebug returns false, the log message is discarded.
	//
	// User must configure this to enable debug log from this package.
	// By default, functions in this package discard all messages.
	EnableDebug func(context.Context) bool

	// LoggerFunc optionally retrieves DebugLogger from a context.Context.
	LoggerFunc func(context.Context) DebugLogger

	// FilterRule optionally configures filter rule to allow or deny log messages
	// in some packages or files.
	//
	// It uses glob to match filename, the syntax is "allow=glob1,glob2;deny=glob3,glob4".
	// For example:
	//
	// - "", empty rule means allow all messages
	// - "allow=all", allow all messages
	// - "deny=all", deny all messages
	// - "allow=pkg1/*,pkg2/*.go",
	//   allow messages from files in `pkg1` and `pkg2`,
	//   deny messages from all other packages
	// - "allow=pkg1/sub1/abc.go,pkg1/sub2/def.go",
	//   allow messages from file `pkg1/sub1/abc.go` and `pkg1/sub2/def.go`,
	//   deny messages from all other files
	// - "allow=pkg1/**",
	//   allow messages from files and sub-packages in `pkg1`,
	//   deny messages from all other packages
	// - "deny=pkg1/**.go,pkg2/**.go",
	//   deny messages from files and sub-packages in `pkg1` and `pkg2`,
	//   allow messages from all other packages
	// - "allow=all;deny=pkg/**", same as "deny=pkg/**"
	//
	// If both "allow" and "deny" directives are configured, the "allow" directive
	// takes effect, the "deny" directive is ignored.
	//
	// The default value is empty, which means all messages are allowed.
	//
	// User can also set the environment variable "EZDBG_FILTER_RULE"
	// to configure it at runtime, if available, the environment variable
	// is used when this value is empty.
	FilterRule string
	// contains filtered or unexported fields
}

Cfg provides optional config to configure this package.

type DebugLogger

type DebugLogger interface {
	Debugf(format string, args ...any)
}

DebugLogger is an interface which log an message at DEBUG level. It's implemented by *logrus.Logger, *logrus.Entry, *zap.SugaredLogger, and many other logging packages.

type PrintFunc

type PrintFunc func(format string, args ...any)

PrintFunc is a function to print the given arguments in format to somewhere. It implements the interface `ErrDebugLogger`.

func (PrintFunc) Debugf

func (f PrintFunc) Debugf(format string, args ...any)

Jump to

Keyboard shortcuts

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