Documentation ¶
Overview ¶
Package accesslog contains a library access logging.
Index ¶
- Variables
- func SetLogEntry(ctx context.Context, le LogEntry) context.Context
- func WithClientIP() httpOption
- func WithHeaders(hs ...string) httpOption
- func WithIgnoredMethods(ms ...string) grpcOption
- func WithIgnoredPaths(ips map[string][]string) httpOption
- func WithMetadata(ms ...string) grpcOption
- func WithPeer() grpcOption
- func WithRequest() grpcOption
- func WithResponse() grpcOption
- type DefaultGRPCLogEntry
- type DefaultGRPCLogFormatter
- type DefaultHTTPLogEntry
- type DefaultHTTPLogFormatter
- 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 WithClientIP ¶ added in v0.2.0
func WithClientIP() httpOption
WithClientIP specifies whether client ip should be captured by the logger.
func WithHeaders ¶
func WithHeaders(hs ...string) httpOption
WithHeaders specifies headers to be captured by the logger. pseudo-headers also can be treated. If you want alias for logging, write like header:alias. e.g. "content-type:ct", this metadata will be logged like "ct": "application/json"
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. See path.Match method how to set path patterns
func WithMetadata ¶
func WithMetadata(ms ...string) grpcOption
WithMetadata specifies metadata to be captured by the logger. pseudo-headers in metadata also can be treated. If you want alias for logging, write like metadata:alias. e.g. "content-type:ct", this metadata will be logged like "ct": "[\"application/grpc\"]"
func WithPeer ¶ added in v0.2.0
func WithPeer() grpcOption
WithPeer specifies whether peer address should 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 chi_middleware.WrapResponseWriter) LogEntry
NewLogEntry returns a New LogEntry formatted in DefaultHTTPLogFormatter.
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 chi_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 chi_middleware.WrapResponseWriter) LogEntry
NewLogEntry returns a New LogEntry.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
Package middleware contains some middlewares for access logging.
|
Package middleware contains some middlewares for access logging. |
Package writer contains some writers implementation for access logging.
|
Package writer contains some writers implementation for access logging. |