log

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OutputModeJson    = "json"
	OutputModeConsole = "console"
)

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message.

func Debugc added in v0.16.0

func Debugc(ctx context.Context, msgFormat string, args ...interface{})

Debugc use WithCtx and fmt.Sprintf to log a template message.

func Debugf

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

Debugf uses fmt.Sprintf to log a template message.

func Error

func Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func Errorc added in v0.16.0

func Errorc(ctx context.Context, msgFormat string, args ...interface{})

Errorc use WithCtx and fmt.Sprintf to log a template message.

func Errorf

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

Errorf uses fmt.Sprintf to log a template message.

func Fatal

func Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.

func Fatalc added in v0.16.0

func Fatalc(ctx context.Context, msgFormat string, args ...interface{})

Fatalc use WithCtx and fmt.Sprintf to log a template message.

func Fatalf

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

Fatalf uses fmt.Sprintf to log a template message, then calls os.Exit.

func Info

func Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

func Infoc added in v0.16.0

func Infoc(ctx context.Context, msgFormat string, args ...interface{})

Infoc use WithCtx and fmt.Sprintf to log a template message.

func Infof

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

Infof uses fmt.Sprintf to log a template message.

func Panic added in v0.15.0

func Panic(args ...interface{})

Panic uses fmt.Sprint to construct and log a message, then panics.

func Panicc added in v0.16.0

func Panicc(ctx context.Context, msgFormat string, args ...interface{})

Panicc use WithCtx and fmt.Sprintf to log a template message.

func Panicf added in v0.15.0

