英文:
When to choose the TRACE log level over the DEBUG log level
问题
在Rust的跟踪中,TRACE与DEBUG相比,它们用于什么情况?我查看了大量的互联网资源,但仍然没有找到一个关于追踪与调试的良好信息来源。这是在Rust的跟踪中,所以在追踪日志中没有堆栈跟踪。它只是另一种日志级别。何时应该使用TRACE而不是DEBUG?
英文:
I have looked at plenty of Internet resources and I still have not found a good source of information for what is used for trace vs debug. This is in Rust tracing, so there are no stack traces on trace logs. It's just another log level. When should I use TRACE over DEBUG?
答案1
得分: 0
Rust的log
、tracing
和许多其他库具有以下日志级别。
以下是何时使用每个级别的示例。
- FATAL - 这在Rust中不存在,因为您应该使用
panic!()
,但无论如何,我可能还是会包含它。
您应该使用FATAL来记录即将导致应用程序崩溃的错误。
示例:FATAL: 配置文件中的语法错误。中止。
- ERROR - 您应该使用ERROR来记录特定任务内部的错误。这些错误会导致任务失败,但这并不是世界末日。
示例:ERROR: 响应请求时出现断开的管道
- WARN - 您应该使用WARN来记录已从中恢复的错误。例如,您正在重试的事情(如果再次失败并且您放弃了,它应该变成ERROR)
- INFO - 您应该使用INFO来记录重要的运行时信息消息,例如主要的状态更新:
INFO: 服务器正在侦听端口80
INFO: 作为<API>登录为<USER>。
INFO: 完成每日数据库过期任务。
- DEBUG - 现在来到重要的部分。
DEBUG
日志应该基本上只记录变量或决策。每当需要记录变量或在重大决策之后,您都可以使用DEBUG日志,例如“用户执行了此操作”或“选择使用分块发送”。 - TRACE - TRACE日志纯粹是**“我在这里!”日志。它们不**用于块的开头或结尾,如if语句,用于指示“嘿,我做出了这个选择!”而是用于指示“嘿,我正在进行API请求...我完成了!”。
英文:
Rust log
, tracing
, and many others have the following log levels.
Here is when to use each, with examples.
- FATAL - This doesn't exist in Rust, because you
panic!()
, but I might as well include it either way.
You should use FATAL to log errors that are about to crash your application.
Example:FATAL: Syntax error in configuration file. Aborting.
- ERROR - You should use ERROR to log errors within some specific task. These errors are causing a task to fail, but it's not the end of the world.
Example:ERROR: Broken pipe responding to request
- WARN - You should use WARN to log errors that were recovered from. For example, things you're retrying again (if this fails again and you give up, it should end up being an ERROR)
- INFO - You should use INFO to log informational messages like major status updates that are important at runtime:
INFO: Server listening on port 80
INFO: Logged into <API> as <USER>.
INFO: Completed daily database expiration task.
- DEBUG - Now to the important part.
DEBUG
logs should basically always only log variables or decisions. You could use DEBUG logs whenever there's variables you need to log, or after a major decision like "user did this" or "choosing to use chunked sending" - TRACE - TRACE logs are purely "I am here!" logs. They are NOT used at the beginning or end of a block like an if statement to indicate "Hey, I made this choice!", they indicate "Hey, I'm making an API request... I'm done!"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论