logutil

package
v7.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: Apache-2.0, Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MetricTableCreatedCounter = prometheus.NewCounter(prometheus.CounterOpts{
	Namespace: "BR",
	Name:      "table_created",
	Help:      "The count of tables have been created.",
})

MetricTableCreatedCounter counts how many tables created. TODO: when br decided to introduce Prometheus, move this to its metric package.

Functions

func AShortError

func AShortError(key string, err error) zap.Field

AShortError make the zap field with key to display error without verbose representation (e.g. the stack trace).

func AbbreviatedArray

func AbbreviatedArray(
	key string, elements interface{}, marshalFunc func(interface{}) []string,
) zap.Field

AbbreviatedArray constructs a field that abbreviates an array of elements.

func CL

func CL(c context.Context) *zap.Logger

CL is the shorthand for LoggerFromContext.

func ContextWithField

func ContextWithField(c context.Context, fields ...zap.Field) context.Context

ContextWithField wrap a context with a logger with some fields.

func File

func File(file *backuppb.File) zap.Field

File make the zap fields for a file.

func Files

func Files(fs []*backuppb.File) zap.Field

Files make the zap field for a set of file.

func Key

func Key(fieldKey string, key []byte) zap.Field

Key constructs a field that carries upper hex format key.

func Keys

func Keys(keys [][]byte) zap.Field

Keys constructs a field that carries upper hex format keys.

func Leader

func Leader(peer *metapb.Peer) zap.Field

Leader make the zap fields for a peer as leader. nolint:interfacer

func LoggerFromContext

func LoggerFromContext(c context.Context) *zap.Logger

LoggerFromContext returns the contextual logger via the context. If there isn't a logger in the context, returns the global logger.

func Peer

func Peer(peer *metapb.Peer) zap.Field

Peer make the zap fields for a peer.

func Redact

func Redact(field zap.Field) zap.Field

Redact replaces the zap field by a '?' if redaction is turned on.

func RedactAny

func RedactAny(fieldKey string, key interface{}) zap.Field

RedactAny constructs a redacted field that carries an interface{}.

func Region

func Region(region *metapb.Region) zap.Field

Region make the zap fields for a region.

func RegionBy

func RegionBy(key string, region *metapb.Region) zap.Field

RegionBy make the zap fields for a region with name.

func ResetGlobalLogger

func ResetGlobalLogger(l *zap.Logger)

ResetGlobalLogger resets the global logger. Contexts have already made by `ContextWithField` would keep untouched, subsequent wrapping over those contexts would keep using the old global logger, only brand new contexts (i.e. context without logger) would be wrapped with the new global logger. This method is mainly for testing.

func RewriteRule

func RewriteRule(rewriteRule *import_sstpb.RewriteRule) zap.Field

RewriteRule make the zap fields for a rewrite rule.

func RewriteRuleObject

func RewriteRuleObject(rewriteRule *import_sstpb.RewriteRule) zapcore.ObjectMarshaler

RewriteRuleObject make zap object marshaler for a rewrite rule.

func SSTMeta

func SSTMeta(sstMeta *import_sstpb.SSTMeta) zap.Field

SSTMeta make the zap fields for a SST meta.

func SSTMetas

func SSTMetas(sstMetas []*import_sstpb.SSTMeta) zap.Field

SSTMetas make the zap fields for SST metas.

func ShortError

func ShortError(err error) zap.Field

ShortError make the zap field to display error without verbose representation (e.g. the stack trace).

func StreamBackupTaskInfo

func StreamBackupTaskInfo(t *backuppb.StreamBackupTaskInfo) zap.Field

StreamBackupTaskInfo makes the zap fields for a stream backup task info.

func StringifyMany

func StringifyMany[T fmt.Stringer](items []T) zapcore.ArrayMarshaler

StringifyMany returns an array marshaler for a slice of stringers.

func WarnTerm

func WarnTerm(message string, fields ...zap.Field)

WarnTerm put a log both to terminal and to the log file.

Types

type AbbreviatedArrayMarshaler

type AbbreviatedArrayMarshaler []string

AbbreviatedArrayMarshaler abbreviates an array of elements.

func (AbbreviatedArrayMarshaler) MarshalLogArray

func (abb AbbreviatedArrayMarshaler) MarshalLogArray(encoder zapcore.ArrayEncoder) error

MarshalLogArray implements zapcore.ArrayMarshaler.

type RateTracer

type RateTracer struct {
	prometheus.Counter
	// contains filtered or unexported fields
}

RateTracer is a trivial rate tracer based on a prometheus counter. It traces the average speed from it was created.

func TraceRateOver

func TraceRateOver(counter prometheus.Counter) RateTracer

TraceRateOver make a trivial rater based on a counter. the current value of this counter would be omitted.

func (*RateTracer) L

func (r *RateTracer) L() *zap.Logger

L make a logger with the current speed.

func (*RateTracer) Rate

func (r *RateTracer) Rate() float64

Rate returns the average rate from when it was created.

func (*RateTracer) RateAt

func (r *RateTracer) RateAt(instant time.Time) float64

RateAt returns the rate until some instant. This function is mainly for testing. WARN: the counter value for calculating is still its CURRENT VALUE.

type StringifyKeys

type StringifyKeys []kv.KeyRange

StringifyKeys wraps the key range into a stringer.

func (StringifyKeys) String

func (kr StringifyKeys) String() string

type StringifyRange

type StringifyRange kv.KeyRange

StringifyRange is the wrapper for displaying a key range.

func (StringifyRange) String

func (rng StringifyRange) String() string

Jump to

Keyboard shortcuts

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