testbuf(const string_type& str) : str_(str) { base::setg(const_cast<CharT*>(str_.data()), const_cast<CharT*>(str_.data()), const_cast<CharT*>(str_.data()) + str_.size()); }
void backend::consume(string_type const& formatted_message) { if (!impl_) return; if((impl_->file_.is_open() && (impl_->written_ + formatted_message.size() >= 512*1024) ) || !impl_->file_.good() ) { rotate_file(); } if (!impl_->file_.is_open()) { fs::create_directories(impl_->root_); impl_->file_.open((impl_->root_ / (impl_->name_ + L".log")).c_str(), std::ios_base::app | std::ios_base::out); if (!impl_->file_.is_open()) { throw bee::exception("Failed to open file '%s' for writing.", (impl_->root_ / (impl_->name_ + L".log")).string().c_str()); } impl_->written_ = static_cast<std::streamoff>(impl_->file_.tellp()); } impl_->file_.write(formatted_message.data(), static_cast<std::streamsize>(formatted_message.size())); impl_->file_.put(static_cast<string_type::value_type>('\n')); impl_->written_ += formatted_message.size() + 1; impl_->file_.flush(); }
//! The method writes the message to the sink BOOST_LOG_API void text_multifile_backend::consume(record_view const& rec, string_type const& formatted_message) { if (!m_pImpl->m_FileNameComposer.empty()) { filesystem::path file_name = m_pImpl->make_absolute(m_pImpl->m_FileNameComposer(rec)); filesystem::create_directories(file_name.parent_path()); m_pImpl->m_File.open(file_name, std::ios_base::out | std::ios_base::app); if (m_pImpl->m_File.is_open()) { m_pImpl->m_File.write(formatted_message.data(), static_cast< std::streamsize >(formatted_message.size())); m_pImpl->m_File.put(static_cast< string_type::value_type >('\n')); m_pImpl->m_File.close(); } } }
BOOST_LOG_API void basic_text_ostream_backend< CharT >::consume(record_view const&, string_type const& message) { typename string_type::const_pointer const p = message.data(); typename string_type::size_type const s = message.size(); typename implementation::ostream_sequence::const_iterator it = m_pImpl->m_Streams.begin(), end = m_pImpl->m_Streams.end(); for (; it != end; ++it) { register stream_type* const strm = it->get(); if (strm->good()) { strm->write(p, static_cast< std::streamsize >(s)); strm->put(static_cast< char_type >('\n')); if (m_pImpl->m_fAutoFlush) strm->flush(); } } }
/// /// Create a binary string from string \a s, that can be compared to other, useful for collation of multiple /// strings. /// /// The transformation follows these rules: /// \code /// compare(level,s1,s2) == sign( transform(level,s1).compare(transform(level,s2)) ); /// \endcode /// string_type transform(level_type level,string_type const &s) const { return do_transform(level,s.data(),s.data()+s.size()); }
long hash(level_type level,string_type const &s) const { return do_hash(level,s.data(),s.data()+s.size()); }
/// /// Compare two strings \a l and \a r using collation level \a level /// /// Returns -1 if the first of the two strings sorts before the seconds, returns 1 if sorts after and 0 if /// they considered equal. /// /// int compare(level_type level,string_type const &l,string_type const &r) const { return do_compare(level,l.data(),l.data()+l.size(),r.data(),r.data()+r.size()); }
/*! * The method finds the attribute value by name. * * \param key Attribute name. * \return Iterator to the found element or \c end() if the attribute with such name is not found. */ const_iterator find(string_type const& key) const { return find_impl(key.data(), key.size()); }