DailyRollingFileHandler ---- 文件应该每天轮换

发布于 2024-08-25 13:10:23 字数 455 浏览 8 评论 0原文

我们有一个要求,要求有一个从 Java 日志记录扩展的处理程序,并允许每天轮换文件。

目前,Java util 日志记录确实支持使用文件处理程序根据文件大小进行轮换。它不支持每日轮换。 https://bugs.java.com/bugdatabase/view_bug?bug_id=6350749

所以,我们正在寻找这样一个允许每日轮换的附加器。我们想编写这样的处理程序,哪个处理程序适合扩展... StreamHandler 或 FileHandler ? 其他问题是,我们是否可以为单个处理程序(例如 FileHandler)配置 2 个不同的文件,例如,我们希望需要在一个文件中捕获某种消息,在另一个文件中捕获其他消息。

如有任何意见,将不胜感激。

We have a requirment which requires to have an Handler that is extended from Java logging and allows to have the files rotated on daily basis.

Currently Java util logging do have the support of rotation based on file size by using File Handler. It doesnt support rotation on daily basis. https://bugs.java.com/bugdatabase/view_bug?bug_id=6350749

So , what we are looking is for such an appender that allows daily rotation . We would like to write such handler and which is the appropriate handler to extend for ... StreamHandler or FileHandler ?
And other questions are , is there way we can configure 2 different files for a single handler say FileHandler say for eg , we would like some kind of messages need to be captured in one file and other messages in other file.

Would appreciate for any comments.

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

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

发布评论

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

评论(3

甜宝宝 2024-09-01 13:10:23

日志轮换 - 告诉管理层 Apache 是世界上最大的代码库之一,我确信有数百万个项目在使用它。但是既然您重申了“管理决策”,您可以编写自己的 FileHandler 或使用 Java 文件处理程序,编写您的任务,编写数百个测试场景(例如当处理程序附加文件时石英滚动文件)

FileHander 写入两个文件- 要么对 FileHandler 进行子类化(文件处理程序应该知道何时发送到这两个文件),但是规定的解决方案是使用两个实际上不同的记录器,具有两个不同的名称,并附加两个附加程序。单个 java 源可以记录任意数量的记录器,因此

class MyClass {
    Logger fileLogger = Logger.getLogger("something.mapped.to.file");
    Logger dbLogger = Logger.getLogger("something.mapped.to.db");

    public void someMethod() {
        dbLogger.log("XXX");
        fileLogger.log("YYY");
    }
}

Log rotation - Tell management that Apache is one of the largest code houses in the world and I am sure there are millions of projects that use it. But since you have reiterated "Management decision" you could write your own FileHandler or use Java File handler, write your tasks, write the many hundred scenarios of tests (like quartz rolling the file when the handler is appending them)

FileHander writing to two files - Either subclass the FileHandler (The filehandler should know when to send to these two files) But the prescribed solutions would be to use two actually different loggers with two different names with two appenders attached. A single java source can do logging to as many loggers as it wants, so

class MyClass {
    Logger fileLogger = Logger.getLogger("something.mapped.to.file");
    Logger dbLogger = Logger.getLogger("something.mapped.to.db");

    public void someMethod() {
        dbLogger.log("XXX");
        fileLogger.log("YYY");
    }
}
在风中等你 2024-09-01 13:10:23

你不需要石英任务。在每个日志中验证是否需要破坏文件。

You don't need Quartz task. Verify at each log if there is a need to break the file.

从此见与不见 2024-09-01 13:10:23

您可以编写一个每天 00:00 运行的调度程序(Quartz 调度程序或类似的程序)。让代码执行 FileHandler 的操作并执行文件轮换。

You can write a scheduler (Quartz scheduler or something similar) that runs at 00:00 hours daily. Let the code do the FileHandler stuff and perform file rotation.

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