四叶的日志工具集
Project description
FovesLog
包括一系列和日志相关的工具。
可使用 pip 安装或下载源码使用:
pip install FovesLog
项目主页: https://github.com/Foves7017/FovesLib
setup_log
用于快速设置日志句柄,可以调节选项:
log_floder: 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:将日志输出到终端时使用的等级
另外,如果安装了 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 秒
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file foveslog-0.1.2.tar.gz.
File metadata
- Download URL: foveslog-0.1.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73693d5751b95eba523ec90ed26cfe116b9dd08ea2a3305c110a025966ae0c9e
|
|
| MD5 |
640e4008cc44b337c2a318e53b02787c
|
|
| BLAKE2b-256 |
54d06aabe9474020829b68ee76a5f14664eb3a7519df39d907404b525a13ca65
|
File details
Details for the file foveslog-0.1.2-py3-none-any.whl.
File metadata
- Download URL: foveslog-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb33de22b64bf85ecbdbf0737f3798f9c658590faeb5a9ca254b0c3e2a9ffee4
|
|
| MD5 |
bc6de6173a2dcef67b50af670372d6f1
|
|
| BLAKE2b-256 |
3d0acaa0439d217532b664a54af954530b0318c290b9ae86ed8990b253335b93
|