对于日志级别是否有近乎共识的指南?

发布于 2024-11-07 13:29:37 字数 465 浏览 0 评论 0原文

我和我的团队在过去两家公司使用的日志级别影响了我。我将在这里分享我们的内容,但请记住,这一点是主观的:

  • 致命 - 您的应用程序正在崩溃。
  • 错误 - 此操作或线程正在崩溃并燃烧。该应用程序也许能够继续。
  • 警告 - 当前操作可能可以继续,但工程师需要调查某些内容。
  • 信息 - 解释您的操作正在做什么。
  • 调试 - 可能会产生大量垃圾信息的操作的说明(内部循环等)。

现在,我的客观问题是在这方面是否有一个高度一致的风格定义。答案可能是否定的。但如果有这样一个标准,你能提供一个 URL 吗?

另请注意,我并不真正关心实际配置什么阈值来记录部署/生产环境中有用的地方。相反,我的问题仅限于我们这些编写代码的人应该使用的指南。

我在我的问题上添加了 C# 标签和 Java 标签。我们可能在这两个阵营有不同的指导方针,但我们的不同可能只是文化原因,而不是概念原因。

I've been influenced by the log levels that I and my teams have used at my last two companies. I'll share ours here but keep in mind this bit is subjective:

  • Fatal - Your app is going down.
  • Error - This operation or thread is crashing and burning. The app may be able to continue.
  • Warn - The current operation may be able to continue but an engineer needs to investigate something.
  • Info - Explain what your operation is doing.
  • Debug - Explanation of operations that may get pretty spammy (inner loops, etc).

Now, my objective question is whether there is a highly-agreed upon style defined in this regard. The answer may be no. But if there is such a standard, can you point a URL to it?

Also note that I don't really care what threshold is actually configured to log somewhere useful in a deployed / production environment. Rather, my question is restricted to guidelines that those of us who write code should use.

I'm putting a C# tag and Java tag on my question. It's possible we'd have different guidelines in these two camps but there are probably only cultural reasons that we'd differ, not conceptual reasons.

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

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

发布评论

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

评论(4

随梦而飞# 2024-11-14 13:29:37

我什至不确定是否可以客观地回答“高度同意”的事情。

Log4jLog4Net 库当然采用您所描述的级别定义。请参阅此链接

有人可能会生成一个使用不同定义的日志级别集的库的反例。

I'm not even sure that whether something is "highly-agreed" upon can be answered objectively.

The Log4j and Log4Net libraries certainly employ the level definitions that you've described. See this link.

Somebody might yet produce a counter-example of a library that uses a differently defined set of logging levels.

無處可尋 2024-11-14 13:29:37

来自 SSCLI(.NET 来源):

namespace System {
    ...
    [Serializable]
    internal enum LogLevel {
        Trace  = 0,
        Status = 20,
        Warning= 40,
        Error  = 50,
        Panic  = 100,
    }
    ...
}

注意 [警告] 值)我依赖于这种发行版变体。无论如何,它是微软)

from SSCLI (.NET sources):

namespace System {
    ...
    [Serializable]
    internal enum LogLevel {
        Trace  = 0,
        Status = 20,
        Warning= 40,
        Error  = 50,
        Panic  = 100,
    }
    ...
}

note the [warning] values) I rely on this variant of distribution. anyway it's Microsoft)

青柠芒果 2024-11-14 13:29:37

据我所知,不存在“高度一致”的标准、风格或建议。但是 Java 的每个主流日志记录子系统都有一组与您已确定的 5 个级别相对应的级别。事实上,这些级别在实践中已经足够一致,可以使用 SLF4J 外观“统一”日志记录。 (我想你可能会说这使得 SLF4J 级别 Java 事实上的首选风格。)

我想添加一些警告:

  • 关于工程师可以和应该做什么来响应日志事件的建议超出了描述日志事件含义的范围。

  • 这些类别必然是主观的,但使用“崩溃和烧毁”这样的语言会导致误解。

  • 在实践中,用法很可能与事实上的风格不一致;例如,某些日志系统允许您使用其他(非清单)级别,并且开发人员可能会在“错误”级别记录事件。


请注意,slf4j 1.4 添加了对 TRACE 级别的支持。

There's no "highly agreed upon" standard, style or advice that I'm aware of. But each of the mainstream logging subsystems for Java has a set of levels that correspond to the 5 that you have identified. Indeed, the levels are well enough aligned in practice that it is possible to "unify" logging using the SLF4J facade. (I guess that you could say that this makes the SLF4J levels a defacto preferred style for Java.)

I would add a couple of caveats:

  • Advice about what an engineer can and should do in response to a log event is out of scope in describing what log events mean.

  • The categories are necessarily subjective, but using language like "crash and burn" is going to lead to misunderstanding.

  • In practice, usage may well not be consistent with the defacto style; e.g. some logging systems allow you to use other (non-manifest) levels, and developers may log events at the "wrong" level.


Note that slf4j 1.4 added support for a TRACE level.

半﹌身腐败 2024-11-14 13:29:37

我想添加 Python 日志记录工具的级别:

DEBUG - 详细信息,通常仅在诊断问题时才感兴趣。

信息 - 确认事情按预期进行。

警告 - 表示发生了意外情况,或表示不久的将来会出现某些问题(例如“磁盘空间不足”)。该软件仍然按预期工作。

错误 - 由于更严重的问题,该软件无法执行某些功能。

CRITICAL - 严重错误,表明程序本身可能无法继续运行。

这些可以在这里找到:
http://docs.python.org/howto/logging.html#logging -基础教程

Thought I'd add the levels from the Python logging facility:

DEBUG - Detailed information, typically of interest only when diagnosing problems.

INFO - Confirmation that things are working as expected.

WARNING - An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.

ERROR - Due to a more serious problem, the software has not been able to perform some function.

CRITICAL - A serious error, indicating that the program itself may be unable to continue running.

These can be found here:
http://docs.python.org/howto/logging.html#logging-basic-tutorial

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