# Discipline Log First

> 三、日志优先（可观测性）

- Skill: `yli769227-jpg/discipline-log-first` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add yli769227-jpg/discipline-log-first`
- Raw SKILL.md: https://api.skillmd.com/api/skills/yli769227-jpg/discipline-log-first/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: yli769227-jpg (https://skillmd.com/u/yli769227-jpg)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/yli769227-jpg/discipline-log-first

---


## 三、日志优先（可观测性）

写代码犯错是正常的，定位问题才是真正困难的。

1. 所有新代码必须包含关键路径日志：连接建立、状态变化、错误发生、请求/响应。
2. 日志格式统一，带前缀标识模块，便于 grep。
3. 错误日志必须包含上下文：什么操作、什么参数、什么错误。
4. Agent 写代码时也必须遵守。

## 加载时机

- 即将写新模块 / 新接口 / 新外部调用 / 新异步任务
- 正在 debug 一段没有日志的代码
- 派 agent 子任务写代码前(任务描述里要明确"加关键路径日志")

## 配套

具体反面例子 / 正面例子见 `EXAMPLES.md`。

