Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2008-01-14 20:49:32


Author: jtorjo
Date: 2008-01-14 20:49:32 EST (Mon, 14 Jan 2008)
New Revision: 42784
URL: http://svn.boost.org/trac/boost/changeset/42784

Log:
[logging]
v0.13.14, 15 jan 2008
- added test_tags test
Added:
   sandbox/logging/lib/logging/tests/test_tags/test_tags.cpp (contents, props changed)
Removed:
   sandbox/logging/lib/logging/tests/test_tags/test.cpp
Text files modified:
   sandbox/logging/boost/logging/detail/format_write_detail.hpp | 5 +++++
   sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp | 3 ++-
   sandbox/logging/boost/logging/format/formatter/convert_format.hpp | 20 +++++++++++++-------
   sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp | 2 +-
   sandbox/logging/lib/logging/tests/test_tags/test.vcproj | 2 +-
   5 files changed, 22 insertions(+), 10 deletions(-)

Modified: sandbox/logging/boost/logging/detail/format_write_detail.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/format_write_detail.hpp (original)
+++ sandbox/logging/boost/logging/detail/format_write_detail.hpp 2008-01-14 20:49:32 EST (Mon, 14 Jan 2008)
@@ -124,6 +124,11 @@
 @remarks Normally the router could own the formatters and destination objects. However, then, it would need to own the objects,
 which would mean needing to come up with a smart pointer strategy. This would complicate the router logic.
 Also, iterating over formatters/destinations would be slower, if we were to keep smart pointers within the router itself.
+
+
+
+@bug adding a spaced generic formatter and deleting the formatter - it won't happen
+
 */
 template<
         class formatter_base,

