I am using the following code to set the log file dynamically instead of
defining it in the xml file:
DOMConfigurator::configure(config);
LoggerPtr logger = Logger::getLogger(cat_name);
FileAppenderPtr appender = logger->getAppender("FILE");
Pool p;
appender->setFile(log_name);
appender->activateOptions(p);
This works with one small side effect. It seems I have to provide a
default setting for the File parameter in the xml config file, otherwise
the configure command complains when the app runs. So I tried doing
this:
<appender name="FILE" class="org.apache.log4j.FileAppender">
<param name="Append" value="true" />
<param name="File" value="TBD" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] [%c{1}]
%m%n"/>
</layout>
</appender>
but this ended up creating an empty file called TBD before the call to
setFile had a chance to run. I have a workaround where I set File to
/dev/null instead of TBD and this seems to work. Is there a
better/correct way to do this?
]