Documentation ¶
Overview ¶
package logger is an HTTP request logger that implements correlated logging to one of several supported platforms. Each HTTP request is logged as the parent log, with all logs generated during the request as child logs.
The Logging destination is configured with an Exporter. This package provides Exporters for Google Cloud Logging and Console Logging.
The GoogleCloudExporter will also correlate logs to Cloud Trace if you instrument your code with tracing.
Index ¶
- func NewRequestLogger(e Exporter) func(http.Handler) http.Handler
- type ConsoleExporter
- type Exporter
- type GoogleCloudExporter
- type Logger
- func (l *Logger) Debug(v interface{})
- func (l *Logger) Debugf(format string, v ...interface{})
- func (l *Logger) Error(v interface{})
- func (l *Logger) Errorf(format string, v ...interface{})
- func (l *Logger) Info(v interface{})
- func (l *Logger) Infof(format string, v ...interface{})
- func (l *Logger) Warn(v interface{})
- func (l *Logger) Warnf(format string, v ...interface{})
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRequestLogger ¶
NewRequestLogger returns a middleware that logs the request and injects a Logger into the context. This Logger can be used during the life of the request, and all logs generated will be correlated to the request log.
If not configured, request logs are sent to stderr by default.
Types ¶
type ConsoleExporter ¶ added in v0.1.0
type ConsoleExporter struct {
// contains filtered or unexported fields
}
ConsoleExporter implements exporting to Google Cloud Logging
func NewConsoleExporter ¶ added in v0.1.0
func NewConsoleExporter() *ConsoleExporter
NewConsoleExporter returns a configured ConsoleExporter
func (*ConsoleExporter) Middleware ¶ added in v0.1.0
func (e *ConsoleExporter) Middleware() func(http.Handler) http.Handler
Middleware returns a middleware that exports logs to Google Cloud Logging
func (*ConsoleExporter) NoColor ¶ added in v0.1.0
func (e *ConsoleExporter) NoColor(v bool) *ConsoleExporter
NoColor controls if this logger will use color to highlight log level
type Exporter ¶ added in v0.1.0
Exporter is the interface for implementing a middleware to export logs to some destination
type GoogleCloudExporter ¶ added in v0.1.0
type GoogleCloudExporter struct {
// contains filtered or unexported fields
}
GoogleCloudExporter implements exporting to Google Cloud Logging
func NewGoogleCloudExporter ¶ added in v0.1.0
func NewGoogleCloudExporter(client *logging.Client, projectID string, opts ...logging.LoggerOption) *GoogleCloudExporter
NewGoogleCloudExporter returns a configured GoogleCloudExporter
func (*GoogleCloudExporter) LogAll ¶ added in v0.1.0
func (e *GoogleCloudExporter) LogAll(v bool) *GoogleCloudExporter
LogAll controls if this logger will log all requests, or only requests that contain logs written to the request Logger (default: true)
func (*GoogleCloudExporter) Middleware ¶ added in v0.1.0
func (e *GoogleCloudExporter) Middleware() func(http.Handler) http.Handler
Middleware returns a middleware that exports logs to Google Cloud Logging
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger implements logging methods for this package
func Ctx ¶ added in v0.1.0
Ctx returns the logger from the context. If no logger is found, it will write to stderr
func Req ¶ added in v0.1.0
Req returns the logger from the http request. If no logger is found, it will write to stderr