本文介绍了记录约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您对log4j或类似库中的日志类别使用了哪些约定?
通常你看到类名作为类别,但是你使用过其他系统吗?

What conventions do you use for log categories in log4j or similar libraries ?Usually you see class names as categories, but have you used other systems ?

日志级别怎么样?您使用的是什么级别?在哪种情况下?

What about log levels ? What levels do you use and in which case ?

更新:正如你们有些人回答的那样,没有正确的答案。我只是在寻找人们使用的不同惯例作为灵感来源。

Update: as some of you replied, there is no 'right' answer. I'm just looking for what different conventions people use as a possible source of inspiration.

推荐答案

我同意:你必须知道你为什么要登录。

I agree with Vaibhav's answer: you have to know why you are logging.


  • 用于调试内部技术调试信息,log4j或任何其他库都可以(假设他们的用法没有人为地增加,需要通过发布总线(例如TIBCO)将这些信息记录到某种数据库。

  • for debug internal technical debug informations, log4j or any other library is fine (provided their usage does not artificially augment the cyclomatic complexity of the functions)
  • for transversal punctual logging (across the whole code), some Aspect-Oriented approach is better suited
  • for monitoring, you enter to an whole other level of logging, namely the KPI, with the need to record those information through a publication bus (like TIBCO for instance) to some kind of database.

因此,仅对于内部记录,我们遵循一种非常标准的方法:

So for internal logging only, we follow a pretty standard approach:


  • 严重对于任何可能危及程序的错误

  • 关于内部进展的信息

  • 罚款以获取某些子步骤详情

粒度(对于经典的内部日志记录)是主类,负责该过程的主要步骤。

The granularity (for classical internal logging) is the main class, the one in charge of the main steps of the process.

这篇关于记录约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 17:17