# README
go-logger

Library for integrating zap logger with Sentry.
Installation
go get -u go.pr0ger.dev/logger
Show me the code
// Create core for logging to stdout/stderr
localCore := logger.NewCore(true)
// Create core splitter to logging both to local and sentry
// zapcore.NewTee also can be used, but is not recommended if you want to use RequestLogger middleware
core := logger.NewSentryCoreWrapper(localCore, sentry.CurrentHub())
// And create logger
log := zap.New(core)
log.Debug("this event will be logged to stdout but will not appear in request breadcrumbs")
// Create handler for network requests
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log := logger.Ctx(r.Context())
log.Debug("some debug logs from request")
// Create an HTTP client with our transport
client := http.Client{
Transport: logger.NewBreadcrumbTransport(sentry.LevelInfo, http.DefaultTransport),
}
// We need to pass current context to HTTP request so transport will know where to log
req, _ := http.NewRequestWithContext(r.Context(), http.MethodGet, "https://go.pr0ger.dev/logger", nil)
resp, err := client.Do(req)
if err != nil {
log.Warn("request failed", zap.Error(err))
} else {
log.Info(fmt.Sprintf("Response status: %s", resp.Status))
resp.Body.Close()
}
log.Error("let's assume we have an error here")
})
// And use it with our middleware
server := &http.Server{
Addr: ":8080",
Handler: logger.RequestLogger(log)(handler),
}
_ = server.ListenAndServe()
# Functions
BreadcrumbLevel will set a minimum level of messages should be stored as breadcrumbs.
Ctx returns the in-context Logger for a request.
EventLevel will set a minimum level of messages should be sent as events.
ForkedLogger will return a new logger with isolated sentry.Hub.
Hub returns the sentry.Hub associated with the context.
No description provided by the author
NewCore will create handy Core with sensible defaults: - messages with error level and higher will go to stderr, everything else to stdout - use json encoder for production and console for development.
No description provided by the author
NewSentryCoreWrapper creates a Core that duplicates log entries into provided local Core and implicitly created Sentry core.
No description provided by the author
No description provided by the author
RequestLogger is a middleware for injecting sentry.Hub and zap.Logger into request context.
No description provided by the author
nolint:cyclop.
WithExtraFields is a middleware for injecting extra field to the logger injected by RequestLogger middleware.
WithHub returns a copy of provided context with added hub field.
WithLogger returns a copy of provided context with added logger field.
WithRequestID returns a copy of provided context with added request id field.
# Constants
Describes data for an HTTP request breadcrumb https://docs.sentry.io/development/sdk-dev/event-payloads/breadcrumbs/#http.
Describes data for an HTTP request breadcrumb https://docs.sentry.io/development/sdk-dev/event-payloads/breadcrumbs/#http.
Describes data for an HTTP request breadcrumb https://docs.sentry.io/development/sdk-dev/event-payloads/breadcrumbs/#http.
Describes data for an HTTP request breadcrumb https://docs.sentry.io/development/sdk-dev/event-payloads/breadcrumbs/#http.
BreadcrumbTypeDefault describes a generic breadcrumb.
BreadcrumbTypeHTTP describes an HTTP request breadcrumb.
# Structs
No description provided by the author
# Interfaces
No description provided by the author
# Type aliases
No description provided by the author