Using Log4j CompositeTriggeringPolicy feature with log4CXX

人盡茶涼 提交于 2019-12-11 07:23:35

问题


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 ?


回答1:


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 method

// log4j
void setFile(String fileName, boolean append, boolean bufferedIO, int bufferSize);
// log4cxx
void setFile(const LogString& filename, bool append1, bool bufferedIO1, size_t bufferSize1, Pool& p);

to continue logging to the appropriate log chunk after process restart, and

// log4j
void subAppend(LoggingEvent event);
// log4cxx
virtual void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p); 

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 your

void setOption(const LogString& option, const LogString& value);

method, where you iterate through option strings and perform necessary initialization actions.

Hope that helps and comes in the right time.



来源:https://stackoverflow.com/questions/7178588/using-log4j-compositetriggeringpolicy-feature-with-log4cxx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!