Documentation ¶
Overview ¶
Package logadapter provides an adapter to the go-kit log.Logger interface.
Index ¶
- func DefaultErrorHandler(ctx context.Context, err error, method string) (handled bool)
- func DefaultFilterHTTP(r *http.Request) bool
- func DefaultFilterRPC(_ context.Context, fullMethod string, _ error) bool
- func InitLogging(w io.Writer, opts ...Option) *logrus.Logger
- func LoggingMiddleware(log *logrus.Logger, opts ...MiddlewareOption) func(http.Handler) http.Handler
- func RecoveryMiddleware(next http.Handler) http.Handler
- func StreamLoggingInterceptor(logger *logrus.Logger, opts ...MiddlewareOption) grpc.StreamServerInterceptor
- func StreamRecoveryInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, ...) (err error)
- func UnaryLoggingInterceptor(logger *logrus.Logger, opts ...MiddlewareOption) grpc.UnaryServerInterceptor
- func UnaryRecoveryInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, ...) (resp interface{}, err error)
- func WithLogger(ctx context.Context, logger *logrus.Logger) context.Context
- type Context
- type Entry
- type ErrorHandler
- type FilterHTTP
- type FilterRPC
- type Formatter
- type GRPCRequest
- type HTTPRequest
- type LogrusGoKitLogger
- type MiddlewareOption
- type Option
- func WithGlobalTraceID(id uuid.UUID) Option
- func WithPrettyPrint() Option
- func WithProjectID(i string) Option
- func WithRegexSkip(v string) Option
- func WithService(n string) Option
- func WithSkipTimestamp() Option
- func WithSourceReference(repository, revision string) Option
- func WithStackSkip(v string) Option
- func WithStackTraceStyle(s StackTraceStyle) Option
- func WithVersion(v string) Option
- type ReportLocation
- type ServiceContext
- type SourceLocation
- type SourceReference
- type SpanHook
- type StackTraceStyle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorHandler ¶ added in v1.0.0
DefaultErrorHandler does nothing.
func DefaultFilterHTTP ¶ added in v1.0.0
DefaultFilterHTTP filters health checks and monitoring canaries from some well known user agents or URL paths.
func DefaultFilterRPC ¶ added in v1.0.0
DefaultFilterRPC filters gRPC standard health check and gRPC reflection requests.
func InitLogging ¶ added in v1.0.0
InitLogging initializes a logrus logger to send things to stackdriver.
func LoggingMiddleware ¶ added in v1.0.0
func LoggingMiddleware(log *logrus.Logger, opts ...MiddlewareOption) func(http.Handler) http.Handler
LoggingMiddleware proivdes a request-scoped log entry into context for HTTP requests, writes request logs in a structured format to stackdriver.
func RecoveryMiddleware ¶ added in v1.0.0
RecoveryMiddleware recovers from panics in the HTTP handler chain, logging an error for Error Reporting.
func StreamLoggingInterceptor ¶ added in v1.0.0
func StreamLoggingInterceptor(logger *logrus.Logger, opts ...MiddlewareOption) grpc.StreamServerInterceptor
StreamLoggingInterceptor provides a request-scoped log entry into context for Streaming gRPC requests, and logs request details at the end of the stream. Logging interceptors should be chained at the very top of the request scope.
func StreamRecoveryInterceptor ¶ added in v1.0.0
func StreamRecoveryInterceptor(srv interface{}, ss grpc.ServerStream, _ *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error)
StreamRecoveryInterceptor is an interceptor that recovers panics from Streaming services and turns them into nicer gRPC errors.
func UnaryLoggingInterceptor ¶ added in v1.0.0
func UnaryLoggingInterceptor(logger *logrus.Logger, opts ...MiddlewareOption) grpc.UnaryServerInterceptor
UnaryLoggingInterceptor provides a request-scoped log entry into context for Unary gRPC requests, and logs request details on the response. Logging interceptors should be chained at the very top of the request scope.
func UnaryRecoveryInterceptor ¶ added in v1.0.0
func UnaryRecoveryInterceptor(ctx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)
UnaryRecoveryInterceptor is an interceptor that recovers panics and turns them into nicer GRPC errors.
Types ¶
type Context ¶ added in v1.0.0
type Context struct { Data map[string]interface{} `json:"data,omitempty"` User string `json:"user,omitempty"` ReportLocation *ReportLocation `json:"reportLocation,omitempty"` HTTPRequest *HTTPRequest `json:"httpRequest,omitempty"` PubSubRequest map[string]interface{} `json:"pubSubRequest,omitempty"` GRPCRequest *GRPCRequest `json:"grpcRequest,omitempty"` GRPCStatus json.RawMessage `json:"grpcStatus,omitempty"` SourceReferences []SourceReference `json:"sourceReferences,omitempty"` }
Context is sent with every message to stackdriver.
type Entry ¶ added in v1.0.0
type Entry struct { Type string `json:"@type,omitempty"` LogName string `json:"logName,omitempty"` Timestamp string `json:"timestamp,omitempty"` ServiceContext *ServiceContext `json:"serviceContext,omitempty"` Message string `json:"message,omitempty"` Severity severity `json:"severity,omitempty"` Context *Context `json:"context,omitempty"` SourceLocation *SourceLocation `json:"logging.googleapis.com/sourceLocation,omitempty"` StackTrace string `json:"stack_trace,omitempty"` Trace string `json:"logging.googleapis.com/trace,omitempty"` SpanID string `json:"logging.googleapis.com/spanId,omitempty"` TraceSampled bool `json:"logging.googleapis.com/trace_sampled,omitempty"` HTTPRequest *HTTPRequest `json:"httpRequest,omitempty"` }
Entry stores a log entry.
type ErrorHandler ¶ added in v1.0.0
ErrorHandler should return true if the error provided has already been logged
type Formatter ¶
type Formatter struct { Service string Version string SourceReference []SourceReference ProjectID string StackSkip []string StackStyle StackTraceStyle SkipTimestamp bool RegexSkip string PrettyPrint bool GlobalTraceID string }
Formatter implements Stackdriver formatting for logrus.
func NewFormatter ¶
NewFormatter returns a new Formatter.
type GRPCRequest ¶ added in v1.0.0
type GRPCRequest struct { Method string `json:"method,omitempty"` UserAgent string `json:"userAgent,omitempty"` PeerAddr string `json:"peer,omitempty"` Deadline string `json:"deadline,omitempty"` Duration string `json:"duration,omitempty"` }
GRPCRequest represents details of a gRPC request and response appended to a log.
type HTTPRequest ¶ added in v1.0.0
type HTTPRequest struct { RequestMethod string `json:"requestMethod,omitempty"` RequestURL string `json:"requestUrl,omitempty"` RequestSize string `json:"requestSize,omitempty"` Status string `json:"status,omitempty"` ResponseSize string `json:"responseSize,omitempty"` UserAgent string `json:"userAgent,omitempty"` RemoteIP string `json:"remoteIp,omitempty"` ServerIP string `json:"serverIp,omitempty"` Referer string `json:"referer,omitempty"` Latency string `json:"latency,omitempty"` CacheLookup bool `json:"cacheLookup,omitempty"` CacheHit bool `json:"cacheHit,omitempty"` CacheValidatedWithOriginServer bool `json:"cacheValidatedWithOriginServer,omitempty"` CacheFillBytes string `json:"cacheFillBytes,omitempty"` Protocol string `json:"protocol,omitempty"` }
HTTPRequest defines details of a request and response to append to a log. https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#httprequest
type LogrusGoKitLogger ¶ added in v1.0.0
type LogrusGoKitLogger struct {
// contains filtered or unexported fields
}
LogrusGoKitLogger is a gokit-compatible wrapper for logrus.LogrusGoKitLogger
func InitLogrusGoKitLogger ¶ added in v1.0.0
func InitLogrusGoKitLogger(w io.Writer, opts ...Option) *LogrusGoKitLogger
InitLogrusGoKitLogger initializes a go kit logger to send things to stackdriver.
func NewLogrusGoKitLogger ¶ added in v1.0.0
func NewLogrusGoKitLogger(logger logrusLogger) *LogrusGoKitLogger
NewLogrusGoKitLogger creates a gokit-compatible logger
func (LogrusGoKitLogger) Log ¶ added in v1.0.0
func (l LogrusGoKitLogger) Log(keyvals ...interface{}) error
Log implements the fundamental Logger interface
type MiddlewareOption ¶ added in v1.0.0
type MiddlewareOption func(*middlewareOptions)
func WithErrorHandler ¶ added in v1.0.0
func WithErrorHandler(h ErrorHandler) MiddlewareOption
func WithHTTPFilter ¶ added in v1.0.0
func WithHTTPFilter(f FilterHTTP) MiddlewareOption
WithHTTPFilter provides a filter to the logging middleware that determines whether or not to log individual messages
func WithRPCFilter ¶ added in v1.0.0
func WithRPCFilter(f FilterRPC) MiddlewareOption
WithRPCFilter provides a filter to the logging middleware that determines whether or not to log individual messages
type Option ¶
type Option func(*Formatter)
Option lets you configure the Formatter.
func WithGlobalTraceID ¶ added in v1.0.0
WithGlobalTraceID sets a consistent trace id on the global logger context If not provided, a random id will be generated at runtime
func WithPrettyPrint ¶ added in v1.0.0
func WithPrettyPrint() Option
WithPrettyPrint pretty-prints logs.
func WithProjectID ¶ added in v1.0.0
WithProjectID makes sure all entries have your Project information.
func WithRegexSkip ¶ added in v1.0.0
WithRegexSkip lets you configure which functions or packages should be skipped for locating the error.
func WithService ¶
WithService lets you configure the service name used for error reporting.
func WithSkipTimestamp ¶ added in v1.0.0
func WithSkipTimestamp() Option
WithSkipTimestamp lets you avoid setting the timestamp
func WithSourceReference ¶ added in v1.0.0
WithSourceReference adds reference to the source code.
func WithStackSkip ¶
WithStackSkip lets you configure which packages should be skipped for locating the error.
func WithStackTraceStyle ¶ added in v1.0.0
func WithStackTraceStyle(s StackTraceStyle) Option
WithStackTraceStyle configures where to write the stacktrace: appended to the message, as its own field, or both
func WithVersion ¶
WithVersion lets you configure the service version used for error reporting.
type ReportLocation ¶ added in v1.0.0
type ReportLocation struct { FilePath string `json:"filePath,omitempty"` LineNumber int `json:"lineNumber,omitempty"` FunctionName string `json:"functionName,omitempty"` }
ReportLocation is the information about where an error occurred. https://cloud.google.com/error-reporting/reference/rest/v1beta1/ErrorContext#SourceLocation
type ServiceContext ¶ added in v1.0.0
type ServiceContext struct { Service string `json:"service,omitempty"` Version string `json:"version,omitempty"` }
ServiceContext provides the data about the service we are sending to Google.
type SourceLocation ¶ added in v1.0.0
type SourceLocation struct { FilePath string `json:"file,omitempty"` LineNumber int `json:"line,omitempty"` FunctionName string `json:"function,omitempty"` }
SourceLocation is the information about where a log entry was produced. https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogEntrySourceLocation
type SourceReference ¶ added in v1.0.0
type SourceReference struct { Repository string `json:"repository,omitempty"` RevisionID string `json:"revisionId,omitempty"` }
SourceReference is a reference to a particular snapshot of the source tree used to build and deploy an application
type StackTraceStyle ¶ added in v1.0.0
type StackTraceStyle int
const ( TraceInMessage StackTraceStyle = iota TraceInPayload TraceInBoth )
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ctxlogrus wraps the go-grpc-middleware ctxlogrus, extracts a trace context to correlate logs emitted to the correct trace and span
|
Package ctxlogrus wraps the go-grpc-middleware ctxlogrus, extracts a trace context to correlate logs emitted to the correct trace and span |