FovesLog
包括一系列和日志相关的工具。
可使用 pip 安装或下载源码使用:
pip install FovesLog
项目主页: https://github.com/Foves7017/FovesLib
setup_log
用于快速设置日志句柄,可以调节选项:
log_folder: Path=Path('./logs'):保存日志文件的文件夹
file_date_format: str='%Y_%m_%d':日志文件使用的时间格式
info_format: str='[%(asctime)s][%(levelname)s][%(name)s] %(message)s':输出日志使用的消息格式
save_to_file: bool=True:是否保存日志文件
output_to_console: bool=True:是否将日志输出到终端
console_level: int=logging.INFO:将日志输出到终端时使用的等级
keep_days: int=0:保留多少天的日期日志,0 表示不删除(负数同样视为不删除)
另外,如果安装了 colorama 库,在输出到终端时会自动设置彩色输出:
| 等级 | 颜色 |
|---|---|
| DEBUG | CYAN |
| INFO | WHITE |
| WARNING | YELLOW |
| ERROR | RED |
| CRITICAL | MAGENTA |
LoggedTask
用来快速建立耗时任务的日志。 使用时只需要使用上下文管理器创建实例:
with LoggedTask('等待'):
time.sleep(5)
# [2026-06-19 17:23:41,182][INFO][任务-等待] 任务 等待 开始
# [2026-06-19 17:23:46,183][INFO][任务-等待] 任务 等待 完成,用时 5.00 秒
可以获取返回的 LoggedTask 对象,这个对象提供一个 checkpoint 方法。会使用创建任务时指定的等级输出一条调试消息,并输出到上一条输出的用时。
with LoggedTask('等待') as task:
for i in range(5):
task.checkpoint(f'{i=}')
time.sleep(0.1)
# [2026-06-19 17:26:33,117][INFO][任务-等待] 任务 等待 开始
# [2026-06-19 17:26:33,118][INFO][任务-等待] i=0, 用时 0.00 秒
# [2026-06-19 17:26:33,218][INFO][任务-等待] i=1, 用时 0.10 秒
# [2026-06-19 17:26:33,319][INFO][任务-等待] i=2, 用时 0.10 秒
# [2026-06-19 17:26:33,420][INFO][任务-等待] i=3, 用时 0.10 秒
# [2026-06-19 17:26:33,520][INFO][任务-等待] i=4, 用时 0.10 秒
# [2026-06-19 17:26:33,621][INFO][任务-等待] 任务 等待 完成,用时 0.50 秒
可以通过 logger 指定输出所使用的 Logger,或通过 level 指定输出的等级
logger = logging.getLogger('TEST')
with LoggedTask('等待', level=logging.ERROR, logger=logger) as task:
time.sleep(0.1)
# [2026-06-19 17:28:31,653][ERROR][TEST] 任务 等待 开始
# [2026-06-19 17:28:31,754][ERROR][TEST] 任务 等待 完成,用时 0.10 秒
可以通过指定 time_precision 的方式来指定显示的小数位数,默认为 2
更新日志
v0.1.6
- 新增
DailyFileHandler:日期日志真正按天滚动,跨天时自动切换到新文件并关闭旧文件句柄(此前FileHandler的文件名在构造后就固定,不重启进程就不会换文件) setup_log新增keep_days参数,可删除超出保留期的旧日期日志,默认0表示不删除;清理逻辑集中在prune_old_logs(),只处理能按file_date_format解析出日期的*.log文件
v0.1.4
LoggedTask.__init__添加了time_precision参数,可以用来指定小数位数
v0.1.3
- 交换了
LoggedTask.__init__中logger和level的位置,更加易于使用
Metadata
Release files for FovesLog 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| foveslog-0.1.6.tar.gz | 7.6 kB | Without provenance | Details for foveslog-0.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| foveslog-0.1.6-py3-none-any.whl | Python 3 | none | any | Details for foveslog-0.1.6-py3-none-any.whl |
Total release size: 15.1 kB
Release files / foveslog-0.1.6.tar.gz
| Download URL | foveslog-0.1.6.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bf89e3916f0a1427875d59b461383d994b08872bfea49b5254e41d4c6ae70974
|
|
BLAKE2b-256 checksum How to use checksums |
98abe2c55527273ce41ae671ed09578fcaf283ef801f817817621c8a0c03f5d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Release files / foveslog-0.1.6-py3-none-any.whl
| Download URL | foveslog-0.1.6-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4355c0ab899e3561425d1302520166450ffc82bec4c45cc76faf4dffe5a578ce
|
|
BLAKE2b-256 checksum How to use checksums |
0e9aea9e7c47e722864208510fef674b7f055219b19016ee6460dfc5a67cb846
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.3
|
Security for FovesLog 0.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.