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.