ezdbg

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: MIT Imports: 13 Imported by: 0

README

ezdgb

GoDoc Go Report Card Issues GitHub release MIT License

ezdbg provides easy to use utilities which helps to do quick development.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Caller

func Caller(skip int) (name, file string, line int)

Caller returns function name, filename, and the line number of the caller. The argument skip is the number of stack frames to ascend, with 0 identifying the caller of Caller.

func CallerName

func CallerName() string

CallerName returns the function name of the direct caller. This is a convenient wrapper around Caller.

func Config

func Config(cfg Cfg)

func DEBUG

func DEBUG(args ...interface{})

DEBUG is debug message logger which do nothing if debug level is not enabled (the default). It gives best 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 ...interface{})

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 DUMP

func DUMP(args ...interface{})

DUMP is similar to DEBUG, but it calls spew.Sdump to format non-basic-type data.

func DUMPSkip

func DUMPSkip(skip int, args ...interface{})

DUMPSkip is similar to DUMP, 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 JSON

func JSON(v interface{}) string

func Logfmt

func Logfmt(v interface{}) string

Logfmt converts given object to a string in logfmt format, it never returns error. Note that only struct and map of basic types are supported, non-basic types are simply ignored.

func PRETTY added in v0.2.0

func PRETTY(args ...interface{})

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

func PRETTYSkip added in v0.2.0

func PRETTYSkip(skip int, args ...interface{})

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".

func Pretty added in v0.2.0

func Pretty(v interface{}) string

Pretty converts given object to a pretty formatted json string. If the input is a json string, it will be formatted using json.Indent with four space characters as indent.

func Pretty2 added in v0.2.0

func Pretty2(v interface{}) string

Pretty2 is like Pretty, but it uses two space characters as indent, instead of four.

func SPEW

func SPEW(args ...interface{})

SPEW is similar to DEBUG, but it calls spew.Sprintf to format non-basic-type data.

func SPEWSkip

func SPEWSkip(skip int, args ...interface{})

SPEWSkip is similar to SPEW, 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 func(context.Context) bool
	LoggerFunc  func(context.Context) DebugLogger
}

type DebugLogger

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

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 ...interface{})

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 ...interface{})

Jump to

Keyboard shortcuts

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