# 在python日志中使用轮转和压缩

在[Python简单日志](https://github.com/huataihuang/cloud-atlas-draft/tree/6f3204fffc11cf006abd394631e2598d98b415c3/develop/python/log/logging/README.md)中讨论了如何处理日志的方法，但是大量的日志会消耗存储资源，需要有一个良好的日志轮转和压缩功能。

通常在操作系统级别会采用通用的logrotate工具来实现日志轮转和压缩，但是对于python来说，也有丰富的日志库可以实现日志轮转和压缩功能。

## 参考

* [Python, want logging with log rotation and compression](https://stackoverflow.com/questions/8467978/python-want-logging-with-log-rotation-and-compression)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/develop/python/log/logging_with_log_rotation_and_compression.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
