# 日志捕获警告：在caplog中未找到名为'myapp'的日志记录器

- **ID:** `python/pytest-logging-capture-missing`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用caplog fixture捕获日志消息，但指定的日志记录器名称不存在或未配置，因此未捕获到任何日志记录。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.0.0 | active | — | — |
| 8.0.0 | active | — | — |

## 解决方案

1. **Verify the logger name used in the code under test and match it in caplog** (90% 成功率)
   ```
   In the test:
import logging
logger = logging.getLogger('myapp')
logger.info('test message')
with caplog.at_level(logging.INFO, logger='myapp'):
    # run code
    assert 'test message' in caplog.text
   ```
2. **Use caplog.set_level() to enable capturing for all loggers** (85% 成功率)
   ```
   caplog.set_level(logging.DEBUG)
# Now all log messages are captured
assert 'expected message' in caplog.text
   ```

## 无效尝试

- **Using caplog.clear() before capturing logs** — This clears existing logs but does not fix the logger name issue. (50% 失败率)
- **Setting the log level to DEBUG globally** — This may generate more logs but does not ensure the correct logger is captured. (40% 失败率)