Modified: sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/changelog.hpp 2008-01-14 20:49:32 EST (Mon, 14 Jan 2008)
@@ -1,7 +1,8 @@
 /**
 @page page_changelog Changelog
 
-_at_section changelog_cur_ver Current Version: v0.13.13, 15 jan 2008
+@section changelog_cur_ver Current Version: v0.13.14, 15 jan 2008
+- added test_tags test
 - added test_named_spacer test
 - solved bug if user doesn't use formatters/destinations, but uses cached string classes
 - solved bug in rolling_file - it could not compile on gcc

Modified: sandbox/logging/boost/logging/format/formatter/convert_format.hpp
==============================================================================
--- sandbox/logging/boost/logging/format/formatter/convert_format.hpp (original)
+++ sandbox/logging/boost/logging/format/formatter/convert_format.hpp 2008-01-14 20:49:32 EST (Mon, 14 Jan 2008)
@@ -40,7 +40,7 @@
             class param9 ,
             class param10> struct holder ;
 }
-
+
 namespace formatter {
 
 
@@ -108,7 +108,8 @@
             dest.prepend_string(src);
         }
 
- template<class string, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(const string_type & src, ::boost::logging::tag::holder<string,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ template<class string_, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(const string_type & src, ::boost::logging::tag::holder<string_,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ typedef typename use_default<string_, hold_string_type>::type string;
             write(src, static_cast<string&>(dest) );
         }
 
@@ -121,7 +122,8 @@
             dest.prepend_string(src);
         }
 
- template<class string, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(char_array src, ::boost::logging::tag::holder<string,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ template<class string_, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(char_array src, ::boost::logging::tag::holder<string_,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ typedef typename use_default<string_, hold_string_type>::type string;
             write(src, static_cast<string&>(dest) );
         }
     }
@@ -138,7 +140,8 @@
         template<class string> void write(const string_type & src, boost::logging::optimize::cache_string_several_str<string> & dest) {
             dest.append_string(src);
         }
- template<class string, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(const string_type & src, ::boost::logging::tag::holder<string,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ template<class string_, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(const string_type & src, ::boost::logging::tag::holder<string_,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ typedef typename use_default<string_, hold_string_type>::type string;
             write(src, static_cast<string&>(dest) );
         }
 
@@ -152,7 +155,8 @@
         template<class string> void write(char_array src, boost::logging::optimize::cache_string_several_str<string> & dest) {
             dest.append_string(src);
         }
- template<class string, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(char_array src, ::boost::logging::tag::holder<string,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ template<class string_, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(char_array src, ::boost::logging::tag::holder<string_,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ typedef typename use_default<string_, hold_string_type>::type string;
             write(src, static_cast<string&>(dest) );
         }
 
@@ -173,7 +177,8 @@
         template<class string> void write(string_type & src, boost::logging::optimize::cache_string_one_str<string> & dest) {
             dest.set_string_swap(src);
         }
- template<class string, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(const string_type & src, ::boost::logging::tag::holder<string,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ template<class string_, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(const string_type & src, ::boost::logging::tag::holder<string_,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ typedef typename use_default<string_, hold_string_type>::type string;
             write(src, static_cast<string&>(dest) );
         }
 
@@ -188,7 +193,8 @@
         template<class string> void write(char_array src, boost::logging::optimize::cache_string_several_str<string> & dest) {
             dest.set_string(src);
         }
- template<class string, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(char_array src, ::boost::logging::tag::holder<string,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ template<class string_, class p1, class p2, class p3, class p4, class p5, class p6, class p7, class p8, class p9, class p10> void write(char_array src, ::boost::logging::tag::holder<string_,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10> & dest) {
+ typedef typename use_default<string_, hold_string_type>::type string;
             write(src, static_cast<string&>(dest) );
         }
     }

Modified: sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp
==============================================================================
--- sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp (original)
+++ sandbox/logging/lib/logging/samples/scenarios/using_tags.cpp 2008-01-14 20:49:32 EST (Mon, 14 Jan 2008)
@@ -31,7 +31,7 @@
 #include <boost/logging/format_fwd.hpp>
 #include <boost/logging/tags.hpp>
 
-// Step 1: Optimize : use a cache string, to make formatting the message faster
+// Step 1: Optimize : use tags (on top of a cache string, to make formatting the message faster)
 namespace bl = boost::logging;
 typedef bl::tag::holder< bl::optimize::cache_string_one_str<>, bl::tag::file_line, bl::tag::thread_id, bl::tag::time> log_string;
 BOOST_LOG_FORMAT_MSG( log_string )

Deleted: sandbox/logging/lib/logging/tests/test_tags/test.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/test_tags/test.cpp 2008-01-14 20:49:32 EST (Mon, 14 Jan 2008)
+++ (empty file)
@@ -1,8 +0,0 @@
-/*
- Tests ...
-*/
-
-#include <boost/logging/logging.hpp>
-
-int main() {
-}

Modified: sandbox/logging/lib/logging/tests/test_tags/test.vcproj
==============================================================================
--- sandbox/logging/lib/logging/tests/test_tags/test.vcproj (original)
+++ sandbox/logging/lib/logging/tests/test_tags/test.vcproj 2008-01-14 20:49:32 EST (Mon, 14 Jan 2008)
@@ -172,7 +172,7 @@
         </References>
         <Files>
                 <File
- RelativePath=".\test.cpp"
+ RelativePath=".\test_tags.cpp"
>
                 </File>
         </Files>

