logutil

package
v0.0.0-...-7f57e1f Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: Apache-2.0 Imports: 15 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// HideSensitive is used to replace sensitive information with `******` in log.
	HideSensitive = func(input string) string {
		output := passwordRegexp.ReplaceAllString(input, "$1******$4")
		output = sslRegexp.ReplaceAllString(output, "$1 \"******\"")
		output = sslStringRegexp.ReplaceAllString(output, "$1 \"******\"")
		return output
	}
)

Functions

func ErrorFilterContextCanceled

func ErrorFilterContextCanceled(logger *zap.Logger, msg string, fields ...zap.Field)

ErrorFilterContextCanceled log the msg and fields but do nothing if fields have cancel error

func FromContext

func FromContext(ctx context.Context) *zap.Logger

FromContext return the logger in context, or return global logger if logger not found in context

func InitGinLogWritter

func InitGinLogWritter() io.Writer

InitGinLogWritter initialize loggers for Gin.

func InitLogger

func InitLogger(cfg *Config, opts ...LoggerOpt) error

InitLogger initializes logger

func NewContextWithLogger

func NewContextWithLogger(ctx context.Context, logger *zap.Logger) context.Context

NewContextWithLogger attaches a new logger to context and return the context

func SetLogLevel

func SetLogLevel(level string) error

SetLogLevel changes TiCDC log level dynamically.

func ShortError

func ShortError(err error) zap.Field

ShortError contructs a field which only records the error message without the verbose text (i.e. excludes the stack trace).

func WithComponent

func WithComponent(component string) *zap.Logger

WithComponent return a logger with specified component scope

func ZapErrorFilter

func ZapErrorFilter(err error, filterErrors ...error) zap.Field

ZapErrorFilter wraps zap.Error, if err is in given filterErrors, it will be set to nil

Types

type Config

type Config struct {
	// Log level.
	Level string `toml:"level" json:"level"`
	// Log filename, leave empty to disable file log.
	File string `toml:"file" json:"file"`
	// Max size for a single file, in MB.
	FileMaxSize int `toml:"max-size" json:"max-size"`
	// Max log keep days, default is never deleting.
	FileMaxDays int `toml:"max-days" json:"max-days"`
	// Maximum number of old log files to retain.
	FileMaxBackups int `toml:"max-backups" json:"max-backups"`
	// ZapInternalErrOutput specify where the internal error of zap logger should be send to.
	ZapInternalErrOutput string `toml:"error-output" json:"error-output"`
}

Config serializes log related config in toml/json.

func (*Config) Adjust

func (cfg *Config) Adjust()

Adjust adjusts config

type LoggerOpt

type LoggerOpt func(*loggerOp)

LoggerOpt is the logger option

func WithInitGRPCLogger

func WithInitGRPCLogger() LoggerOpt

WithInitGRPCLogger enables grpc logger initialization when initializes global logger

func WithInitMySQLLogger

func WithInitMySQLLogger() LoggerOpt

WithInitMySQLLogger enables mysql logger initialization when initializes global logger

func WithInitSaramaLogger

func WithInitSaramaLogger() LoggerOpt

WithInitSaramaLogger enables sarama logger initialization when initializes global logger

func WithOutputWriteSyncer

func WithOutputWriteSyncer(output zapcore.WriteSyncer) LoggerOpt

WithOutputWriteSyncer will replace the WriteSyncer of global logger with customized WriteSyncer Easy for test when using zaptest.Buffer as WriteSyncer

Jump to

Keyboard shortcuts

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