Documentation
¶
Overview ¶
Package accesslog contains a library access logging.
Index ¶
- Variables
- func SetLogEntry(ctx context.Context, le LogEntry) context.Context
- func WithHeaders(hs ...string) httpOption
- func WithIgnoredMethods(ms ...string) grpcOption
- func WithIgnoredPaths(ips map[string][]string) httpOption
- func WithMetadata(ms ...string) grpcOption
- func WithRequest() grpcOption
- func WithResponse() grpcOption
- type DefaultGRPCLogEntry
- type DefaultGRPCLogFormatter
- type DefaultHTTPLogEntry
- type DefaultHTTPLogFormatter
- type FluentLogWriter
- type GRPCLogFormatter
- type GRPCLogger
- type HTTPLogFormatter
- type HTTPLogger
- type LogEntry
Constants ¶
This section is empty.
Variables ¶
var DefaultGRPCLogger = NewGRPCLogger(os.Stdout, NewDefaultGRPCLogFormatter())
DefaultGRPCLogger is default gRPC Logger.
var DefaultHTTPLogger = NewHTTPLogger(os.Stdout, NewDefaultHTTPLogFormatter())
DefaultHTTPLogger is default HTTP Logger.
var LogEntryCtxKey = struct{}{}
LogEntryCtxKey is the context key for LogEntry.
Functions ¶
func SetLogEntry ¶
SetLogEntry sets LogEntry in context.
func WithHeaders ¶
func WithHeaders(hs ...string) httpOption
WithHeaders specifies headers to be captured by the logger.
func WithIgnoredMethods ¶
func WithIgnoredMethods(ms ...string) grpcOption
WithIgnoredMethods specifies full methods to be ignored by the server side interceptor. When an incoming request's full method is in ms, the request will not be captured.
func WithIgnoredPaths ¶
WithIgnoredPaths specifies methods and paths to be ignored by the logger. This only works when using chi.Router.
func WithMetadata ¶
func WithMetadata(ms ...string) grpcOption
WithMetadata specifies headers to be captured by the logger.
func WithRequest ¶
func WithRequest() grpcOption
WithRequest specifies whether gRPC requests should be captured by the logger.
func WithResponse ¶
func WithResponse() grpcOption
WithResponse specifies whether gRPC responses should be captured by the logger.
Types ¶
type DefaultGRPCLogEntry ¶
type DefaultGRPCLogEntry struct {
// contains filtered or unexported fields
}
DefaultGRPCLogEntry is the LogEntry formatted in DefaultGRPCLogFormatter.
func (*DefaultGRPCLogEntry) Add ¶
func (le *DefaultGRPCLogEntry) Add(f func(e *zerolog.Event))
Add adds function for adding fields to log event.
func (*DefaultGRPCLogEntry) Write ¶
func (le *DefaultGRPCLogEntry) Write(t time.Time)
Write writes a log.
type DefaultGRPCLogFormatter ¶
type DefaultGRPCLogFormatter struct {
// contains filtered or unexported fields
}
DefaultGRPCLogFormatter is default GRPCLogFormatter.
func NewDefaultGRPCLogFormatter ¶
func NewDefaultGRPCLogFormatter(opts ...grpcOption) *DefaultGRPCLogFormatter
NewDefaultGRPCLogFormatter returns a new DefaultGRPCLogFormatter.
func (*DefaultGRPCLogFormatter) NewLogEntry ¶
func (f *DefaultGRPCLogFormatter) NewLogEntry(l *zerolog.Logger, ctx context.Context, req interface{}, res *interface{}, info *grpc.UnaryServerInfo, err *error) LogEntry
NewLogEntry returns a New LogEntry formatted in DefaultGRPCLogFormatter.
type DefaultHTTPLogEntry ¶
type DefaultHTTPLogEntry struct {
// contains filtered or unexported fields
}
DefaultHTTPLogEntry is the LogEntry formatted in DefaultHTTPLogFormatter.
func (*DefaultHTTPLogEntry) Add ¶
func (le *DefaultHTTPLogEntry) Add(f func(e *zerolog.Event))
Add adds function for adding fields to log event.
func (*DefaultHTTPLogEntry) Write ¶
func (le *DefaultHTTPLogEntry) Write(t time.Time)
Write writes a log.
type DefaultHTTPLogFormatter ¶
type DefaultHTTPLogFormatter struct {
// contains filtered or unexported fields
}
DefaultHTTPLogFormatter is default HTTPLogFormatter.
func NewDefaultHTTPLogFormatter ¶
func NewDefaultHTTPLogFormatter(opts ...httpOption) *DefaultHTTPLogFormatter
NewDefaultHTTPLogFormatter returns a new DefaultHTTPLogFormatter.
func (*DefaultHTTPLogFormatter) NewLogEntry ¶
func (f *DefaultHTTPLogFormatter) NewLogEntry(l *zerolog.Logger, r *http.Request, ww middleware.WrapResponseWriter) LogEntry
NewLogEntry returns a New LogEntry formatted in DefaultHTTPLogFormatter.
type FluentLogWriter ¶
type FluentLogWriter struct {
// contains filtered or unexported fields
}
FluentLogWriter is the log writer that implements io.Writer. It writes a log by Fluent Forwarder.
func NewFluentLogWriter ¶
func NewFluentLogWriter(tag, host string, port int) (*FluentLogWriter, error)
NewFluentLogWriter creates a new FluentLogWriter.
func NewFluentLogWriterFromForwarder ¶
func NewFluentLogWriterFromForwarder(tag string, f *fluent.Fluent) *FluentLogWriter
NewFluentLogWriterFromForwarder creates a new FluentLigWriter from Fluent Forwarder.
func (*FluentLogWriter) Close ¶
func (f *FluentLogWriter) Close() error
Close closes underlying connections with the Fluent daemon.
type GRPCLogFormatter ¶
type GRPCLogFormatter interface {
NewLogEntry(l *zerolog.Logger, ctx context.Context, req interface{}, res *interface{}, info *grpc.UnaryServerInfo, err *error) LogEntry
}
GRPCLogFormatter is the interface for NewLogEntry method.
type GRPCLogger ¶
type GRPCLogger struct {
// contains filtered or unexported fields
}
GRPCLogger is logger for gRPC access logging.
func NewGRPCLogger ¶
func NewGRPCLogger(w io.Writer, f GRPCLogFormatter) *GRPCLogger
NewGRPCLogger returns a new GRPCLogger.
func (*GRPCLogger) NewLogEntry ¶
func (l *GRPCLogger) NewLogEntry(ctx context.Context, req interface{}, res *interface{}, info *grpc.UnaryServerInfo, err *error) LogEntry
NewLogEntry returns a New LogEntry.
type HTTPLogFormatter ¶
type HTTPLogFormatter interface {
NewLogEntry(l *zerolog.Logger, r *http.Request, ww middleware.WrapResponseWriter) LogEntry
}
HTTPLogFormatter is the interface for NewLogEntry method.
type HTTPLogger ¶
type HTTPLogger struct {
// contains filtered or unexported fields
}
HTTPLogger is logger for HTTP access logging.
func NewHTTPLogger ¶
func NewHTTPLogger(w io.Writer, f HTTPLogFormatter) *HTTPLogger
NewHTTPLogger returns a new HTTPLogger.
func (*HTTPLogger) NewLogEntry ¶
func (l *HTTPLogger) NewLogEntry(r *http.Request, ww middleware.WrapResponseWriter) LogEntry
NewLogEntry returns a New LogEntry.