BigMichi1 opened a new issue, #439:
URL: https://github.com/apache/logging-log4cxx/issues/439

   when adding a `MultiprocessRollingFileAppender` to `log4cxx.xml` like in the 
following snippet
   
   ```xml
   <?xml version="1.0" encoding="UTF-8" ?>
   <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
   <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>
   
     <appender name="multi" 
class="org.apache.log4j.rolling.MultiprocessRollingFileAppender">
       <param name="file" value="log/logfile.log"/>
       <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
         <param name="FileNamePattern" 
value="log/logfile.%d{yyyy-MM-dd}.log.gz"/>
       </rollingPolicy>
       <triggeringPolicy 
class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
         <param name="MaxFileSize" value="100MB"/>
       </triggeringPolicy>
       <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss}] %c 
%-5p - %m%n"/>
       </layout>
     </appender>
   
     <root>
       <priority value ="debug" />
       <appender-ref ref="multi" />
     </root>
     
   </log4j:configuration>
   ```
   
   and in my `main.cpp`
   
   ```cpp
     LogLog::setInternalDebugging(true);
     DOMConfigurator::configure("log4cxx.xml");
     auto root = Logger::getRootLogger();
   
     LOG4CXX_DEBUG(root, "Foo Bar");
   ```
   
   i receive an error
   
   ```plain
   log4cxx: DOMConfigurator configuring file log4cxx.xml...
   log4cxx: Loading configuration file [log4cxx.xml].
   log4cxx: debug attribute= "".
   log4cxx: Ignoring internalDebug attribute.
   log4cxx: Threshold ="".
   log4cxx: Class name: 
[org.apache.log4j.rolling.MultiprocessRollingFileAppender]
   log4cxx: Setting option name=[file], value=[log/logfile.log]
   log4cxx: Parsing rolling policy of class: 
"org.apache.log4j.rolling.TimeBasedRollingPolicy"
   log4cxx: Setting option name=[FileNamePattern], 
value=[log/logfile.%d{yyyy-MM-dd}.log.gz]
   log4cxx: Parsing triggering policy of class: 
"org.apache.log4j.rolling.SizeBasedTriggeringPolicy"
   log4cxx: Setting option name=[MaxFileSize], value=[100MB]
   log4cxx: Parsing layout of class: "org.apache.log4j.PatternLayout"
   log4cxx: Setting option name=[ConversionPattern], value=[[%d{yyyy-MM-dd 
HH:mm:ss}] %c %-5p - %m%n]
   log4cxx: Adding appender named [multi] to logger [root].
   log4cxx: Can't cast writer to FileOutputStream
   ```
   
   as far as i understand the code it is caused by the cast in 
https://github.com/apache/logging-log4cxx/blob/master/src/main/cpp/multiprocessrollingfileappender.cpp#L508
   
   a quick and dirty implementation change which fixed the issue is instead of 
   
   ```cpp
   const FileOutputStreamPtr fos = LOG4CXX_NS::cast<FileOutputStream>( writer );
   ```
   
   something like this must be used to retrieve the `FileOutputStream` from the 
`WriterPtr`
   
   ```cpp
       const OutputStreamWriterPtr oswptr = 
static_pointer_cast<OutputStreamWriter>(writer);
       const OutputStreamPtr osptr = oswptr->getOutputStreamPtr();
       const CountingOutputStreamPtr cos = 
static_pointer_cast<CountingOutputStream>(osptr);
       const OutputStream *ptr = &(cos->getFileOutPutStreamPtr());
       const FileOutputStream *fos = dynamic_cast<const FileOutputStream 
*>(ptr);
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to