a bug in " PatternLayout::format...

guolisen
2012-12-14
2013-05-20
  • guolisen

    guolisen - 2012-12-14

    Sstd::string PatternLayout::format(const LoggingEvent& event) {
            std::ostringstream message;
            for(ComponentVector::const_iterator i = _components.begin();
                i != _components.end(); ++i) {
                (*i)->append(message, event);
            }
    [b]return message.str();[/b]
        }

        void OstreamAppender::_append(const LoggingEvent& event) {
          [b][u]  (*_stream) << _getLayout().format(event);[/u][/b]
            if (!_stream->good()) {
                // XXX help! help!
            }
        }
    

    I use "OstreamAppender" and "PatternLayout", but sometimes Log4cpp crash in  "oprator<<" ,  I think "PatternLayout::format"  have problem. it shuold be like this:

    Sstd::string PatternLayout::format(const LoggingEvent& event) {
            std::ostringstream message;
            for(ComponentVector::const_iterator i = _components.begin();
                i != _components.end(); ++i) {
                (*i)->append(message, event);
            }
           return std::string(message.str()); //HERE!!!
        }
    
     
  • darkangel

    darkangel - 2012-12-14

    Nope :), it should'nt. message.str() allready has std::string type and such wrapping is useless.  If you work on Windows try to check runtimes - that common problem.

     

Log in to post a comment.