Sync shared snapshot from 2e6baaa

This commit is contained in:
Gabriel20xx committed 2026-09-06 22:51:07 +02:00
1 parent 5ea8551d60
commit 81b62cdc26
34 files changed
+197 -121

No files matched your search

+19 -19
View File
@@ -1,5 +1,5 @@
// Package logshipper is the client-side adapter for LoggingServer
// (Web/LoggingServer), the workspace's centralized log sink. It is the
// Package logshipper is the client-side adapter for OmniLogger
// (Web/OmniLogger), the workspace's centralized log sink. It is the
// logging equivalent of the authclient package added alongside AuthServer:
// each service currently owns its own local internal/logging package (see
// Original/OutdoorGames/OutdoorGamesServerGo/internal/logging/logging.go for
@@ -10,12 +10,12 @@
// logging.New(...) call for logshipper.New(...) with no call-site changes,
// once the owner decides to migrate a given service.
//
// No project imports this yet — see LoggingServer/README.md's "Migration
// No project imports this yet — see OmniLogger/README.md's "Migration
// notes" for the deliberate, per-project follow-up this requires.
//
// Shipper always writes the same human-readable line to stdout/stderr that
// the local loggers write today, in addition to batching entries off to
// LoggingServer. Nothing is lost if LoggingServer is never wired up, never
// OmniLogger. Nothing is lost if OmniLogger is never wired up, never
// reachable, or removed later — this is a mirror, not a replacement, for the
// container's own stdout/stderr logs.
package logshipper
@@ -63,7 +63,7 @@ func levelOf(s string) Level {
}
}
// sevName is the canonical, lowercase level name LoggingServer's ingest API
// sevName is the canonical, lowercase level name OmniLogger's ingest API
// expects (debug/info/warn/error/critical), independent of the uppercase
// name used in the local stdout/stderr line.
func sevName(sev Level) (upper, lower string) {
@@ -92,13 +92,13 @@ const (
// Config configures a Shipper. Only BaseURL, IngestToken, and Service are
// normally set by a caller; everything else has a workable default.
type Config struct {
// BaseURL is LoggingServer's base URL, e.g. "http://loggingserver:8090".
// BaseURL is OmniLogger's base URL, e.g. "http://omnilogger:8090".
// Required.
BaseURL string
// IngestToken is the shared INGEST_TOKEN bearer secret LoggingServer
// requires (see LoggingServer/README.md). Required.
// IngestToken is the shared INGEST_TOKEN bearer secret OmniLogger
// requires (see OmniLogger/README.md). Required.
IngestToken string
// Service is this process's service name as reported to LoggingServer,
// Service is this process's service name as reported to OmniLogger,
// e.g. "playhouse" or "outdoorgames-server-go". Required.
Service string
@@ -110,11 +110,11 @@ type Config struct {
// var (debug/info/warn/error/critical/silent). Defaults to "info".
Level string
// LogAll mirrors the LOG_ALL env var: when true, a verbose JSON context
// dump is also printed locally (never sent to LoggingServer differently
// dump is also printed locally (never sent to OmniLogger differently
// than normal — see Debug/InfoCtx doc comments).
LogAll bool
// FlushInterval is how often buffered entries are sent to LoggingServer.
// FlushInterval is how often buffered entries are sent to OmniLogger.
// Defaults to 2s.
FlushInterval time.Duration
// MaxBatchSize triggers an out-of-band flush as soon as the buffer
@@ -127,13 +127,13 @@ type Config struct {
// Defaults to 2000.
BufferCapacity int
// HTTPClient overrides the client used to POST to LoggingServer.
// HTTPClient overrides the client used to POST to OmniLogger.
// Defaults to a client with a 5s timeout.
HTTPClient *http.Client
}
// wireEntry mirrors LoggingServer's POST /api/logs request shape
// (LoggingServer/internal/httpapi.LogEntryInput) field-for-field.
// wireEntry mirrors OmniLogger's POST /api/logs request shape
// (OmniLogger/internal/httpapi.LogEntryInput) field-for-field.
type wireEntry struct {
Service string `json:"service"`
Level string `json:"level"`
@@ -142,7 +142,7 @@ type wireEntry struct {
OccurredAt time.Time `json:"occurred_at"`
}
// Shipper batches log entries in memory and flushes them to LoggingServer on
// Shipper batches log entries in memory and flushes them to OmniLogger on
// a background goroutine, while also behaving like a local
// internal/logging.Logger (same method surface, same stdout/stderr output).
// A Shipper is safe for concurrent use.
@@ -263,7 +263,7 @@ func (s *Shipper) enqueue(entry wireEntry) {
}
}
// flush sends every currently buffered entry to LoggingServer in one
// flush sends every currently buffered entry to OmniLogger in one
// request. Failures are swallowed (beyond a rate-limited local warning) by
// design: a host application must never fail, panic, or slow down because
// its log sink is unreachable.
@@ -302,12 +302,12 @@ func (s *Shipper) flush() {
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
s.warnOnce(fmt.Errorf("logshipper: LoggingServer rejected %d entries: HTTP %d", len(batch), resp.StatusCode))
s.warnOnce(fmt.Errorf("logshipper: OmniLogger rejected %d entries: HTTP %d", len(batch), resp.StatusCode))
}
}
// warnOnce prints a local stderr warning at most once per minute, no matter
// how many sends fail in that window, so an unreachable LoggingServer cannot
// how many sends fail in that window, so an unreachable OmniLogger cannot
// itself become a log-spam problem.
func (s *Shipper) warnOnce(err error) {
s.warnMu.Lock()
@@ -369,7 +369,7 @@ func (s *Shipper) emit(sev Level, ctx map[string]any, args ...any) {
}
// Unlike the local-only verbose dump above (which scrubs IDs for
// readability), the context shipped to LoggingServer is sent unscrubbed:
// readability), the context shipped to OmniLogger is sent unscrubbed:
// the whole point of centralizing logs is cross-service correlation by
// request/user/entity ID, so stripping IDs here would defeat that.
var rawCtx json.RawMessage