通过 Python 在大型脚本中记录每个步骤和操作

发布于 2024-12-21 12:46:26 字数 160 浏览 1 评论 0原文

我最后创建了一个大的 python 脚本。但现在我需要一个记录器。我在脚本中有输入步骤、提示..函数调用..While循环..等。

而且,记录器也必须记录成功操作。

我找不到适合我的答案。我又上网查了一下,也想问问你。

你的意见是什么?

谢谢

I have created a large python script at the end. But now I need a logger for it. I have input steps, prompts.. Function calls.. While Loops.., etc. in the script.

And also, the logger is have to log success operations too.

I couldn't find a suitable answer for me. I'm searching on the internet again, and wanted to ask you too.

Whats your opinion?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月松间行 2024-12-28 12:46:26

标准库中有一个模块 logging 。基本使用方法非常简单;在每个需要进行日志记录的模块中,放置

logger = logging.getLogger(__name__)

并记录,例如,

logger.info("Doing something interesting")
logger.warn("Oops, something's not right")

然后在主模块中,放置类似

logging.basicConfig(level=logging.INFO)

打印严重性为 INFO 或更严重的标准错误的所有日志。该模块非常可配置,请参阅其文档了解详细信息。

There's a module logging in the standard library. Basic usage is very simple; in every module that needs to do logging, put

logger = logging.getLogger(__name__)

and log with, e.g.,

logger.info("Doing something interesting")
logger.warn("Oops, something's not right")

Then in the main module, put something like

logging.basicConfig(level=logging.INFO)

to print all logs with a severity of INFO or worse to standard error. The module is very configurable, see its documentation for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文