rzlog

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 21 Imported by: 1

README

RZ-log

Documentation

Index

Constants

View Source
const (
	PackageName = "RZ_LOG"
)

Variables

View Source
var DefaultDurationToField = DurationToTimeMillisField

DefaultDurationToField is the default implementation of converting request duration to a log field (key and value).

Functions

func Debug

func Debug(ctx context.Context, args ...interface{})

func DebugKV

func DebugKV(ctx context.Context, kv KV, args ...interface{})

func DebugKVf

func DebugKVf(ctx context.Context, kv KV, msg string, args ...interface{})

func Debugf

func Debugf(ctx context.Context, msg string, args ...interface{})

func DefaultClientCodeToLevel

func DefaultClientCodeToLevel(code codes.Code) logrus.Level

DefaultClientCodeToLevel is the default implementation of gRPC return codes to log levels for client side.

func DefaultCodeToLevel

func DefaultCodeToLevel(code codes.Code) logrus.Level

DefaultCodeToLevel is the default implementation of gRPC return codes to log levels for server side.

func DefaultDeciderMethod

func DefaultDeciderMethod(fullMethodName string, err error) bool

func DefaultErrorToCode

func DefaultErrorToCode(err error) codes.Code

func DefaultMessageProducer

func DefaultMessageProducer(ctx context.Context, format string, level logrus.Level, code codes.Code, err error, fields logrus.Fields)

DefaultMessageProducer writes the default message

func DurationToDurationField

func DurationToDurationField(duration time.Duration) (key string, value interface{})

DurationToDurationField uses the duration value to log the request duration.

func DurationToTimeMillisField

func DurationToTimeMillisField(duration time.Duration) (key string, value interface{})

DurationToTimeMillisField converts the duration to milliseconds and uses the key `grpc.time_ms`.

func Error

func Error(ctx context.Context, err error, args ...interface{})

func ErrorKV

func ErrorKV(ctx context.Context, err error, kv KV, args ...interface{})

func ErrorKVf

func ErrorKVf(ctx context.Context, err error, kv KV, msg string, args ...interface{})

func Errorf

func Errorf(ctx context.Context, err error, msg string, args ...interface{})

func Info

func Info(ctx context.Context, args ...interface{})

func InfoKV

func InfoKV(ctx context.Context, kv KV, args ...interface{})

func InfoKVf

func InfoKVf(ctx context.Context, kv KV, msg string, args ...interface{})

func Infof

func Infof(ctx context.Context, msg string, args ...interface{})

func NewRequestLogger

func NewRequestLogger() func(next http.Handler) http.Handler

func SetLogLevel

func SetLogLevel(level string) error

func StreamServerInterceptor

func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor

func TwirpServerLoggingHook added in v1.0.1

func TwirpServerLoggingHook() *twirp.ServerHooks

func UnaryServerInterceptor

func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor

func Warn

func Warn(ctx context.Context, args ...interface{})

func WarnKV

func WarnKV(ctx context.Context, kv KV, args ...interface{})

func WarnKVf

func WarnKVf(ctx context.Context, kv KV, msg string, args ...interface{})

func Warnf

func Warnf(ctx context.Context, msg string, args ...interface{})

Types

type CodeToLevel

type CodeToLevel func(code codes.Code) logrus.Level

CodeToLevel function defines the mapping between gRPC return codes and interceptor log level.

type Decider

type Decider func(fullMethodName string, err error) bool

type DurationToField

type DurationToField func(duration time.Duration) (key string, value interface{})

DurationToField function defines how to produce duration fields for logging

type ErrorToCode

type ErrorToCode func(err error) codes.Code

type KV

type KV map[string]interface{}

type LogCfg

type LogCfg struct {
	FilePath string `mapstructure:"file_path" json:"file_path" envconfig:"FILE_PATH" required:"false"`
	Level    string `mapstructure:"level" json:"level" envconfig:"LEVEL" required:"true" default:"info"`
	Format   string `mapstructure:"format" json:"format" envconfig:"FORMAT" required:"false" default:"json"`
	Rotation bool   `mapstructure:"rotation" json:"rotation" envconfig:"ROTATION" required:"false" default:"false"`
}

type LogEntry

type LogEntry interface {
	Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{})
	Panic(v interface{}, stack []byte)
}

type LogEntryCtxKey

type LogEntryCtxKey struct{}

func (LogEntryCtxKey) String

func (logEntryCtxKey LogEntryCtxKey) String() string

type Logger

type Logger interface {
	Error(context.Context, error, ...interface{})
	Warn(context.Context, ...interface{})
	Info(context.Context, ...interface{})
	Debug(context.Context, ...interface{})

	Errorf(context.Context, error, string, ...interface{})
	Warnf(context.Context, string, ...interface{})
	Infof(context.Context, string, ...interface{})
	Debugf(context.Context, string, ...interface{})

	ErrorKV(context.Context, error, KV, ...interface{})
	WarnKV(context.Context, KV, ...interface{})
	InfoKV(context.Context, KV, ...interface{})
	DebugKV(context.Context, KV, ...interface{})

	ErrorKVf(context.Context, error, KV, string, ...interface{})
	WarnKVf(context.Context, KV, string, ...interface{})
	InfoKVf(context.Context, KV, string, ...interface{})
	DebugKVf(context.Context, KV, string, ...interface{})

	SetLogLevel(string) error
	NewRequestLogger() func(next http.Handler) http.Handler
	UnaryServerInterceptor(...Option) grpc.UnaryServerInterceptor
	StreamServerInterceptor(...Option) grpc.StreamServerInterceptor
	TwirpServerLoggingHook() *twirp.ServerHooks
}

func Init

func Init(cfg LogCfg) Logger

