This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2025-01-15 18:14:35 +08:00

60 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 日志清理工具
## 功能描述
本工具用于自动清理指定目录及其子目录下的所有.log文件,并记录清理操作。
## 文件说明
- `clean_logs.py`: 主脚本文件
- `clean_logs.bat`: Windows批处理文件
- `clean_logs_history.log`: 自动生成的清理记录日志
## 使用方法
### 1. 配置
1. 使用文本编辑器打开`clean_logs.py`
2. 找到文件顶部的`TARGET_DIR`变量
3. 将其值修改为实际要清理的目录路径,例如:
```python
TARGET_DIR = "e:/path/to/your/logs"
```
### 2. 运行方式
- **Windows系统**
1. 双击`clean_logs.bat`文件
2. 脚本将自动执行,完成后会显示结果
- **其他系统**
1. 打开终端
2. 运行命令:
```bash
python clean_logs.py
```
## 运行效果
1. 脚本将:
- 递归清理指定目录及其子目录下的所有.log文件
- 在脚本所在目录生成`clean_logs_history.log`文件
- 自动清理超过7天的日志记录
2. 每次运行后:
- 终端会显示删除的文件路径
- 清理记录会追加到`clean_logs_history.log`
- 如果目录无效或Python未安装,会显示错误信息
## 注意事项
1. 请确保Python已安装并添加到系统PATH
2. 清理操作不可逆,请谨慎使用
3. 日志记录文件最多保留7天
4. 如果目标目录包含重要.log文件,请先备份
5. 支持中文路径,请确保系统编码设置为UTF-8
6. 文件大小统一以MB为单位显示
7. 清理记录包括:
- 删除时间
- 文件路径
- 文件大小
- 总清理统计
8. 如果遇到权限问题,请以管理员身份运行
9. 支持Windows、Linux、macOS系统
10. 建议定期清理日志记录文件
11. 可通过修改clean_logs.py中的timedelta(days=7)调整日志保留时间