Repository navigation
feat(logging): add zap-based structured logging with CLI/output channels - #8
Merged
Merged
Conversation
Introduce internal/logging as the single logging facility, replacing ad-hoc
fmt/os output with a structured pipeline and a separate user-facing CLI
channel.
Logging package (internal/logging, 7 files split by responsibility):
- logging.go: Logger wrapper over zap SugaredLogger; level methods take
key/value pairs (no zap.String field construction); WithName tags a
package-level logger resolved through Get so later Setup still applies
- setup.go: default logger lifecycle (Get/Setup) with goroutine-safe swap
- config.go: Config struct plus rotation defaults (100MB/5 backups/30d/compress)
- encoder.go: zap core construction (text vs json) with AddCallerSkip(1)
- rotate.go: lumberjack-based size rotation with gzip + backup retention
- level.go: log-level string parsing with sane fallback
- cli.go: CLIPrintf/CLIPrintln/CLIPrint user-facing stdout channel, never
redirected by --log-file
Config precedence: CLI flag > env var (GPI_LOG_LEVEL/GPI_LOG_FILE/
GPI_LOG_FORMAT) > config logging: section > defaults (stdout/info/text).
Package-level named logger convention: every package declares
var logger = logging.WithName("module")
at the top of its same-name go file; all per-type Log fields and
logging.Get() call sites are removed project-wide (provisioner, serve,
jobs, server, metacache, backend docker/local/existing, cloud aws/aliyun,
cli, gpilet). WithName resolves through Get on each call so the package
logger follows Setup even when the var is initialized before configuration.
Key-path diagnostics added:
- cloud aws/aliyun RunInstances decision logging (reuse running / resume
stopped / create instances) at Info
- backend docker/local/existing lifecycle (launch/teardown/stop/start)
- optimizer candidate collection and placement choice at Debug
- metacache fetch success/failure at Debug
- /healthz requests skipped from request logging to avoid probe noise
CLI output migrated from fmt to logging.CLIPrintf/CLIPrintln across all
cli subcommands; gpilet status uses CLIPrint. Diagnostic-only paths keep
the zap channel (e.g. serve teardown warnings).
server middleware split from one middlewares.go into per-middleware files:
middleware.go (interface + chain), cors.go, security.go, logging.go;
dropped the unused unixMillis helper.
Docs: AGENTS.md Go conventions section (import grouping in 3 blocks via
goimports -local, logging conventions, package file layout), README logging
section, logging: example in examples/gpi-config.yaml, MEMORY.md v22.
Merge branch 'main' of github.com:acmestack/gpi into feature/logging. Upstream added the zh/en document bilingualization (docs/zh + docs/en, root README.md/README.en.md) which bumped MEMORY.md to v22; this branch's logging work also used v22. Resolve by keeping both records and bumping the file to v23: v23 = logging system decisions, v22 = bilingualization. The other upstream changes (docs/zh|en translations, .github/CLA.md and RELEASE_NOTES.md sentence-level bilingualization, AGENTS.md bilingual conventions) merge cleanly alongside the Go conventions section.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce internal/logging as the single logging facility, replacing ad-hoc fmt/os output with a structured pipeline and a separate user-facing CLI channel.
Logging package (internal/logging, 7 files split by responsibility):
Config precedence: CLI flag > env var (GPI_LOG_LEVEL/GPI_LOG_FILE/
GPI_LOG_FORMAT) > config logging: section > defaults (stdout/info/text).
Package-level named logger convention: every package declares
var logger = logging.WithName("module")
at the top of its same-name go file; all per-type Log fields and logging.Get() call sites are removed project-wide (provisioner, serve, jobs, server, metacache, backend docker/local/existing, cloud aws/aliyun, cli, gpilet). WithName resolves through Get on each call so the package logger follows Setup even when the var is initialized before configuration.
Key-path diagnostics added:
CLI output migrated from fmt to logging.CLIPrintf/CLIPrintln across all cli subcommands; gpilet status uses CLIPrint. Diagnostic-only paths keep the zap channel (e.g. serve teardown warnings).
server middleware split from one middlewares.go into per-middleware files: middleware.go (interface + chain), cors.go, security.go, logging.go; dropped the unused unixMillis helper.
Docs: AGENTS.md Go conventions section (import grouping in 3 blocks via goimports -local, logging conventions, package file layout), README logging section, logging: example in examples/gpi-config.yaml, MEMORY.md v22.
What / 变更内容
Why / 为什么
How verified / 测试
make buildpasses (incl.go generate) / 通过(含go generate)go vet ./...passes / 通过go test ./...passes / 通过GOOS=linux/darwin GOARCH=amd64/arm64)Related / 关联
Notes / 其他