accesslog

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package accesslog writes proxy activity as JSON Lines.

Index

Constants

View Source
const (

	// EventRequest identifies the response sent by the proxy to a client.
	EventRequest = "request"
	// EventUpstream identifies one HTTP exchange with an upstream service.
	EventUpstream = "upstream"
)

Variables

This section is empty.

Functions

func RequestID

func RequestID(ctx context.Context) string

RequestID returns the proxy request ID stored in ctx.

func URLWithoutSecrets

func URLWithoutSecrets(value *url.URL) string

URLWithoutSecrets returns a URL without user information, query values, or fragments.

func WithRequestID

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID stores a proxy request ID in ctx.

Types

type Entry

type Entry struct {
	Time       time.Time `json:"time"`
	Event      string    `json:"event"`
	RequestID  string    `json:"request_id,omitempty"`
	Method     string    `json:"method"`
	Path       string    `json:"path,omitempty"`
	URL        string    `json:"url,omitempty"`
	StatusCode int       `json:"status_code,omitempty"`
	DurationMS int64     `json:"duration_ms"`
	RemoteAddr string    `json:"remote_addr,omitempty"`
	Error      string    `json:"error,omitempty"`
}

Entry is one proxy activity record.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger appends complete JSON objects to a file, one per line.

func Open

func Open(path string) (*Logger, error)

Open opens path for append, creating it with owner-only permissions when needed.

func (*Logger) Close

func (l *Logger) Close() error

Close closes the log file after any active writer finishes.

func (*Logger) Write

func (l *Logger) Write(entry Entry) error

Write appends an entry to the log.

Jump to

Keyboard shortcuts

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