Documentation ¶
Index ¶
- Constants
- Variables
- func AddFields(ctx context.Context, fields Fields)
- func GetRequestEntry(ctx context.Context) *logrus.Entry
- func GetRequestID(ctx context.Context) (string, bool)
- func NewRequestID() string
- func RequestID(headerName string) func(next http.Handler) http.Handler
- func StreamServerInterceptor(logger *Logger) grpc.StreamServerInterceptor
- func UnaryServerInterceptor(logger *Logger) grpc.UnaryServerInterceptor
- func WithRequestEntry(ctx context.Context, entry *logrus.Entry) context.Context
- func WithRequestID(ctx context.Context, requestID string) context.Context
- type Fields
- type Logger
Constants ¶
const ( // RequestIDKey is the context key that should store the request identifier. RequestIDKey key = iota // RequestEntryKey is the context key that should store information about the current request. RequestEntryKey )
Variables ¶
var ErrorKey = logrus.ErrorKey
ErrorKey defines the key used to log errors.
Functions ¶
func GetRequestEntry ¶
GetRequestEntry returns the logrus entry of the request.
func GetRequestID ¶
GetRequestID returns the request id from the context if it exists.
func NewRequestID ¶
func NewRequestID() string
NewRequestID creates a new request id using github.com/rs/xid.
func RequestID ¶
RequestID returns a new middleware that gets the given header and sets it in the context so it can be written in the logger. If the header does not exists or it's the empty string, it uses github.com/rs/xid to create a new one.
func StreamServerInterceptor ¶
func StreamServerInterceptor(logger *Logger) grpc.StreamServerInterceptor
StreamServerInterceptor returns a new streaming server interceptor that adds logrus.Entry to the context.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(logger *Logger) grpc.UnaryServerInterceptor
UnaryServerInterceptor returns a new unary server interceptors that adds logrus.Entry to the context.
func WithRequestEntry ¶
WithRequestEntry creates a new context with the given logrus entry.
Types ¶
type Logger ¶
Logger is an alias of logrus.Logger.
func New ¶
func New(name string, raw json.RawMessage) (*Logger, error)
New initializes the logger with the given options.
func (*Logger) GetTimeFormat ¶
GetTimeFormat return the string to format the time.
func (*Logger) GetTraceHeader ¶
GetTraceHeader returns the trace header configured