logx

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logx holds the logging conventions shared by every Jōei component, so a log line reads the same whichever subsystem wrote it.

Every request gets one ID, minted by Middleware at the edge of the server. It reaches the client as the X-Request-Id header, the request's log lines as the request_id field, JSON error bodies and the console request feed — so one ID ties together everything a single request left behind.

Field vocabulary (use these names, never synonyms):

component        subsystem that wrote the line: server, proxy,
                 metadata_filter, docker, console, telemetry, auth
request_id       the request's ID (via Logger, never set by hand)
ecosystem        pypi | npm | maven | rubygems | go | docker
package          package name (Docker: the repository)
version          package version (Docker: tag or digest as requested)
classifier       Maven classifier, when present
digest           Docker content digest
path             request path, for requests that name no package
verdict, gate,   outcome of a gated request (see Outcome)
reason, status,
duration_ms
upstream_attempts  per-mirror attempt list (upstream.Attempts)
error            the error (zerolog's Err)

Messages are short lowercase phrases without a subsystem prefix; the component field carries the subsystem.

Index

Constants

View Source
const HeaderRequestID = "X-Request-Id"

HeaderRequestID is the response header that carries the request ID.

View Source
const MsgOutcome = "request gated"

MsgOutcome is the message of the single line each gated request ends with.

Variables

This section is empty.

Functions

func Ensure

func Ensure(r *http.Request) (*http.Request, string)

Ensure returns r carrying a request ID, minting one when r has none, and that ID. Handlers call it so they work the same mounted behind Middleware or used directly.

func Logger

func Logger(ctx context.Context, base zerolog.Logger) zerolog.Logger

Logger returns base with the request_id field of ctx's request, or base unchanged outside a request.

func Middleware

func Middleware(next http.Handler) http.Handler

Middleware gives every request an ID and returns it in the X-Request-Id response header.

func Outcome

func Outcome(log zerolog.Logger, ev gate.Event)

Outcome writes the one line a gated request ends with, mirroring the telemetry event it records. log must already carry the request's identity fields (request_id, ecosystem, package, version). PASS and CACHE log at info, BLOCK and client-side errors (4xx) at warn, other errors at error.

func RequestID

func RequestID(ctx context.Context) string

RequestID returns the request ID carried by ctx, or "" when there is none.

func WithRequestID

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

WithRequestID returns ctx carrying id as the request ID.

Types

This section is empty.

Jump to

Keyboard shortcuts

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