Skip to main content

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 秒

Metadata

Release files for FovesLog 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for FovesLog 0.1.3
File Size Uploaded
foveslog-0.1.3.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for FovesLog 0.1.3
File Interpreter ABI Platform
foveslog-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.3 kB

Release files / foveslog-0.1.3.tar.gz

Download URL foveslog-0.1.3.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2ad832425f93703246d387271da3aa5fe3bfc1f9387481091df4c3a22ec21913
BLAKE2b-256 checksum
How to use checksums
539faefbbd645c6e1128c185ee7d0d3d724545687ca0509225374a82186bc915
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / foveslog-0.1.3-py3-none-any.whl

Download URL foveslog-0.1.3-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9037efceafe93b20ebe072caf047de974d8c969622bc4f33d3193612450ff9df
BLAKE2b-256 checksum
How to use checksums
9066734bbd613098f298a213476c5c12b464c420f6d0ab85bbb64fdeb8aff2fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

0.1.4

2 release files

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page