func New

func New(cfg LogCfg) Logger

type LoggerCtxKey

type LoggerCtxKey struct{}

type MessageProducer

type MessageProducer func(ctx context.Context, format string, level logrus.Level, code codes.Code, err error, fields logrus.Fields)

MessageProducer produces a user defined log message

type Option

type Option func(*options)

func WithCodes

func WithCodes(f ErrorToCode) Option

WithCodes customizes the function for mapping errors to error codes.

func WithDecider

func WithDecider(f Decider) Option

WithDecider customizes the function for deciding if the gRPC interceptor logs should log.

func WithDurationField

func WithDurationField(f DurationToField) Option

WithDurationField customizes the function for mapping request durations to log fields.

func WithLevels

func WithLevels(f CodeToLevel) Option

WithLevels customizes the function for mapping gRPC return codes and interceptor log level statements.

func WithMessageProducer

func WithMessageProducer(f MessageProducer) Option

WithMessageProducer customizes the function for message formation.

func WithTimestampFormat

func WithTimestampFormat(format string) Option

WithTimestampFormat customizes the timestamps emitted in the log fields.

type RequestStructureLogger

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

* RequestStructureLogger: implementation of Chi LogFormatter interface

func (*RequestStructureLogger) NewLogEntry

func (l *RequestStructureLogger) NewLogEntry(r *http.Request) LogEntry

func (*RequestStructureLogger) NewStructuredEntry

func (l *RequestStructureLogger) NewStructuredEntry(r *http.Request) LogEntry

type StructuredLoggerEntry

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

func (*StructuredLoggerEntry) Debug

func (l *StructuredLoggerEntry) Debug(ctx context.Context, args ...interface{})

func (*StructuredLoggerEntry) DebugKV

func (l *StructuredLoggerEntry) DebugKV(ctx context.Context, kv KV, args ...interface{})

func (*StructuredLoggerEntry) DebugKVf

func (l *StructuredLoggerEntry) DebugKVf(ctx context.Context, kv KV, message string, args ...interface{})

func (*StructuredLoggerEntry) Debugf

func (l *StructuredLoggerEntry) Debugf(ctx context.Context, message string, args ...interface{})

func (*StructuredLoggerEntry) Error

func (l *StructuredLoggerEntry) Error(ctx context.Context, err error, args ...interface{})

func (*StructuredLoggerEntry) ErrorKV

func (l *StructuredLoggerEntry) ErrorKV(ctx context.Context, err error, kv KV, args ...interface{})

func (*StructuredLoggerEntry) ErrorKVf

func (l *StructuredLoggerEntry) ErrorKVf(ctx context.Context, err error, kv KV, message string, args ...interface{})

func (*StructuredLoggerEntry) Errorf

func (l *StructuredLoggerEntry) Errorf(ctx context.Context, err error, message string, args ...interface{})

func (*StructuredLoggerEntry) Info

func (l *StructuredLoggerEntry) Info(ctx context.Context, args ...interface{})

func (*StructuredLoggerEntry) InfoKV

func (l *StructuredLoggerEntry) InfoKV(ctx context.Context, kv KV, args ...interface{})

func (*StructuredLoggerEntry) InfoKVf

func (l *StructuredLoggerEntry) InfoKVf(ctx context.Context, kv KV, message string, args ...interface{})

func (*StructuredLoggerEntry) Infof

func (l *StructuredLoggerEntry) Infof(ctx context.Context, message string, args ...interface{})

func (*StructuredLoggerEntry) Panic

func (l *StructuredLoggerEntry) Panic(v interface{}, stack []byte)

func (*StructuredLoggerEntry) Warn

func (l *StructuredLoggerEntry) Warn(ctx context.Context, args ...interface{})

func (*StructuredLoggerEntry) WarnKV

func (l *StructuredLoggerEntry) WarnKV(ctx context.Context, kv KV, args ...interface{})

func (*StructuredLoggerEntry) WarnKVf

func (l *StructuredLoggerEntry) WarnKVf(ctx context.Context, kv KV, message string, args ...interface{})

func (*StructuredLoggerEntry) Warnf

func (l *StructuredLoggerEntry) Warnf(ctx context.Context, message string, args ...interface{})

func (*StructuredLoggerEntry) Write

func (l *StructuredLoggerEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, data interface{})

func (*StructuredLoggerEntry) WriteError

func (l *StructuredLoggerEntry) WriteError(status, bytes int, elapsed time.Duration)

func (*StructuredLoggerEntry) WriteWarn

func (l *StructuredLoggerEntry) WriteWarn(status, bytes int, elapsed time.Duration)

type WrapResponseWriter

type WrapResponseWriter interface {
	http.ResponseWriter
	// Status returns the HTTP status of the request, or 0 if one has not
	// yet been sent.
	Status() int
	// BytesWritten returns the total number of bytes sent to the client.
	BytesWritten() int
	// Tee causes the response body to be written to the given io.Writer in
	// addition to proxying the writes through. Only one io.Writer can be
	// tee'd to at once: setting a second one will overwrite the first.
	// Writes will be sent to the proxy before being written to this
	// io.Writer. It is illegal for the tee'd writer to be modified
	// concurrently with writes.
	Tee(io.Writer)
	// Unwrap returns the original proxied target.
	Unwrap() http.ResponseWriter
}

WrapResponseWriter is a proxy around an http.ResponseWriter that allows you to hook into various parts of the response process.

func NewWrapResponseWriter

func NewWrapResponseWriter(w http.ResponseWriter, protoMajor int) WrapResponseWriter

NewWrapResponseWriter wraps an http.ResponseWriter, returning a proxy that allows you to hook into various parts of the response process.

Jump to

Keyboard shortcuts

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