#include "tuple_log.h" #include #include #include template void benchmark (logging::basic_logger& the_log, const std::string& what, const typename logging::basic_logger::entry_type& entry) { size_t counter = 0; boost::timer timer; while (counter < 1000000) { the_log.write (entry); ++counter; } std::cout << what << ": " << counter << " logging operations in " << timer.elapsed() << " sec = " << counter / timer.elapsed() << " ops/sec or " << timer.elapsed() / counter << " sec/op\n"; } void test1 () { tuple_log::logger the_log; typedef tuple_log::logger::entry_type entry_type; tuple_log::ostream_sink out (std::cout); tuple_log::file_sink logfile ("log.log", std::ios::app, false); the_log.filter() = tuple_log::filter(); the_log.sinks().push_back (boost::ref (out)); the_log.sinks().push_back (boost::ref (logfile)); the_log.write (entry_type (tuple_log::level::info, tuple_log::category:: program_flow, "Noise", "Here I am!")); the_log.write (entry_type (tuple_log::level::error, tuple_log::category::program_flow, BOOST_CURRENT_FUNCTION, "Done")); benchmark (the_log, "level exclusion", entry_type (tuple_log::level::trace, tuple_log::category::program_flow, "Trace", BOOST_CURRENT_FUNCTION)); benchmark (the_log, "category exclusion", entry_type (tuple_log::level::trace, tuple_log::category::function_arguments, "Trace", BOOST_CURRENT_FUNCTION)); /// Change the filter on the log so that the keyword "info" is /// disabled (this is independent of tuple_log::level::info) the_log.filter() = tuple_log::filter (tuple_log::level::default_value, tuple_log::category::default_value, "!info"); benchmark (the_log, "keyword exclusion", entry_type (tuple_log::level::info, tuple_log::category::program_flow, "info", BOOST_CURRENT_FUNCTION)); the_log.sinks().clear (); benchmark (the_log, "empty sink list", entry_type (tuple_log::level::warning, tuple_log::category::function_arguments, "info", BOOST_CURRENT_FUNCTION)); } int main () { test1(); }