Log First / 日誌優先
Writing buggy code is normal. Locating the bug is the hard part — logs are how you win that part. 寫程式碼犯錯是正常的,定位問題才是真正困難的——日誌就是你贏下這一關的方式。
The discipline / 紀律
- All new code carries key-path logs: connection established, state change, error raised, request/response. 所有新程式碼帶關鍵路徑日誌:連接建立、狀態變化、錯誤發生、請求/回應。
- Keep log format consistent and prefix each line with a module tag so it greps cleanly. 日誌格式統一,每行帶模組前綴,便於 grep。
- Error logs must carry context: which operation, which arguments, which error. 錯誤日誌必須帶上下文:什麼操作、什麼參數、什麼錯誤。
- This applies to agent-written code too — a sub-task to write code must require key-path logging. agent 寫的程式碼同樣適用——派寫程式碼的子任務時要寫明「加關鍵路徑日誌」。(派子任務的完整必含項見 agent-team 的「派子任務必含清單」)
When this triggers / 觸發時機
- About to write a new module / interface / external call / async task.
- Debugging a stretch of code that has no logs (add them first).
- Before handing an agent a code-writing sub-task (require "add key-path logs").
Done criterion (verifiable) / 完成判據(可驗證)
✅ A grep over the new code (e.g. grep -nE 'log\.(info|warn|error)' <file>) shows a line at each key path — connect, state change, error, request/response — each module-prefixed and carrying context.
⚠️ Some paths logged, some missing — name the gaps.
❌ The new code is silent. If it fails in prod, you'll be blind. Add logs before shipping.
Worked examples / 實戰反例
Real before/after cases for this discipline live in EXAMPLES.md — read them before you act. 本紀律的真實 before/after 反例見 EXAMPLES.md —— 動手前先對照。