Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(ctx context.Context, args ...interface{})
- func DebugKV(ctx context.Context, kv KV, args ...interface{})
- func DebugKVf(ctx context.Context, kv KV, msg string, args ...interface{})
- func Debugf(ctx context.Context, msg string, args ...interface{})
- func DefaultClientCodeToLevel(code codes.Code) logrus.Level
- func DefaultCodeToLevel(code codes.Code) logrus.Level
- func DefaultDeciderMethod(fullMethodName string, err error) bool
- func DefaultErrorToCode(err error) codes.Code
- func DefaultMessageProducer(ctx context.Context, format string, level logrus.Level, code codes.Code, ...)
- func DurationToDurationField(duration time.Duration) (key string, value interface{})
- func DurationToTimeMillisField(duration time.Duration) (key string, value interface{})
- func Error(ctx context.Context, err error, args ...interface{})
- func ErrorKV(ctx context.Context, err error, kv KV, args ...interface{})
- func ErrorKVf(ctx context.Context, err error, kv KV, msg string, args ...interface{})
- func Errorf(ctx context.Context, err error, msg string, args ...interface{})
- func Info(ctx context.Context, args ...interface{})
- func InfoKV(ctx context.Context, kv KV, args ...interface{})
- func InfoKVf(ctx context.Context, kv KV, msg string, args ...interface{})
- func Infof(ctx context.Context, msg string, args ...interface{})
- func NewRequestLogger() func(next http.Handler) http.Handler
- func SetLogLevel(level string) error
- func StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor
- func TwirpServerLoggingHook() *twirp.ServerHooks
- func UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor
- func Warn(ctx context.Context, args ...interface{})
- func WarnKV(ctx context.Context, kv KV, args ...interface{})
- func WarnKVf(ctx context.Context, kv KV, msg string, args ...interface{})
- func Warnf(ctx context.Context, msg string, args ...interface{})
- type CodeToLevel
- type Decider
- type DurationToField
- type ErrorToCode
- type KV
- type LogCfg
- type LogEntry
- type LogEntryCtxKey
- type Logger
- type LoggerCtxKey
- type MessageProducer
- type Option
- type RequestStructureLogger
- type StructuredLoggerEntry
- func (l *StructuredLoggerEntry) Debug(ctx context.Context, args ...interface{})
- func (l *StructuredLoggerEntry) DebugKV(ctx context.Context, kv KV, args ...interface{})
- func (l *StructuredLoggerEntry) DebugKVf(ctx context.Context, kv KV, message string, args ...interface{})
- func (l *StructuredLoggerEntry) Debugf(ctx context.Context, message string, args ...interface{})
- func (l *StructuredLoggerEntry) Error(ctx context.Context, err error, args ...interface{})
- func (l *StructuredLoggerEntry) ErrorKV(ctx context.Context, err error, kv KV, args ...interface{})
- func (l *StructuredLoggerEntry) ErrorKVf(ctx context.Context, err error, kv KV, message string, args ...interface{})
- func (l *StructuredLoggerEntry) Errorf(ctx context.Context, err error, message string, args ...interface{})
- func (l *StructuredLoggerEntry) Info(ctx context.Context, args ...interface{})
- func (l *StructuredLoggerEntry) InfoKV(ctx context.Context, kv KV, args ...interface{})
- func (l *StructuredLoggerEntry) InfoKVf(ctx context.Context, kv KV, message string, args ...interface{})
- func (l *StructuredLoggerEntry) Infof(ctx context.Context, message string, args ...interface{})
- func (l *StructuredLoggerEntry) Panic(v interface{}, stack []byte)
- func (l *StructuredLoggerEntry) Warn(ctx context.Context, args ...interface{})
- func (l *StructuredLoggerEntry) WarnKV(ctx context.Context, kv KV, args ...interface{})
- func (l *StructuredLoggerEntry) WarnKVf(ctx context.Context, kv KV, message string, args ...interface{})
- func (l *StructuredLoggerEntry) Warnf(ctx context.Context, message string, args ...interface{})
- func (l *StructuredLoggerEntry) Write(status, bytes int, header http.Header, elapsed time.Duration, data interface{})
- func (l *StructuredLoggerEntry) WriteError(status, bytes int, elapsed time.Duration)
- func (l *StructuredLoggerEntry) WriteWarn(status, bytes int, elapsed time.Duration)
- type WrapResponseWriter
Constants ¶
const (
PackageName = "RZ_LOG"
)
Variables ¶
var DefaultDurationToField = DurationToTimeMillisField
DefaultDurationToField is the default implementation of converting request duration to a log field (key and value).
Functions ¶
func DefaultClientCodeToLevel ¶
DefaultClientCodeToLevel is the default implementation of gRPC return codes to log levels for client side.
func DefaultCodeToLevel ¶
DefaultCodeToLevel is the default implementation of gRPC return codes to log levels for server side.
func DefaultDeciderMethod ¶
func DefaultErrorToCode ¶
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 ¶
DurationToDurationField uses the duration value to log the request duration.
func DurationToTimeMillisField ¶
DurationToTimeMillisField converts the duration to milliseconds and uses the key `grpc.time_ms`.
func SetLogLevel ¶
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
Types ¶
type CodeToLevel ¶
CodeToLevel function defines the mapping between gRPC return codes and interceptor log level.
type DurationToField ¶
DurationToField function defines how to produce duration fields for logging
type ErrorToCode ¶
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 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 }
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 ¶
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 ¶
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) 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) WriteError ¶
func (l *StructuredLoggerEntry) WriteError(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.