Added: sandbox/logging/lib/logging/tests/test_tags/test_tags.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/test_tags/test_tags.cpp 2008-01-14 20:49:32 EST (Mon, 14 Jan 2008)
@@ -0,0 +1,102 @@
+/*
+ Tests using tags
+ - tests writing file/line & function
+ - tests dumping the module and the thread_id
+
+*/
+
+#include <boost/logging/format_fwd.hpp>
+#include <boost/logging/tags.hpp>
+
+// Optimize : use tags
+namespace bl = boost::logging;
+typedef bl::tag::holder< bl::default_, bl::tag::file_line, bl::tag::function, bl::tag::thread_id, bl::tag::module> log_string;
+BOOST_LOG_FORMAT_MSG( log_string )
+
+#include <boost/logging/format.hpp>
+#include <boost/logging/format/formatter/tags.hpp>
+
+using namespace boost::logging::scenario::usage;
+typedef use< filter_::change::single_thread, filter_::level::no_levels, logger_::change::single_thread, logger_::favor::single_thread > finder;
+
+using namespace boost::logging;
+
+BOOST_DEFINE_LOG_FILTER(g_log_filter, finder::filter )
+BOOST_DEFINE_LOG(g_l, finder::logger )
+
+
+
+
+
+// this macro is used to write the file/line and function
+#define LOG_FILE_FUNC_ BOOST_LOG_USE_LOG_IF_FILTER(g_l, g_log_filter->is_enabled() ) .set_tag( BOOST_LOG_TAG_FILELINE) .set_tag( BOOST_LOG_TAG_FUNCTION)
+
+// this macro is used to write module and thread id
+#define LOG_MODULE_(mod) BOOST_LOG_USE_LOG_IF_FILTER(g_l, g_log_filter->is_enabled() ) .set_tag( BOOST_LOG_TAG(module)(mod) )
+
+
+// whatever we log, is logged here too (easy was to find out all the info that was logged)
+std::stringstream g_out;
+
+// we're constantly writing hello world
+std::string g_msg = "hello world";
+
+void init_logs_fileline_function() {
+ g_l->writer().add_formatter( formatter::tag::file_line()); //, "[%] " );
+ g_l->writer().add_formatter( formatter::tag::function()); //, "% " );
+ g_l->writer().add_formatter( formatter::append_newline() );
+ g_l->writer().add_destination( destination::stream(g_out) );
+ g_l->writer().add_destination( destination::cout() );
+ g_l->turn_cache_off();
+}
+
+// the str should contain
+bool test_str_contains(const std::string & str, const std::string & find) {
+ return str.find(find) != std::string::npos;
+}
+
+void test_fileline_function() {
+ init_logs_fileline_function();
+ LOG_FILE_FUNC_ << g_msg;
+ BOOST_ASSERT( test_str_contains( g_out.str(), "test_tags.cpp"));
+ BOOST_ASSERT( test_str_contains( g_out.str(), "test_fileline_function"));
+ g_out.str("");
+
+ LOG_FILE_FUNC_ << g_msg;
+ BOOST_ASSERT( test_str_contains( g_out.str(), "test_tags.cpp"));
+ BOOST_ASSERT( test_str_contains( g_out.str(), "test_fileline_function"));
+ g_out.str("");
+}
+
+
+void init_logs_module_thread_id() {
+ g_l->writer().del_formatter( formatter::tag::file_line() );
+ g_l->writer().del_formatter( formatter::tag::function() );
+
+ // after deleting the file/line and function formatters, they shouldn't be called
+ LOG_FILE_FUNC_ << g_msg;
+ BOOST_ASSERT( !test_str_contains( g_out.str(), "test_tags.cpp"));
+ BOOST_ASSERT( !test_str_contains( g_out.str(), "test_fileline_function"));
+ g_out.str("");
+
+ g_l->writer().add_formatter( formatter::tag::module(), "[%] " );
+ g_l->writer().add_formatter( formatter::tag::thread_id(), "[%] " );
+}
+
+void test_module_and_thread_id() {
+ init_logs_module_thread_id();
+
+ std::ostringstream out;
+ out << detail::get_thread_id();
+ std::string thread_id = out.str();
+
+ LOG_MODULE_("module_a") << g_msg;
+ BOOST_ASSERT( test_str_contains( g_out.str(), "[module_a]"));
+ BOOST_ASSERT( test_str_contains( g_out.str(), "[" + thread_id + "]"));
+}
+
+int main() {
+ test_fileline_function();
+ test_module_and_thread_id();
+}
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk