Ejemplo n.º 1
0
Archivo: Log.cpp Proyecto: HymiR/i2pcpp
	void Log::formatter(boost::log::record_view const &rec, boost::log::formatting_ostream &s)
	{
		const boost::log::attribute_value_set& attrSet = rec.attribute_values();

		static std::locale loc(std::clog.getloc(), new boost::posix_time::time_facet("%Y-%m-%d %T.%f"));
		std::stringstream ss;
		ss.imbue(loc);
		if(!ss.good()) return;
		ss << boost::log::extract<boost::posix_time::ptime>("Timestamp", rec);
		if(!ss.good()) return;
		s << '[' << ss.str() << ']';

		s << ' ' << boost::log::extract<std::string>("Channel", rec);
		if(attrSet.find("Scope") != attrSet.end())
			s << '(' << boost::log::extract<std::string>("Scope", rec) << ')';
		s << '/' << boost::log::extract<severity_level>("Severity", rec);


		if(attrSet.find("RouterHash") != attrSet.end())
			s << " [" << boost::log::extract<RouterHash>("RouterHash", rec) << ']';

		if(attrSet.find("Endpoint") != attrSet.end())
			s << " [" << boost::log::extract<Endpoint>("Endpoint", rec) << ']';

		s << ": " << rec[expr::smessage];
	}
Ejemplo n.º 2
0
 void operator()(logging::record_view const& rec, logging::formatting_ostream& strm) const
 {
     // We need to acquire the attribute value from the log record
     logging::visit< scope_stack >
     (
         name_,
         rec.attribute_values(),
         boost::bind(&scope_list_formatter::format, _1, boost::ref(strm))
     );
 }
Ejemplo n.º 3
0
void StatsBackend::consume(boost::log::record_view const& rec)
{
    std::lock_guard<std::mutex> lock(m_mutex);

    
    if(rec.attribute_values().count("sent")) {
        m_stats.bytes_sent += boost::log::extract<uint64_t>("sent", rec).get();
    } else if(rec.attribute_values().count("received")) {
        m_stats.bytes_recv += boost::log::extract<uint64_t>("received", rec).get();
    } else if(rec.attribute_values().count("peers")) {
        m_stats.peer_count = boost::log::extract<uint32_t>("peers", rec).get();
    } else if(rec.attribute_values().count("i2np_ib")) {
        std::string msg_type = boost::log::extract<std::string>("i2np_ib", rec).get();
        if (m_stats.i2np_ib.find(msg_type) == m_stats.i2np_ib.end()) {
            m_stats.i2np_ib[msg_type] = 0;
        }
        m_stats.i2np_ib[msg_type] += 1;
    } else if(rec.attribute_values().count("i2np_ob")) {
        std::string msg_type = boost::log::extract<std::string>("i2np_ob", rec).get();
        if (m_stats.i2np_ob.find(msg_type) == m_stats.i2np_ob.end()) {
            m_stats.i2np_ob[msg_type] = 0;
        }
        m_stats.i2np_ob[msg_type] += 1;
    } else if(rec.attribute_values().count("participating")) {
        m_stats.participating_tunnels = boost::log::extract<uint32_t>("participating", rec).get();
    }
}
// The function consumes the log records that come from the frontend
void stat_collector::consume(logging::record_view const& rec)
{
    // Accumulate statistical readings
    if (rec.attribute_values().count("Connected"))
        ++m_active_connections;
    else if (rec.attribute_values().count("Disconnected"))
        --m_active_connections;
    else
    {
        namespace phoenix = boost::phoenix;
        logging::visit(sent, rec, phoenix::ref(m_sent_bytes) += phoenix::placeholders::_1);
        logging::visit(received, rec, phoenix::ref(m_received_bytes) += phoenix::placeholders::_1);
    }
    ++m_collected_count;

    // Check if it's time to write the accumulated data to the file
    boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
    if (now - m_last_store_time >= m_write_interval)
    {
        write_data();
        m_last_store_time = now;
    }
}
Ejemplo n.º 5
0
 /*!
  * Checking operator
  *
  * \param rec A log record
  * \return \c true if the log record contains the sought attribute value, \c false otherwise
  */
 result_type operator() (boost::log::record_view const& rec) const
 {
     return operator()(rec.attribute_values());
 }