如何记录新创建的日志文件?

发布于 2024-12-29 05:41:18 字数 159 浏览 1 评论 0原文

我被要求日志文件的第一行必须以特定标头开头。该标头应指定当前文件是新创建的。即使日志文件自动轮换。

这看起来很奇怪,但它是在项目规范中的。

环境信息:

  • 应用程序服务器:Glassfish V2
  • 日志记录:SL4J

I've been given the requirement that the first line of my log files must begin with a specific header. This header should specify that this current file is newly created. Even when log files are automatically rotated.

It seems odd but it is in the specification for the project.

Environment info:

  • App Server: Glassfish V2
  • Logging: SL4J

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

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

发布评论

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

评论(2

倾城月光淡如水﹏ 2025-01-05 05:41:18

我认为您必须对相关附加程序进行子类化并添加您自己的代码才能执行此操作。

I think you're going to have to subclass the relevant appender and add your own code to do this.

轻许诺言 2025-01-05 05:41:18

日志文件不是slf4j写入的。它是由立面后面的日志系统编写的。解决方案将取决于日志系统是什么。

除非该日志系统具有执行此操作的现有日志文件附加程序,否则您将需要编写一个自定义附加程序(使用适当的 API 等),以便在每次打开新日志文件时写入标头。

The log file is not written by slf4j. It is written by the logging system behind the facade. The solution will depend on what that logging system is.

Unless that logging system has an existing log file appender that does this, you will need to write a custom appender (using the appropriate API, etc) that writes the header each time it opens a new log file.

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