Exemple #1
0
 void operator()(std::ostream& strm, logging::record const& rec) 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, boost::ref(strm), _1)
     );
 }
Exemple #2
0
//[ example_core_record_attr_value_lookup
// Prints severity level by searching the attribute values
void print_severity_lookup(logging::record const& rec)
{
    logging::attribute_value_set const& values = rec.attribute_values();
    logging::attribute_value_set::const_iterator it = values.find("Severity");
    if (it != values.end())
    {
        logging::attribute_value const& value = it->second;

        // A single attribute value can also be visited or extracted
        std::cout << value.extract< severity_level >() << std::endl;
    }
}
//[ example_tutorial_formatters_custom
void my_formatter(std::ostream& strm, logging::record const& rec)
{
    // Get the LineID attribute value and put it into the stream
    strm << logging::extract< unsigned int >("LineID", rec).get() << ": ";

    // The same for the severity level
    strm << "<"
        << logging::extract< logging::trivial::severity_level >("Severity", rec).get()
        << "> ";

    // Finally, put the record message to the stream
    strm << rec.message();
}