将 Log4j CompositeTriggeringPolicy 功能与 log4CXX 结合使用
我想在附加程序中结合滚动时间和滚动大小,似乎 log4cxx 中没有复合滚动,对吗?
I would like to combine both rolling time and rolling size in an appender, it seems there is no composite rolling in log4cxx, am I right ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,没有。事实上,log4j 中也没有实现这样的组合策略,因此它没有转移到 log4cxx 中。
我曾经有一个任务是编写这样的混合策略滚动文件附加程序(尽管是在 log4j 中)。我通过重写 FileAppender 来做到这一点,特别是。该方法
在进程重新启动后继续记录到适当的日志块,并
在每个日志条目后测试滚动条件是否为真。
在 log4j/cxx 中实现自己的附加程序的一个真正强大的功能是,您可以在
log4j.properties
中定义其属性并由库设置它们。在 Java 中,由于反射,你可以免费获得它;在 log4cxx 中,您只需要编写方法,在其中迭代选项字符串并执行必要的初始化操作。
希望能有所帮助并在正确的时间出现。
No, there isn't. In fact, there is no such combined policy implemented in log4j, either, so it was not transferred to log4cxx.
I once had a task of writing such mixed-policy rolling file appender (in log4j, though). I did this by overriding
FileAppender
, esp. the methodto continue logging to the appropriate log chunk after process restart, and
to test after every log entry whether the condition for rolling over is true.
A truly powerful feature of implementing your own appender in log4j/cxx is that you can define its properties in
log4j.properties
and have them set by the library. In Java you get it for free, thanks to reflection; in log4cxx you only need to write yourmethod, where you iterate through option strings and perform necessary initialization actions.
Hope that helps and comes in the right time.