func Panicf(msgFormat string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func ReplaceGlobal

func ReplaceGlobal(logger *ZapLogger)

ReplaceGlobal Register a logger instance as global

func Warn

func Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

func Warnc added in v0.16.0

func Warnc(ctx context.Context, msgFormat string, args ...interface{})

Warnc use WithCtx and fmt.Sprintf to log a template message.

func Warnf

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

Warnf uses fmt.Sprintf to log a template message.

Types

type ContextExtractor added in v0.15.0

type ContextExtractor func(ctx context.Context) []field.Field

type ContextExtractors added in v0.15.0

type ContextExtractors []ContextExtractor

func (ContextExtractors) Extract added in v0.15.0

func (c ContextExtractors) Extract(ctx context.Context) []field.Field

func (ContextExtractors) IsExtractable added in v0.15.0

func (c ContextExtractors) IsExtractable() bool

type ContextualLogger added in v0.16.0

type ContextualLogger interface {
	// Debugc formats the message according to the format specifier
	// with some additional info in the context and logs it at debug level.
	Debugc(ctx context.Context, template string, args ...interface{})

	// Infoc formats the message according to the format specifier
	// with some additional info in the context and logs it at info level.
	Infoc(ctx context.Context, template string, args ...interface{})

	// Warnc formats the message according to the format specifier
	// with some additional info in the context and logs it at warn level.
	Warnc(ctx context.Context, template string, args ...interface{})

	// Errorc formats the message according to the format specifier
	// with some additional info in the context and logs it at error level.
	Errorc(ctx context.Context, template string, args ...interface{})

	// Fatalc formats the message according to the format specifier
	// with some additional info in the context and calls os.Exit.
	Fatalc(ctx context.Context, template string, args ...interface{})

	// Panicc formats the message according to the format specifier
	// with some additional info in the context and panics.
	Panicc(ctx context.Context, template string, args ...interface{})
}

type FiledKey added in v0.15.0

type FiledKey int
const (
	FieldKeyErr FiledKey = iota
	FieldKeyTime
	FieldKeyLevel
	FieldKeyName
	FieldKeyCaller
	FieldKeyFunc
	FieldKeyMsg
	FieldKeyStacktrace
)

type Logger

type Logger interface {
	StdLogger
	ContextualLogger

	// WithCtx adds additional info in the context and
	// additional fields to the logging context.
	WithCtx(ctx context.Context, additionalFields ...field.Field) Logger

	// WithField adds a variadic number of fields to the logging context.
	WithField(fields ...field.Field) Logger

	// WithError adds an error with FieldKeyErr field to the logging context.
	WithError(err error) Logger

	// WithErrors adds a field with FieldKeyErr field that carries a slice of errors.
	WithErrors(errs ...error) Logger

	// WithAny adds a key and an arbitrary value and chooses the best way to represent
	// them as a field.
	WithAny(key string, value interface{}) Logger
}

func GetGlobal

func GetGlobal() Logger

GetGlobal Get global logger instance

func WithAny added in v0.15.0

func WithAny(key string, value interface{}) Logger

func WithCtx added in v0.15.0

func WithCtx(ctx context.Context, additionalFields ...field.Field) Logger

func WithError added in v0.15.0

func WithError(err error) Logger

func WithErrors added in v0.15.0

func WithErrors(errs ...error) Logger

func WithField added in v0.15.0

func WithField(fields ...field.Field) Logger

type OptionFunc

type OptionFunc func(opt *Options)

func AddCallerSkip

func AddCallerSkip(skip int) OptionFunc

type Options

type Options struct {
	// Development puts the logger in development mode, which changes the
	// behavior of DPanicLevel and takes stack traces more liberally.
	Development bool

	// LogLevel is the minimum enabled logging level.
	// In Development mode, LogLevel will be set to DEBUG,
	// Opposite, LogLevel will be set to INFO mode automatically.
	LogLevel string

	// JsonOutputMode Enable or disable json output mode.
	JsonOutputMode bool

	// DisableCaller stops annotating logs with the calling function's file
	// name and line number. By default, all logs are annotated.
	DisableCaller bool

	// DisableStacktrace completely disables automatic stacktrace capturing. By
	// default, stacktrace-s are captured for WarnLevel and above logs in
	// development and ErrorLevel and above in production.
	DisableStacktrace bool

	// CallerSkip Set the number of callers
	// will be skipped before show caller
	CallerSkip int

	// FieldKeyMap Set the keys used for each log entry.
	// If any key is empty, that portion of the entry is omitted.
	FieldKeyMap map[FiledKey]string

	// ContextExtractors Define the list of extractors
	// that will be used when extract value from log context.
	ContextExtractors ContextExtractors
}

type Properties

type Properties struct {
	// Development puts the logger in development mode, which changes the
	// behavior of DPanicLevel and takes stack traces more liberally.
	Development bool `default:"false"`

	// LogLevel is the minimum enabled logging level.
	// In Development mode, LogLevel will be set to DEBUG,
	// Opposite, LogLevel will be set to INFO mode automatically.
	LogLevel string

	// JsonOutputMode Enable or disable json output mode.
	JsonOutputMode bool `default:"true"`

	// DisableCaller stops annotating logs with the calling function's file
	// name and line number. By default, all logs are annotated.
	DisableCaller bool

	// DisableStacktrace completely disables automatic stacktrace capturing. By
	// default, stacktrace-s are captured for WarnLevel and above logs in
	// development and ErrorLevel and above in production.
	DisableStacktrace bool

	// CallerSkip Set the number of callers
	// will be skipped before show caller
	CallerSkip int `default:"1"`
}

func NewProperties

func NewProperties(loader config.Loader) (*Properties, error)

func (Properties) Prefix

func (l Properties) Prefix() string

type StdLogger added in v0.15.0

type StdLogger interface {
	// Debug logs the provided arguments at debug level.
	// Spaces are added between arguments when neither is a string.
	Debug(args ...interface{})

	// Info logs the provided arguments at debug level.
	// Spaces are added between arguments when neither is a string.
	Info(args ...interface{})

	// Warn logs the provided arguments at debug level.
	// Spaces are added between arguments when neither is a string.
	Warn(args ...interface{})

	// Error logs the provided arguments at debug level.
	// Spaces are added between arguments when neither is a string.
	Error(args ...interface{})

	// Fatal constructs a message with the provided arguments and calls os.Exit.
	// Spaces are added between arguments when neither is a string.
	Fatal(args ...interface{})

	// Panic constructs a message with the provided arguments and panics.
	// Spaces are added between arguments when neither is a string.
	Panic(args ...interface{})

	// Debugf formats the message according to the format specifier
	// and logs it at debug level.
	Debugf(template string, args ...interface{})

	// Infof formats the message according to the format specifier
	// and logs it at info level.
	Infof(template string, args ...interface{})

	// Warnf formats the message according to the format specifier
	// and logs it at warn level.
	Warnf(template string, args ...interface{})

	// Errorf formats the message according to the format specifier
	// and logs it at error level.
	Errorf(template string, args ...interface{})

	// Fatalf formats the message according to the format specifier
	// and calls os.Exit.
	Fatalf(template string, args ...interface{})

	// Panicf formats the message according to the format specifier
	// and panics.
	Panicf(template string, args ...interface{})
}

type TestingLogger

type TestingLogger struct {
	*ZapLogger
	// contains filtered or unexported fields
}

func NewTestingLogger

func NewTestingLogger(tb testing.TB, options *Options) (*TestingLogger, error)

func NewTestingLoggerFromDefault

func NewTestingLoggerFromDefault(tb testing.TB, defaultLogger *ZapLogger) *TestingLogger

type TestingWriter

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

TestingWriter is a WriteSyncer that writes to the given testing.TB.

func NewTestingWriter

func NewTestingWriter(tb testing.TB) TestingWriter

func (TestingWriter) Sync

func (w TestingWriter) Sync() error

func (TestingWriter) Write

func (w TestingWriter) Write(p []byte) (n int, err error)

type ZapLogger added in v0.15.0

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

func NewZapLogger added in v0.15.0

func NewZapLogger(opts *Options) (*ZapLogger, error)

func (*ZapLogger) Clone added in v0.15.0

func (l *ZapLogger) Clone(addedCallerSkip int, fields ...field.Field) *ZapLogger

func (*ZapLogger) Debug added in v0.15.0

func (l *ZapLogger) Debug(args ...interface{})

func (*ZapLogger) Debugc added in v0.16.0

func (l *ZapLogger) Debugc(ctx context.Context, template string, args ...interface{})

func (*ZapLogger) Debugf added in v0.15.0

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

func (*ZapLogger) Error added in v0.15.0

func (l *ZapLogger) Error(args ...interface{})

func (*ZapLogger) Errorc added in v0.16.0

func (l *ZapLogger) Errorc(ctx context.Context, template string, args ...interface{})

func (*ZapLogger) Errorf added in v0.15.0

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

func (*ZapLogger) Fatal added in v0.15.0

func (l *ZapLogger) Fatal(args ...interface{})

func (*ZapLogger) Fatalc added in v0.16.0

func (l *ZapLogger) Fatalc(ctx context.Context, template string, args ...interface{})

func (*ZapLogger) Fatalf added in v0.15.0

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

func (*ZapLogger) Info added in v0.15.0

func (l *ZapLogger) Info(args ...interface{})

func (*ZapLogger) Infoc added in v0.16.0

func (l *ZapLogger) Infoc(ctx context.Context, template string, args ...interface{})

func (*ZapLogger) Infof added in v0.15.0

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

func (*ZapLogger) Panic added in v0.15.0

func (l *ZapLogger) Panic(args ...interface{})

func (*ZapLogger) Panicc added in v0.16.0

func (l *ZapLogger) Panicc(ctx context.Context, template string, args ...interface{})

func (*ZapLogger) Panicf added in v0.15.0

func (l *ZapLogger) Panicf(template string, args ...interface{})

func (*ZapLogger) Warn added in v0.15.0

func (l *ZapLogger) Warn(args ...interface{})

func (*ZapLogger) Warnc added in v0.16.0

func (l *ZapLogger) Warnc(ctx context.Context, template string, args ...interface{})

func (*ZapLogger) Warnf added in v0.15.0

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

func (*ZapLogger) WithAny added in v0.15.0

func (l *ZapLogger) WithAny(key string, value interface{}) Logger

func (*ZapLogger) WithCtx added in v0.15.0

func (l *ZapLogger) WithCtx(ctx context.Context, additionalFields ...field.Field) Logger

func (*ZapLogger) WithError added in v0.15.0

func (l *ZapLogger) WithError(err error) Logger

func (*ZapLogger) WithErrors added in v0.15.0

func (l *ZapLogger) WithErrors(errs ...error) Logger

func (*ZapLogger) WithField added in v0.15.0

func (l *ZapLogger) WithField(fields ...field.Field) Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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