logger

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2023 License: MIT Imports: 12 Imported by: 0

README

logger

GoDoc

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.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRequestLogger

func NewRequestLogger(e Exporter) func(http.Handler) http.Handler

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

type Exporter interface {
	Middleware() func(http.Handler) http.Handler
}

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

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

func Ctx(ctx context.Context) *Logger

Ctx returns the logger from the context. If no logger is found, it will write to stderr

func Req added in v0.1.0

func Req(r *http.Request) *Logger

Req returns the logger from the http request. If no logger is found, it will write to stderr

func (*Logger) Debug

func (l *Logger) Debug(v interface{})

Debug logs a debug message.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...interface{})

Debugf logs a debug message with format.

func (*Logger) Error

func (l *Logger) Error(v interface{})

Error logs an error message.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...interface{})

Errorf logs an error message with format.

func (*Logger) Info

func (l *Logger) Info(v interface{})

Info logs a info message.

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...interface{})

Infof logs a info message with format.

func (*Logger) Warn

func (l *Logger) Warn(v interface{})

Warn logs a warning message.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...interface{})

Warnf logs a warning message with format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL