【问题标题】:Problem extending jog4j RollingFileAppender rollOver() access Level扩展 jog4j RollingFileAppender rollOver() 访问级别的问题
【发布时间】:2010-10-15 16:44:25
【问题描述】:

我正在尝试扩展 RollingFileAppender,以便即使没有消息进入日志系统,它也会旋转。通常当消息到达并完成时间检查以触发旋转时调用 rollOver 方法。

我的 RollingFileAppender 版本将每 x 秒调用一次 rollOver,这样即使没有消息到达,我也能保证轮换。

现在我的问题是 RollingFileAppender rollOver 的访问级别修饰符没有修饰符。因此,我不能像我希望的那样每隔 x 秒调用一次。

  /**
     Rollover the current file to a new file.
  */
  void rollOver() throws IOException {

现在查看代码,我不明白为什么它不需要修改器,我决定将这个类放入我的包中并调用 rollOver。

现在感觉很脏,如果我想调用 rollOver,我还有其他选择吗?

【问题讨论】:

  • 您使用哪个版本的 log4j?它在我使用的 1.2.14 和最新的 1.2.15 中是公开的。
  • 1.2.15 我把上面的代码从源代码中粘贴出来

标签: java logging log4j access-modifiers


【解决方案1】:

你当然可以使用反射来做到这一点。

从主干或标签 1.2.15 中提取的源代码:svn at apache

public // synchronization not necessary since doAppend is alreasy synched
void rollOver() {
  File target;
  ...

我们谈论的是同一件事吗:log4j-1.2.15?

【讨论】:

  • 谢谢 Matthieu 我去看看
猜你喜欢
  • 1970-01-01
  • 2016-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-17
  • 2011-10-05
相关资源
最近更新 更多