On Feb 1, 2007, at 3:31 PM, Mark Toohey wrote:
Hi,
I wrote some code which updates some fileAppenders after the files
reach a
certain size ( so once a file reaches x size it will be rolled over
into an
overflow file ). It was working fine when it was compiled as debug
application
(using VC6++ ). I compiled it as a release and this code is now
causing me
problems....specifically I believe when it tries to destruct the
object and
create a new one. Is there another way that I can change the
current settings in
an appender?
Is there some reason that log4cxx::rolling::RollingFileAppender (the
one defined in log4cxx/rolling/rollingfileappender.h, not the one in
log4cxx/rollingfileappender.h) doesn't work for you? It allows
pluggable triggering policies (the part that decides that it is time
to roll) and rolling policies (the part that decides on file name).
log4cxx::RollingFileAppender is a specific configuration of
log4cxx::rolling::RFA to emulate org.apache.log4j.RollingFileAppender.
I'm not sure what the following code does. I'm just throwing off
random observations.
LoggerPtr loggerRef = (LoggerPtr&)curLogger->loggerPtr;
Why do you need the cast? Actually, it would more efficient to use
the copy constructor (instead of a default constructor and assignment):
LoggerPtr loggerRef(curLogger->loggerPtr);
DailyRollingFileAppenderPtr appender = loggerRef->getAppender
( cName );
This will throw an exception if the appender isn't a DRFA. DRFA is a
specific configuration of log4cxx::rolling::RFA
cOption = convert_to_wchar_t( "file" );
cFile = convert_to_wchar_t( * curLogger->loggingModule->file );
appender->setOption( cOption , cFile );
logchar is typically UTF-8 char on Unixes and wchar_t on Windows
(though that can be changed by configuration). I'm guessing this
would not compile if logchar == UTF-8. Also, if you are going to the
effort to cast to DRFA, then you should use setFile() instead of the
generic setOption(). So either:
appender->setOption(LOG4CXX_STR("file"), curLogger->loggingModule-
>file);
of just:
appender->setFile(curLogger->loggingModule->file);
Pool pool;
appender->activateOptions( pool );