Skip to content

refactor: config 路径自动检测 + 日志规范化 + me flag 过滤#36

Merged
NeverENG merged 1 commit into
mainfrom
refactor/config-improvements
May 20, 2026
Merged

refactor: config 路径自动检测 + 日志规范化 + me flag 过滤#36
NeverENG merged 1 commit into
mainfrom
refactor/config-improvements

Conversation

@NeverENG
Copy link
Copy Markdown
Owner

@NeverENG NeverENG commented May 20, 2026

Summary

  • 新增 defaultLogDir() — 从当前目录向上查找 go.mod 来定位项目根目录,自动推导 log/ 路径
  • WALPath / SSTablePath 改为基于自动检测的目录,不再硬编码 ../../../log
  • 新增 meFlagArgs() — 从 os.Args 中仅提取 -me / -me=... 参数,避免未定义 flag 报错
  • 所有日志改为结构化 slog 格式(无 [INFO] 等冗余前缀)
  • ParseFlags 中无效 me 值改为 panic(替代 os.Exit),便于定位调用栈

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Configuration system now gracefully handles file reading and parsing failures by reverting to defaults, preventing unexpected termination
    • Enhanced validation and structured logging of configuration parameters during initialization
    • Improved diagnostic output to aid troubleshooting of configuration discovery and startup processes

Review Change Stack

- 新增 defaultLogDir() 通过 go.mod 自动定位项目根目录,消除硬编码相对路径
- WALPath/SSTablePath 使用自动检测的 log 目录
- 新增 meFlagArgs() 过滤命令行参数,仅传递 -me 相关参数给 flag 解析
- 日志规范化:使用结构化 slog 格式,去除冗余标签前缀
- 无效 me 值时用 panic 替代 os.Exit,更易于调试

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@NeverENG NeverENG merged commit 33e4b8e into main May 20, 2026
0 of 3 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: edd91289-6f85-4efc-9ae0-b1c851878c08

📥 Commits

Reviewing files that changed from the base of the PR and between 4aada05 and aab7de6.

📒 Files selected for processing (1)
  • config/global.go

📝 Walkthrough

Walkthrough

This PR refactors global configuration initialization and CLI argument parsing in config/global.go. It introduces dynamic log directory discovery, improves error handling to be more resilient, adds structured logging to key initialization steps, and implements selective flag parsing for the -me argument with stricter validation.

Changes

Configuration and CLI updates

Layer / File(s) Summary
Log directory discovery infrastructure
config/global.go (imports, defaultLogDir() helper)
Import statements add path/filepath and strings. New unexported defaultLogDir() helper searches upward from the current working directory for go.mod to determine the log directory, falling back to "log" if not found.
Dynamic path configuration and initialization
config/global.go (NewGlobalConfig(), GlobalConfig.Init())
NewGlobalConfig() derives WALPath and SSTablePath dynamically via the computed log directory using filepath.Join. GlobalConfig.Init() logs the discovered config path, gracefully returns on read/unmarshal errors instead of terminating, and emits a finalized "config initialized" message.
Flag parsing with selective -me handling
config/global.go (GlobalConfig.ParseFlags(), meFlagArgs() helper)
ParseFlags() now filters arguments to only parse -me and -me= flags via new unexported meFlagArgs() helper. Structured logging is added for me set by flag/environment and for final config state. Invalid me handling changes from os.Exit(1) to panic.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through config with care,
Finding go.mod hiding here and there,
Flags parsed with grace, not exit but panic,
Error handling calm, not quite so manic,
Paths spring to life, dynamic and free!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/config-improvements

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant