关于记录器名称的 Java 记录最佳实践

发布于 2024-10-05 21:47:39 字数 175 浏览 0 评论 0原文

我只是询问记录器名称...

可以为记录器指定自定义名称,或使用类名称。 但在什么情况下该使用什么呢?

->为每个应用程序模块使用自定义名称:某些类由 2 个模块使用 ->它应该属于哪个记录器名称?

->使用类名:似乎需要良好的包组织 ->记录的最佳实践知道吗?

I just ask about the logger name...

It it possible to give a custom name for a logger, or to use class name.
But what to use in which case?

-> Using a custom name for each application module: some classes are used by 2 modules -> to which logger name should it belong to?

-> Using classname: it seems to require a good package organisation -> best practices for logging known about that?

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

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

发布评论

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

评论(4

浸婚纱 2024-10-12 21:47:39

我更喜欢使用类名来进行调试。您可以从日志文件中读取日志跟踪(并且将显示类名)并查看行代码等。从这个意义上讲,它很有用。如果其他人维护您的代码,他们不必进行繁琐的搜索来查找“自定义名称”的填充位置(在哪个类中)。

I prefer using class names for the purpose of debugging. You can read the log trace (and the class name will be displayed) from the log file and view line code, etc. It's useful in that sense. If someone else maintains your code, they don't have to do hectic searches on finding where the "custom name" is populated (in which class).

云仙小弟 2024-10-12 21:47:39

我还是更喜欢类名。它并不需要一个良好的包组织,但反映了你的(好 - 嘿还有什么?)包组织。使用类名是一种常见的模式。

您可以从日志中读取日志记录类文件并在包上设置日志级别。

遵循常见模式可以防止我花费太多时间来思考好的(完美的)自定义记录器名称;-)

I still prefer classnames. It does not require a good package organisation but reflects your (good - hey what else?) package orgnization. And it's a common pattern to use the class names.

You can read the logging class file from the logs and set log levels on packages.

And following the common pattern prevents me from spending too much time on thinking about good (perfect) custom logger names ;-)

黯然#的苍凉 2024-10-12 21:47:39

我从来没有听说过有人使用类名以外的任何东西。我认为其他任何事情都会是一个错误,导致潜在的日志细节丢失。

不要想太多,只需使用类名运行即可。

I've never heard of anyone use anything other than class name. I think anything else would be a mistake, leading to potential loss of logging detail down the line.

Don't overthink this one, just run with class name.

番薯 2024-10-12 21:47:39

除了类名之外,我什么都不知道,因为无论如何,通过类来查找问题或其他任何内容都很容易阅读......!最好使用所有类型的日志级别来记录代码,例如跟踪所有可能的细节、致命的异常以及类似的调试、错误、信息等。

I donno about anything else than class name because in any case it's very easy to read through class for locating the issue or anything else..! And it is also better to log the code using all kinda log levels e.g. trace for all possible details, fatal for exception and similarly the debud,error,info etc.

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