DailyRollingFileHandler ---- 文件应该每天轮换
我们有一个要求,要求有一个从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
日志轮换 - 告诉管理层 Apache 是世界上最大的代码库之一,我确信有数百万个项目在使用它。但是既然您重申了“管理决策”,您可以编写自己的 FileHandler 或使用 Java 文件处理程序,编写您的任务,编写数百个测试场景(例如当处理程序附加文件时石英滚动文件)
FileHander 写入两个文件- 要么对 FileHandler 进行子类化(文件处理程序应该知道何时发送到这两个文件),但是规定的解决方案是使用两个实际上不同的记录器,具有两个不同的名称,并附加两个附加程序。单个 java 源可以记录任意数量的记录器,因此
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
你不需要石英任务。在每个日志中验证是否需要破坏文件。
You don't need Quartz task. Verify at each log if there is a need to break the file.
您可以编写一个每天 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.