Let callers provide a logger instead of the global B2_LOG_LEVEL debug output

Aperta
#173 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Start with internal/blog/blog.go to trace how B2_LOG_LEVEL and the global log writer are used, then read base/base.go around logRequest and logResponse and follow how client options reach base. Define how a per-client logger and code-set level fit that flow while preserving the environment fallback. Done means the acceptance criteria pass for one logger, two isolated clients, and the no-logger fallback.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Summary

blazer's debug output can only be controlled through the environment. internal/blog reads B2_LOG_LEVEL once in init and writes through the process-wide log package. A library user cannot, from code, turn the output on or off, change its level, send it to their own logger (for example log/slog, a per-client sink or a test buffer), or filter it before it is written.

Current behavior

At a5e0d13:

  • internal/blog/blog.go:33-40: the level comes from B2_LOG_LEVEL in init; there is no setter.
  • internal/blog/blog.go:50-60: Info and Infof write with log.Print, after dropping CR and LF (added by Backblaze/blazer#170).
  • base/base.go:244-268 and :309-341: logRequest and logResponse write through blog.V(2), including request and response bodies (with credential fields redacted) at level 2.

The only way for an application to capture or silence the output is to replace the global log writer, which also affects its own logging and every other library that uses log.

Expected behavior

Applications decide where blazer's debug output goes and at what level, per client, without relying on the process environment.

Proposed change

  • Add a client option that takes a *slog.Logger (available with the current go 1.26.10 minimum) or a func(level int, msg string), passed through to base so each client logs to its own sink.
  • Add an option to set the debug level from code.
  • Keep B2_LOG_LEVEL and the global log writer (with the CR/LF stripping) as the fallback when no logger is set, and document that level 2 includes request and response bodies.

Acceptance criteria

  • With a caller-provided logger and level 2 set from code, the logger receives the request and response messages and the global log writer receives none.
  • Two clients with different loggers in one process each receive only their own messages.
  • With no logger set, B2_LOG_LEVEL behaves as today.

Related

Backblaze/blazer#149 (closed) and Backblaze/blazer#142 (merged) changed what the verbose log contains by redacting credential fields. Backblaze/blazer#170 (merged) drops CR and LF from log messages, and Backblaze/blazer#160 (merged) hardened SSE-C logging. This issue is about where the output goes.

Lingua principale
Go
Stelle
66
Fork
18
Merge medio
1g 10h
PR unite (30g)
132

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Backblaze/blazer

Tutte le issue di Backblaze/blazer

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.