Boost logo

Boost-Commit :

From: john.groups_at_[hidden]
Date: 2007-10-30 06:24:56


Author: jtorjo
Date: 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
New Revision: 40601
URL: http://svn.boost.org/trac/boost/changeset/40601

Log:
[logging]
put the old tests in a "donot_use" directory, to clearly show they're not meant to be used by users
Added:
   sandbox/logging/lib/logging/tests/donot_use/
   sandbox/logging/lib/logging/tests/donot_use/format/
   sandbox/logging/lib/logging/tests/donot_use/format/test_format_write_ts.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/format/test_manip_being_func.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/format/test_manip_w_msgroute.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/format/test_simple_formatter.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/readme1st.txt (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/template.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/test_mul_lev_difflogs.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/test_mul_lev_samelog.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/test_multiple_simple_logs.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/test_ostream_like.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/test_simple_dump_to_cout.cpp (contents, props changed)
   sandbox/logging/lib/logging/tests/donot_use/testfast.cpp (contents, props changed)
Removed:
   sandbox/logging/lib/logging/tests/format/
   sandbox/logging/lib/logging/tests/obsolete.txt
   sandbox/logging/lib/logging/tests/template.cpp
   sandbox/logging/lib/logging/tests/test_mul_lev_difflogs.cpp
   sandbox/logging/lib/logging/tests/test_mul_lev_samelog.cpp
   sandbox/logging/lib/logging/tests/test_multiple_simple_logs.cpp
   sandbox/logging/lib/logging/tests/test_ostream_like.cpp
   sandbox/logging/lib/logging/tests/test_simple_dump_to_cout.cpp
   sandbox/logging/lib/logging/tests/testfast.cpp
Text files modified:
   sandbox/logging/boost/logging/detail/raw_doc/common_usage_steps_fd.hpp | 2 +-
   1 files changed, 1 insertions(+), 1 deletions(-)

Modified: sandbox/logging/boost/logging/detail/raw_doc/common_usage_steps_fd.hpp
==============================================================================
--- sandbox/logging/boost/logging/detail/raw_doc/common_usage_steps_fd.hpp (original)
+++ sandbox/logging/boost/logging/detail/raw_doc/common_usage_steps_fd.hpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -4,7 +4,7 @@
 @page common_usage_steps_fd Common steps when using Formatters and destinations
 
 The usual steps when using the Boost Logging Lib are:
-- Step 1: (optional) Specify your format and/or message class. By default, it's @c std::(w)string.
+- Step 1: (optional) Specify your format and/or message class. By default, it's <tt>std::(w)string</tt>.
   You'll use this when you want an @ref "optimize string class".
 - Step 2: (optional) Specify your @ref boost::logging::manipulator "formatter & destination base classes"
 - Step 3: Specify your logger class(es)

Added: sandbox/logging/lib/logging/tests/donot_use/format/test_format_write_ts.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/format/test_format_write_ts.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,46 @@
+// test_format_write_ts.cpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#include <boost/logging/logging.hpp>
+#include <boost/logging/format/optimize.hpp>
+#include <boost/logging/process_msg/ostream_like.hpp>
+#include <boost/logging/format.hpp>
+#include <sstream>
+#include <boost/shared_ptr.hpp>
+#include <time.h>
+#include <iostream>
+#include <fstream>
+#include <boost/logging/writer/on_dedicated_thread.hpp>
+
+using namespace boost::logging;
+
+typedef optimize::cache_string_one_str<> cache_string;
+typedef destination::base<const std::string &, op_equal::same_type> destination_base;
+
+
+void test_format_write_ts() {
+}
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_format_write_ts();
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/format/test_manip_being_func.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/format/test_manip_being_func.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,38 @@
+// test_manipulator_being_func.cpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#include <boost/logging/logging.hpp>
+
+/**
+ Tests formatters and destinations being functions. In this case, calling them won't involve a virtual function call.
+*/
+
+using namespace boost::logging;
+
+
+void test_manipulator_being_func() {
+}
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_manipulator_being_func();
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/format/test_manip_w_msgroute.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/format/test_manip_w_msgroute.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,182 @@
+// test_manipulator_with_msg_route.cpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#include <boost/logging/logging.hpp>
+#include <boost/logging/format/optimize.hpp>
+#include <boost/logging/process_msg/ostream_like.hpp>
+#include <boost/logging/format.hpp>
+#include <sstream>
+#include <boost/shared_ptr.hpp>
+#include <time.h>
+#include <iostream>
+#include <fstream>
+
+
+using namespace boost::logging;
+
+/*
+ Using formatters/destinations.
+
+ Always, in your applications, all formatters need to have a common base class. Same for destinations.
+
+ This calls the formatters/destinations in a specific way - specified by a "route"
+ (class boost::logging::msg_route::with_route)
+
+ The simple router just calls all formatters, and then all destinations.
+ However, with the with_route router, you can specify how they're called.
+
+ In our example:
+
+ to cout: [idx] [time] message [enter]
+ to dbg_window: [time] message [enter]
+ to file: message [enter]
+
+ So our route is:
+
+ prepend [time]
+ append [enter]
+ to dbg window
+ prepend [idx]
+ to cout
+ clear format
+ append [enter]
+ to file
+*/
+typedef optimize::cache_string_one_str<> cache_string;
+
+
+//////////////////////////////////////////////////////////////////////
+// Formatters
+
+typedef formatter::base<cache_string&> format_base;
+
+// formatter: prepend the message's index
+struct write_idx : format_base, formatter::non_const_context<int> {
+ write_idx() : non_const_context_base((int)0) {}
+ void operator()(param str) const {
+ std::stringstream idx;
+ idx << "[" << ++context() << "] ";
+ str.prepend_string( idx.str() );
+ }
+};
+
+struct write_time : format_base {
+ void operator()(cache_string & str) const {
+ char t[10];
+ time_t now = time(0);
+ tm details = *localtime(&now);
+ strftime(t, 10, "%M:%S ", &details);
+ str.prepend_string(t);
+ }
+};
+
+struct append_enter : format_base {
+ void operator()(cache_string & str) const {
+ str.append_string("\n");
+ }
+};
+
+//////////////////////////////////////////////////////////////////////
+// Destinations
+
+typedef destination::base<const std::string &> destination_base;
+
+struct write_to_cout : destination_base {
+ void operator()(param msg) const {
+ std::cout << msg ;
+ }
+};
+
+struct write_to_dbg : destination_base {
+ void operator()(param msg) const {
+#ifdef BOOST_WINDOWS
+ ::OutputDebugStringA( msg.c_str() );
+#else
+ msg; // so that there's no warning
+#endif
+ }
+};
+
+struct write_to_file : destination_base, destination::non_const_context<std::ofstream> {
+ write_to_file() : non_const_context_base("out.txt") {}
+ void operator()(param msg) const {
+ context() << msg ;
+ }
+};
+
+typedef process_msg<
+ gather::ostream_like::return_cache_str<> ,
+ writer::format_write<
+ format_base,
+ destination_base,
+ format_and_write::simple_care_for_clear_format<cache_string>,
+ msg_route::with_route<format_base,destination_base> > > process;
+logger<process, filter::no_ts> g_l;
+
+#define L_ if ( !g_l) ; else g_l->read_msg().gather().out()
+
+
+
+void test_manipulator_with_msg_route() {
+ g_l->writer().add_formatter( write_time() );
+ g_l->writer().add_formatter( write_idx() );
+ g_l->writer().add_formatter( append_enter() );
+
+ g_l->writer().add_destination( write_to_cout() );
+ g_l->writer().add_destination( write_to_dbg() );
+ g_l->writer().add_destination( write_to_file() );
+
+ /*
+ prepend [time]
+ append [enter]
+ to dbg window
+ prepend [idx]
+ to cout
+ clear format
+ prepend [idx]
+ append [enter]
+ to file
+ */
+ g_l->writer().router().set_route()
+ .fmt( write_time() )
+ .fmt( append_enter() )
+ .dest( write_to_dbg() )
+ .fmt( write_idx() )
+ .dest( write_to_cout() )
+ .clear()
+ .fmt( append_enter() )
+ .dest( write_to_file())
+ ;
+
+ int i = 1;
+ L_ << "good to use " << i++ << " version";
+ L_ << "Boost Logging lib v" << i++;
+}
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_manipulator_with_msg_route();
+
+
+
+
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/format/test_simple_formatter.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/format/test_simple_formatter.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,143 @@
+// test_simple_format_and_write_simple_formatter.cpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#include <boost/logging/logging.hpp>
+#include <boost/logging/format/optimize.hpp>
+#include <boost/logging/process_msg/ostream_like.hpp>
+#include <boost/logging/format.hpp>
+#include <sstream>
+#include <boost/shared_ptr.hpp>
+#include <time.h>
+#include <iostream>
+#include <fstream>
+
+using namespace boost::logging;
+
+/*
+ Using simple formatters/destinations.
+ Also, using the simple router: which just calls all formatters, and then all destinations.
+
+ Always, in your applications, all formatters need to have a common base class. Same for destinations.
+
+ Other than that, you can choose your "string" type, and then implement operator().
+
+ Note that here, for formatters, I'm using cache_string - which optimizes formatting the strings.
+
+ Also, I'm adding formatters/destinations, and at a later time, I'm removing some - thus, when logging,
+ we won't call the deleted formatters/destinations.
+
+
+
+ IMPORTANT:
+ In this example, I'm creating my own formatter classes. To see me use default formatters, try another example FIXME
+*/
+
+typedef optimize::cache_string_one_str<> cache_string;
+
+
+//////////////////////////////////////////////////////////////////////
+// Formatters
+
+typedef formatter::base<cache_string&> format_base;
+
+// formatter: prepend the message's index
+struct write_idx : formatter::class_<write_idx, format_base, op_equal_no_context>, formatter::non_const_context<int> {
+ write_idx() : non_const_context_base((int)0) {}
+ void operator()(param str) const {
+ std::stringstream idx;
+ idx << "[" << ++context() << "] ";
+ str.prepend_string( idx.str() );
+ }
+};
+
+struct write_time : formatter::class_<write_time, format_base, op_equal_no_context> {
+ void operator()(cache_string & str) const {
+ char t[10];
+ time_t now = time(0);
+ tm details = *localtime(&now);
+ strftime(t, 10, "%M:%S ", &details);
+ str.prepend_string(t);
+ }
+};
+
+struct append_enter : formatter::class_<append_enter, format_base, op_equal_no_context> {
+ void operator()(cache_string & str) const {
+ str.append_string("\n");
+ }
+};
+
+//////////////////////////////////////////////////////////////////////
+// Destinations
+
+typedef destination::base<const std::string &> destination_base;
+
+struct write_to_cout : destination::class_<write_to_cout, destination_base, op_equal_no_context> {
+ void operator()(param msg) const {
+ std::cout << msg ;
+ }
+};
+
+struct write_to_file : destination::class_<write_to_file, destination_base, op_equal_no_context>, destination::non_const_context<std::ofstream> {
+ write_to_file(const char* filename) : non_const_context_base(filename) {}
+ void operator()(param msg) const {
+ context() << msg ;
+ }
+};
+
+typedef process_msg<
+ gather::ostream_like::return_cache_str<> ,
+ writer::format_write<
+ format_base,
+ destination_base, format_and_write::simple<cache_string> > > process;
+logger<process, filter::no_ts> g_l;
+
+#define L_ if ( !g_l) ; else g_l->read_msg().gather().out()
+
+
+void test_simple_format_and_write_simple_formatter() {
+ // add formatters : [idx] [time] message [enter]
+ g_l->writer().add_formatter( write_idx() );
+ g_l->writer().add_formatter( write_time() );
+ g_l->writer().add_formatter( append_enter() );
+
+ // write to cout and file
+ g_l->writer().add_destination( write_to_cout() );
+ g_l->writer().add_destination( write_to_file("out.txt") );
+
+ int i = 1;
+ L_ << "this is so cool" << i++;
+ L_ << "must be prefixed by index and time , enter is appended as well " << i++;
+ L_ << "must be prefixed by index and time , enter is appended as well " << i++;
+
+ g_l->writer().del_formatter( write_idx() );
+ g_l->writer().del_formatter( append_enter() );
+ g_l->writer().del_destination( write_to_cout() );
+
+ // will not be written to cout
+ L_ << "must be prefixed by time , no enter " << i++ << ";";
+ L_ << "must be prefixed by time , no enter " << i++ << ";";
+}
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_simple_format_and_write_simple_formatter();
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/readme1st.txt
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/readme1st.txt 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,6 @@
+
+Note: the tests here are OBSOLETE.
+Please disregard them.
+
+Take a look at scenarios though. They are correct.
+

Added: sandbox/logging/lib/logging/tests/donot_use/template.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/template.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,32 @@
+// test_Template.hpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+#include <boost/logging/logging.hpp>
+
+using namespace boost::logging;
+
+void test_template() {
+}
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_template();
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/test_mul_lev_difflogs.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/test_mul_lev_difflogs.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,118 @@
+// test_multiple_levels_different_logs.cpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#include <boost/logging/logging.hpp>
+#include <boost/logging/level.hpp>
+#include <boost/logging/process_msg/ostream_like.hpp>
+#include <boost/shared_ptr.hpp>
+#include <fstream>
+#include <iostream>
+
+using namespace boost::logging;
+
+/*
+ Tests levels - having multiple levels, but all messages go to the same log
+
+ By default we have these levels:
+
+ info (smallest level),
+ warning ,
+ debug ,
+ error ,
+ fatal (highest level)
+
+ Depending which level is enabled, some messages will reach the log: those messages having at least that level.
+ For instance, if info level is enabled, all logged messages will reach the log.
+ If warning level is enabled, all messages are logged, but the warnings.
+ If debug level is enabled, messages that have levels debug, error, fatal will be logged.
+
+
+ To see the difference between having multiple levels and logging to the same log destination,
+ or different log destinations, see test_multiple_levels_to_same_log.cpp
+*/
+
+using namespace boost::logging;
+
+struct write_to_file {
+ typedef boost::shared_ptr<std::ofstream> ptr;
+
+ write_to_file(const std::string & filename) : m_out(new std::ofstream(filename.c_str())) {}
+ void operator()(const std::string & msg) const {
+ (*m_out) << msg << std::endl ;
+ }
+
+ // Always, when you need to hold some context in your writer object, you need to hold
+ // it as a shared pointer - this is because multiple copies of the same object might exist at the same time
+ mutable ptr m_out;
+};
+
+typedef process_msg< gather::ostream_like::return_str<>, write_to_file> processor;
+
+level::holder_no_ts level_holder;
+
+typedef logger<processor, filter_level<level::holder_no_ts, level::debug> > debug_logger;
+typedef logger<processor, filter_level<level::holder_no_ts, level::error> > error_logger;
+typedef logger<processor, filter_level<level::holder_no_ts, level::info> > info_logger;
+
+debug_logger g_log_dbg( init_both, "dbg.txt", &level_holder );
+error_logger g_log_err( init_both, "err.txt", &level_holder );
+info_logger g_log_app( init_both, "out.txt", &level_holder );
+
+
+#define LAPP_ if ( !g_log_app) ; else g_log_app->read_msg().gather().out()
+#define LERR_ if ( !g_log_err) ; else g_log_err->read_msg().gather().out()
+#define LDBG_ if ( !g_log_dbg) ; else g_log_dbg->read_msg().gather().out()
+
+void test_multiple_levels_different_logs() {
+ // read from a file, dump it word by word
+ std::ifstream in("readme.txt");
+ std::string word;
+
+ // at this time, print everything
+ level_holder.set_enabled(level::info);
+
+ // when reaching these many words, we toggle the log level (enable/disabling some of the log messages)
+ int toggle_count = 10;
+
+ int idx = 1;
+ int idx_toggle_level = 0;
+ for ( ; in >> word; ++idx) {
+ LAPP_ << "info at : " << idx << " : reading word " << word;
+ LDBG_ << "debug at: " << idx << ", reading " << word;
+ LERR_ << "error at: " << idx << ", while reading " << word;
+
+ if ( idx % toggle_count == 0) {
+ // toggle the logs
+ switch ( ++idx_toggle_level % 4) {
+ case 0: level_holder.set_enabled(level::info); break;
+ case 1: level_holder.set_enabled(level::debug); break;
+ case 2: level_holder.set_enabled(level::error); break;
+ case 3: level_holder.set_enabled(level::fatal); break;
+ }
+ }
+ }
+}
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_multiple_levels_different_logs();
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/test_mul_lev_samelog.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/test_mul_lev_samelog.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,126 @@
+// test_multiple_levels_same_log.cpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#include <boost/logging/logging.hpp>
+#include <boost/logging/level.hpp>
+#include <boost/logging/process_msg/ostream_like.hpp>
+#include <boost/shared_ptr.hpp>
+#include <fstream>
+#include <iostream>
+
+/*
+ Tests levels - having multiple levels, but all messages go to the same log
+
+ By default we have these levels:
+
+ info (smallest level),
+ warning ,
+ debug ,
+ error ,
+ fatal (highest level)
+
+ Depending which level is enabled, some messages will reach the log: those messages having at least that level.
+ For instance, if info level is enabled, all logged messages will reach the log.
+ If warning level is enabled, all messages are logged, but the warnings.
+ If debug level is enabled, messages that have levels debug, error, fatal will be logged.
+
+
+ To see the difference between having multiple levels and logging to the same log destination,
+ or different log destinations, see test_multiple_levels_to_different_logs.cpp
+*/
+
+using namespace boost::logging;
+
+struct write_to_file {
+ typedef boost::shared_ptr<std::ofstream> ptr;
+
+ write_to_file(const std::string & filename) : m_out(new std::ofstream(filename.c_str())) {}
+ void operator()(const std::string & msg) const {
+ (*m_out) << msg << std::endl ;
+ }
+
+ // Always, when you need to hold some context in your writer object, you need to hold
+ // it as a shared pointer - this is because multiple copies of the same object might exist at the same time
+ mutable ptr m_out;
+};
+
+typedef process_msg< gather::ostream_like::return_str<>, write_to_file> processor;
+
+level::holder_no_ts level_holder;
+/*
+ VERY IMPORTANT: if we plan to write to the same destination, we need to share this:
+ write_to_file writer("out.txt");
+
+ Having 3 separate copies will simply open 3 iostream files on the same file, and that is not
+ guaranteed to work (for instance, the first instance might succeed, while the other 2 would
+ just get 2 invalid streams).
+*/
+write_to_file file_writer("out.txt");
+
+typedef logger<processor, filter_level<level::holder_no_ts, level::debug> > debug_logger;
+typedef logger<processor, filter_level<level::holder_no_ts, level::error> > error_logger;
+typedef logger<processor, filter_level<level::holder_no_ts, level::info> > info_logger;
+
+debug_logger g_log_dbg( init_both, file_writer, &level_holder );
+error_logger g_log_err( init_both, file_writer, &level_holder );
+info_logger g_log_app( init_both, file_writer, &level_holder );
+
+
+#define LAPP_ if ( !g_log_app) ; else g_log_app->read_msg().gather().out()
+#define LERR_ if ( !g_log_err) ; else g_log_err->read_msg().gather().out()
+#define LDBG_ if ( !g_log_dbg) ; else g_log_dbg->read_msg().gather().out()
+
+
+void test_multiple_levels_same_log() {
+ // read from a file, dump it word by word
+ std::ifstream in("readme.txt");
+ std::string word;
+
+ // at this time, print everything
+ level_holder.set_enabled(level::info);
+
+ // when reaching these many words, we toggle the log level (enable/disabling some of the log messages)
+ int toggle_count = 10;
+
+ int idx = 1;
+ int idx_toggle_level = 0;
+ for ( ; in >> word; ++idx) {
+ LAPP_ << "info at :" << idx << " : reading word " << word;
+ LDBG_ << " debug at : " << idx << ", reading " << word;
+ LERR_ << " error at: " << idx << ", while reading " << word;
+
+ if ( idx % toggle_count == 0) {
+ // toggle the logs
+ switch ( ++idx_toggle_level % 4) {
+ case 0: level_holder.set_enabled(level::info); break;
+ case 1: level_holder.set_enabled(level::debug); break;
+ case 2: level_holder.set_enabled(level::error); break;
+ case 3: level_holder.set_enabled(level::fatal); break;
+ }
+ }
+ }
+}
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_multiple_levels_same_log();
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/test_multiple_simple_logs.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/test_multiple_simple_logs.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,102 @@
+// test_multiple_simple_logs.cpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#include <boost/logging/logging.hpp>
+#include <boost/logging/process_msg/ostream_like.hpp>
+#include <boost/shared_ptr.hpp>
+#include <fstream>
+#include <iostream>
+
+using namespace boost::logging;
+
+struct write_to_file {
+ typedef boost::shared_ptr<std::ofstream> ptr;
+
+ write_to_file(const std::string & filename) : m_out(new std::ofstream(filename.c_str())) {}
+ void operator()(const std::string & msg) const {
+ (*m_out) << msg << std::endl ;
+ }
+
+ // Always, when you need to hold some context in your writer object, you need to hold
+ // it as a shared pointer - this is because multiple copies of the same object might exist at the same time
+ mutable ptr m_out;
+};
+
+struct write_to_cout {
+ void operator()(const std::string & msg) const {
+ std::cout << msg << std::endl ;
+ }
+};
+
+struct write_to_dbg {
+ void operator()(const std::string & msg) const {
+#ifdef BOOST_WINDOWS
+ ::OutputDebugStringA( (msg + "\n").c_str() );
+#else
+ msg; // so that there's no warning
+#endif
+ }
+};
+
+typedef process_msg< gather::ostream_like::return_str<>, write_to_cout> processor_cout;
+typedef process_msg< gather::ostream_like::return_str<>, write_to_file> processor_file;
+typedef process_msg< gather::ostream_like::return_str<>, write_to_dbg> processor_dbg;
+
+logger<processor_cout, filter::no_ts> g_log_app;
+logger<processor_file, filter::no_ts> g_log_err("err.txt");
+logger<processor_dbg, filter::no_ts> g_log_dbg;
+
+#define LAPP_ if ( !g_log_app) ; else g_log_app->read_msg().gather().out()
+#define LERR_ if ( !g_log_err) ; else g_log_err->read_msg().gather().out()
+#define LDBG_ if ( !g_log_dbg) ; else g_log_dbg->read_msg().gather().out()
+
+
+void test_multiple_simple_logs() {
+ // read from a file, dump it word by word
+ std::ifstream in("readme.txt");
+ std::string word;
+
+ g_log_err.set_enabled(false);
+
+ // when reaching these many words, we toggle the logs (enable/disable them)
+ int toggle_count = 20;
+
+ int idx = 1;
+ for ( ; in >> word; ++idx) {
+ LAPP_ << idx << " : reading word " << word;
+ LERR_ << "error at " << idx << ", while reading " << word;
+ LDBG_ << "debug info: " << idx << ", reading " << word;
+
+
+ if ( idx % toggle_count == 0) {
+ // toggle the logs
+ g_log_app.set_enabled( !g_log_app.is_enabled() );
+ g_log_err.set_enabled( !g_log_err.is_enabled() );
+ g_log_dbg.set_enabled( !g_log_dbg.is_enabled() );
+ }
+ }
+}
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_multiple_simple_logs();
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/test_ostream_like.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/test_ostream_like.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,78 @@
+// test_dump_to_file_and_cout_ostream_like.cpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#include <boost/logging/logging.hpp>
+#include <boost/logging/process_msg/ostream_like.hpp>
+#include <fstream>
+#include <iostream>
+#include <boost/shared_ptr.hpp>
+
+using namespace boost::logging;
+
+/*
+ Dump to both cout and file, using the cool "<<" operator.
+
+ Note that writing to the log is totally decoupled from the logging syntax ,
+ while being efficient (if the log is disabled, we don't compute anything related to the message).
+*/
+
+struct write_to_cout_and_file {
+ typedef boost::shared_ptr<std::ofstream> ptr;
+
+ write_to_cout_and_file(const std::string & filename) : m_out(new std::ofstream(filename.c_str())) {}
+ void operator()(const std::string & msg) const {
+ std::cout << msg << std::endl ;
+ (*m_out) << msg << std::endl ;
+ }
+
+ // Always, when you need to hold some context in your writer object, you need to hold
+ // it as a shared pointer - this is because multiple copies of the same object might exist at the same time
+ mutable ptr m_out;
+};
+
+typedef process_msg< gather::ostream_like::return_str<>, write_to_cout_and_file> processor;
+logger<processor, filter::no_ts> g_single_log("out.txt");
+
+#define L_ if ( !g_single_log) ; else g_single_log->read_msg().gather().out()
+
+
+void test_dump_to_file_and_cout_ostream_like() {
+ // read from a file, dump it word by word
+ std::ifstream in("readme.txt");
+ std::string word;
+
+ // when reaching these many words, we toggle the log (enable/disable it)
+ int toggle_count = 20;
+
+ int idx = 1;
+ for ( ; in >> word; ++idx) {
+ L_ << idx << " : reading word " << word;
+
+ if ( idx % toggle_count == 0)
+ g_single_log.set_enabled( !g_single_log.is_enabled() ); // toggle the log
+ }
+}
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_dump_to_file_and_cout_ostream_like();
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/test_simple_dump_to_cout.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/test_simple_dump_to_cout.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,73 @@
+// simple_dump_to_cout.cpp
+
+// Boost Logging library
+//
+// Author: John Torjo, www.torjo.com
+//
+// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
+//
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org for updates, documentation, and revision history.
+// See http://www.torjo.com/log2/ for more details
+
+
+#include <boost/logging/logging.hpp>
+#include <iostream>
+#include <fstream>
+
+/*
+ As simple as it gets: Have a simple non-thread safe logger (filter::no_ts),
+ and if the log is enabled, dump to cout.
+
+ We log full messages, no using any "<<" when doing logging. That is,
+ we do this:
+ L_("my message")
+
+ not:
+ L_ << "my message comes from user " << user << ", with greetings"
+*/
+
+struct write_to_cout {
+ void operator()(const std::string & msg) const {
+ std::cout << msg << std::endl ;
+ }
+};
+
+using namespace boost::logging;
+logger<write_to_cout, filter::no_ts> g_single_log;
+
+// FIXME i need to create a macro for "if ( sink<write_to_cout> s = g_single_log) s.process_msg()"
+#define L_(x) if ( g_single_log) g_single_log.process_msg()(x)
+
+
+void test_simple_dump_to_cout() {
+ // read from a file, dump it word by word
+ std::ifstream in("readme.txt");
+ std::string word;
+
+ // we allow only this many words
+ int allow_word_count = 100;
+
+ int idx = 0;
+ for ( ; in >> word; ++idx)
+ if ( idx < allow_word_count )
+ L_("reading word " + word);
+ else if ( idx == allow_word_count )
+ // disable the log
+ g_single_log.set_enabled(false);
+}
+
+
+#ifdef SINGLE_TEST
+
+int main() {
+ test_simple_dump_to_cout();
+}
+
+#endif
+
+// End of file
+

Added: sandbox/logging/lib/logging/tests/donot_use/testfast.cpp
==============================================================================
--- (empty file)
+++ sandbox/logging/lib/logging/tests/donot_use/testfast.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
@@ -0,0 +1,67 @@
+
+#define BOOST_LOG_COMPILE_FAST_ON
+#include <boost/logging/format_fwd.hpp>
+
+// Step 1: Optimize : use a cache string, to make formatting the message faster
+BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
+
+#include <boost/logging/format.hpp>
+
+using namespace boost::logging;
+
+// Step 3 : Specify your logging class(es)
+typedef logger_format_write< > log_type;
+
+BOOST_DECLARE_LOG(g_l, log_type)
+
+
+// Step 4: declare which filters and loggers you'll use (usually in a header file)
+BOOST_DECLARE_LOG_FILTER(g_log_filter, filter::no_ts )
+BOOST_DECLARE_LOG(g_l, log_type)
+
+// Step 5: define the macros through which you'll log
+#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l, g_log_filter->is_enabled() )
+
+
+void one_logger_one_filter_example() {
+ // Step 7: add formatters and destinations
+ // That is, how the message is to be formatted and where should it be written to
+
+ g_l->writer().add_formatter( formatter::idx() );
+ g_l->writer().add_formatter( formatter::append_enter() );
+ g_l->writer().add_destination( destination::file("out.txt") );
+ g_l->writer().add_destination( destination::cout() );
+ g_l->writer().add_destination( destination::dbg_window() );
+
+ // Step 8: use it...
+ int i = 1;
+ L_ << "this is so cool " << i++;
+ L_ << "this is so cool again " << i++;
+
+ std::string hello = "hello", world = "world";
+ L_ << hello << ", " << world;
+
+ g_log_filter->set_enabled(false);
+ L_ << "this will not be written to the log";
+ L_ << "this won't be written to the log";
+
+ g_log_filter->set_enabled(true);
+ L_ << "good to be back ;) " << i++;
+}
+
+
+
+#ifdef SINGLE_TEST
+
+int main() {
+ one_logger_one_filter_example();
+}
+
+#endif
+
+// End of file
+
+// Step 6: Define the filters and loggers you'll use (usually in a source file)
+BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
+BOOST_DEFINE_LOG(g_l, log_type)
+

Deleted: sandbox/logging/lib/logging/tests/obsolete.txt
==============================================================================
--- sandbox/logging/lib/logging/tests/obsolete.txt 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
+++ (empty file)
@@ -1,2 +0,0 @@
-Note: the tests here are obsolete.
-Please disregard them

Deleted: sandbox/logging/lib/logging/tests/template.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/template.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
+++ (empty file)
@@ -1,32 +0,0 @@
-// test_Template.hpp
-
-// Boost Logging library
-//
-// Author: John Torjo, www.torjo.com
-//
-// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
-//
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// See http://www.boost.org for updates, documentation, and revision history.
-// See http://www.torjo.com/log2/ for more details
-
-#include <boost/logging/logging.hpp>
-
-using namespace boost::logging;
-
-void test_template() {
-}
-
-#ifdef SINGLE_TEST
-
-int main() {
- test_template();
-}
-
-#endif
-
-// End of file
-

Deleted: sandbox/logging/lib/logging/tests/test_mul_lev_difflogs.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/test_mul_lev_difflogs.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
+++ (empty file)
@@ -1,118 +0,0 @@
-// test_multiple_levels_different_logs.cpp
-
-// Boost Logging library
-//
-// Author: John Torjo, www.torjo.com
-//
-// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
-//
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// See http://www.boost.org for updates, documentation, and revision history.
-// See http://www.torjo.com/log2/ for more details
-
-
-#include <boost/logging/logging.hpp>
-#include <boost/logging/level.hpp>
-#include <boost/logging/process_msg/ostream_like.hpp>
-#include <boost/shared_ptr.hpp>
-#include <fstream>
-#include <iostream>
-
-using namespace boost::logging;
-
-/*
- Tests levels - having multiple levels, but all messages go to the same log
-
- By default we have these levels:
-
- info (smallest level),
- warning ,
- debug ,
- error ,
- fatal (highest level)
-
- Depending which level is enabled, some messages will reach the log: those messages having at least that level.
- For instance, if info level is enabled, all logged messages will reach the log.
- If warning level is enabled, all messages are logged, but the warnings.
- If debug level is enabled, messages that have levels debug, error, fatal will be logged.
-
-
- To see the difference between having multiple levels and logging to the same log destination,
- or different log destinations, see test_multiple_levels_to_same_log.cpp
-*/
-
-using namespace boost::logging;
-
-struct write_to_file {
- typedef boost::shared_ptr<std::ofstream> ptr;
-
- write_to_file(const std::string & filename) : m_out(new std::ofstream(filename.c_str())) {}
- void operator()(const std::string & msg) const {
- (*m_out) << msg << std::endl ;
- }
-
- // Always, when you need to hold some context in your writer object, you need to hold
- // it as a shared pointer - this is because multiple copies of the same object might exist at the same time
- mutable ptr m_out;
-};
-
-typedef process_msg< gather::ostream_like::return_str<>, write_to_file> processor;
-
-level::holder_no_ts level_holder;
-
-typedef logger<processor, filter_level<level::holder_no_ts, level::debug> > debug_logger;
-typedef logger<processor, filter_level<level::holder_no_ts, level::error> > error_logger;
-typedef logger<processor, filter_level<level::holder_no_ts, level::info> > info_logger;
-
-debug_logger g_log_dbg( init_both, "dbg.txt", &level_holder );
-error_logger g_log_err( init_both, "err.txt", &level_holder );
-info_logger g_log_app( init_both, "out.txt", &level_holder );
-
-
-#define LAPP_ if ( !g_log_app) ; else g_log_app->read_msg().gather().out()
-#define LERR_ if ( !g_log_err) ; else g_log_err->read_msg().gather().out()
-#define LDBG_ if ( !g_log_dbg) ; else g_log_dbg->read_msg().gather().out()
-
-void test_multiple_levels_different_logs() {
- // read from a file, dump it word by word
- std::ifstream in("readme.txt");
- std::string word;
-
- // at this time, print everything
- level_holder.set_enabled(level::info);
-
- // when reaching these many words, we toggle the log level (enable/disabling some of the log messages)
- int toggle_count = 10;
-
- int idx = 1;
- int idx_toggle_level = 0;
- for ( ; in >> word; ++idx) {
- LAPP_ << "info at : " << idx << " : reading word " << word;
- LDBG_ << "debug at: " << idx << ", reading " << word;
- LERR_ << "error at: " << idx << ", while reading " << word;
-
- if ( idx % toggle_count == 0) {
- // toggle the logs
- switch ( ++idx_toggle_level % 4) {
- case 0: level_holder.set_enabled(level::info); break;
- case 1: level_holder.set_enabled(level::debug); break;
- case 2: level_holder.set_enabled(level::error); break;
- case 3: level_holder.set_enabled(level::fatal); break;
- }
- }
- }
-}
-
-#ifdef SINGLE_TEST
-
-int main() {
- test_multiple_levels_different_logs();
-}
-
-#endif
-
-// End of file
-

Deleted: sandbox/logging/lib/logging/tests/test_mul_lev_samelog.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/test_mul_lev_samelog.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
+++ (empty file)
@@ -1,126 +0,0 @@
-// test_multiple_levels_same_log.cpp
-
-// Boost Logging library
-//
-// Author: John Torjo, www.torjo.com
-//
-// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
-//
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// See http://www.boost.org for updates, documentation, and revision history.
-// See http://www.torjo.com/log2/ for more details
-
-
-#include <boost/logging/logging.hpp>
-#include <boost/logging/level.hpp>
-#include <boost/logging/process_msg/ostream_like.hpp>
-#include <boost/shared_ptr.hpp>
-#include <fstream>
-#include <iostream>
-
-/*
- Tests levels - having multiple levels, but all messages go to the same log
-
- By default we have these levels:
-
- info (smallest level),
- warning ,
- debug ,
- error ,
- fatal (highest level)
-
- Depending which level is enabled, some messages will reach the log: those messages having at least that level.
- For instance, if info level is enabled, all logged messages will reach the log.
- If warning level is enabled, all messages are logged, but the warnings.
- If debug level is enabled, messages that have levels debug, error, fatal will be logged.
-
-
- To see the difference between having multiple levels and logging to the same log destination,
- or different log destinations, see test_multiple_levels_to_different_logs.cpp
-*/
-
-using namespace boost::logging;
-
-struct write_to_file {
- typedef boost::shared_ptr<std::ofstream> ptr;
-
- write_to_file(const std::string & filename) : m_out(new std::ofstream(filename.c_str())) {}
- void operator()(const std::string & msg) const {
- (*m_out) << msg << std::endl ;
- }
-
- // Always, when you need to hold some context in your writer object, you need to hold
- // it as a shared pointer - this is because multiple copies of the same object might exist at the same time
- mutable ptr m_out;
-};
-
-typedef process_msg< gather::ostream_like::return_str<>, write_to_file> processor;
-
-level::holder_no_ts level_holder;
-/*
- VERY IMPORTANT: if we plan to write to the same destination, we need to share this:
- write_to_file writer("out.txt");
-
- Having 3 separate copies will simply open 3 iostream files on the same file, and that is not
- guaranteed to work (for instance, the first instance might succeed, while the other 2 would
- just get 2 invalid streams).
-*/
-write_to_file file_writer("out.txt");
-
-typedef logger<processor, filter_level<level::holder_no_ts, level::debug> > debug_logger;
-typedef logger<processor, filter_level<level::holder_no_ts, level::error> > error_logger;
-typedef logger<processor, filter_level<level::holder_no_ts, level::info> > info_logger;
-
-debug_logger g_log_dbg( init_both, file_writer, &level_holder );
-error_logger g_log_err( init_both, file_writer, &level_holder );
-info_logger g_log_app( init_both, file_writer, &level_holder );
-
-
-#define LAPP_ if ( !g_log_app) ; else g_log_app->read_msg().gather().out()
-#define LERR_ if ( !g_log_err) ; else g_log_err->read_msg().gather().out()
-#define LDBG_ if ( !g_log_dbg) ; else g_log_dbg->read_msg().gather().out()
-
-
-void test_multiple_levels_same_log() {
- // read from a file, dump it word by word
- std::ifstream in("readme.txt");
- std::string word;
-
- // at this time, print everything
- level_holder.set_enabled(level::info);
-
- // when reaching these many words, we toggle the log level (enable/disabling some of the log messages)
- int toggle_count = 10;
-
- int idx = 1;
- int idx_toggle_level = 0;
- for ( ; in >> word; ++idx) {
- LAPP_ << "info at :" << idx << " : reading word " << word;
- LDBG_ << " debug at : " << idx << ", reading " << word;
- LERR_ << " error at: " << idx << ", while reading " << word;
-
- if ( idx % toggle_count == 0) {
- // toggle the logs
- switch ( ++idx_toggle_level % 4) {
- case 0: level_holder.set_enabled(level::info); break;
- case 1: level_holder.set_enabled(level::debug); break;
- case 2: level_holder.set_enabled(level::error); break;
- case 3: level_holder.set_enabled(level::fatal); break;
- }
- }
- }
-}
-
-#ifdef SINGLE_TEST
-
-int main() {
- test_multiple_levels_same_log();
-}
-
-#endif
-
-// End of file
-

Deleted: sandbox/logging/lib/logging/tests/test_multiple_simple_logs.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/test_multiple_simple_logs.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
+++ (empty file)
@@ -1,102 +0,0 @@
-// test_multiple_simple_logs.cpp
-
-// Boost Logging library
-//
-// Author: John Torjo, www.torjo.com
-//
-// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
-//
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// See http://www.boost.org for updates, documentation, and revision history.
-// See http://www.torjo.com/log2/ for more details
-
-
-#include <boost/logging/logging.hpp>
-#include <boost/logging/process_msg/ostream_like.hpp>
-#include <boost/shared_ptr.hpp>
-#include <fstream>
-#include <iostream>
-
-using namespace boost::logging;
-
-struct write_to_file {
- typedef boost::shared_ptr<std::ofstream> ptr;
-
- write_to_file(const std::string & filename) : m_out(new std::ofstream(filename.c_str())) {}
- void operator()(const std::string & msg) const {
- (*m_out) << msg << std::endl ;
- }
-
- // Always, when you need to hold some context in your writer object, you need to hold
- // it as a shared pointer - this is because multiple copies of the same object might exist at the same time
- mutable ptr m_out;
-};
-
-struct write_to_cout {
- void operator()(const std::string & msg) const {
- std::cout << msg << std::endl ;
- }
-};
-
-struct write_to_dbg {
- void operator()(const std::string & msg) const {
-#ifdef BOOST_WINDOWS
- ::OutputDebugStringA( (msg + "\n").c_str() );
-#else
- msg; // so that there's no warning
-#endif
- }
-};
-
-typedef process_msg< gather::ostream_like::return_str<>, write_to_cout> processor_cout;
-typedef process_msg< gather::ostream_like::return_str<>, write_to_file> processor_file;
-typedef process_msg< gather::ostream_like::return_str<>, write_to_dbg> processor_dbg;
-
-logger<processor_cout, filter::no_ts> g_log_app;
-logger<processor_file, filter::no_ts> g_log_err("err.txt");
-logger<processor_dbg, filter::no_ts> g_log_dbg;
-
-#define LAPP_ if ( !g_log_app) ; else g_log_app->read_msg().gather().out()
-#define LERR_ if ( !g_log_err) ; else g_log_err->read_msg().gather().out()
-#define LDBG_ if ( !g_log_dbg) ; else g_log_dbg->read_msg().gather().out()
-
-
-void test_multiple_simple_logs() {
- // read from a file, dump it word by word
- std::ifstream in("readme.txt");
- std::string word;
-
- g_log_err.set_enabled(false);
-
- // when reaching these many words, we toggle the logs (enable/disable them)
- int toggle_count = 20;
-
- int idx = 1;
- for ( ; in >> word; ++idx) {
- LAPP_ << idx << " : reading word " << word;
- LERR_ << "error at " << idx << ", while reading " << word;
- LDBG_ << "debug info: " << idx << ", reading " << word;
-
-
- if ( idx % toggle_count == 0) {
- // toggle the logs
- g_log_app.set_enabled( !g_log_app.is_enabled() );
- g_log_err.set_enabled( !g_log_err.is_enabled() );
- g_log_dbg.set_enabled( !g_log_dbg.is_enabled() );
- }
- }
-}
-
-#ifdef SINGLE_TEST
-
-int main() {
- test_multiple_simple_logs();
-}
-
-#endif
-
-// End of file
-

Deleted: sandbox/logging/lib/logging/tests/test_ostream_like.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/test_ostream_like.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
+++ (empty file)
@@ -1,78 +0,0 @@
-// test_dump_to_file_and_cout_ostream_like.cpp
-
-// Boost Logging library
-//
-// Author: John Torjo, www.torjo.com
-//
-// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
-//
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// See http://www.boost.org for updates, documentation, and revision history.
-// See http://www.torjo.com/log2/ for more details
-
-
-#include <boost/logging/logging.hpp>
-#include <boost/logging/process_msg/ostream_like.hpp>
-#include <fstream>
-#include <iostream>
-#include <boost/shared_ptr.hpp>
-
-using namespace boost::logging;
-
-/*
- Dump to both cout and file, using the cool "<<" operator.
-
- Note that writing to the log is totally decoupled from the logging syntax ,
- while being efficient (if the log is disabled, we don't compute anything related to the message).
-*/
-
-struct write_to_cout_and_file {
- typedef boost::shared_ptr<std::ofstream> ptr;
-
- write_to_cout_and_file(const std::string & filename) : m_out(new std::ofstream(filename.c_str())) {}
- void operator()(const std::string & msg) const {
- std::cout << msg << std::endl ;
- (*m_out) << msg << std::endl ;
- }
-
- // Always, when you need to hold some context in your writer object, you need to hold
- // it as a shared pointer - this is because multiple copies of the same object might exist at the same time
- mutable ptr m_out;
-};
-
-typedef process_msg< gather::ostream_like::return_str<>, write_to_cout_and_file> processor;
-logger<processor, filter::no_ts> g_single_log("out.txt");
-
-#define L_ if ( !g_single_log) ; else g_single_log->read_msg().gather().out()
-
-
-void test_dump_to_file_and_cout_ostream_like() {
- // read from a file, dump it word by word
- std::ifstream in("readme.txt");
- std::string word;
-
- // when reaching these many words, we toggle the log (enable/disable it)
- int toggle_count = 20;
-
- int idx = 1;
- for ( ; in >> word; ++idx) {
- L_ << idx << " : reading word " << word;
-
- if ( idx % toggle_count == 0)
- g_single_log.set_enabled( !g_single_log.is_enabled() ); // toggle the log
- }
-}
-
-#ifdef SINGLE_TEST
-
-int main() {
- test_dump_to_file_and_cout_ostream_like();
-}
-
-#endif
-
-// End of file
-

Deleted: sandbox/logging/lib/logging/tests/test_simple_dump_to_cout.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/test_simple_dump_to_cout.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
+++ (empty file)
@@ -1,73 +0,0 @@
-// simple_dump_to_cout.cpp
-
-// Boost Logging library
-//
-// Author: John Torjo, www.torjo.com
-//
-// Copyright (C) 2007 John Torjo (see www.torjo.com for email)
-//
-// Distributed under the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE_1_0.txt or copy at
-// http://www.boost.org/LICENSE_1_0.txt)
-//
-// See http://www.boost.org for updates, documentation, and revision history.
-// See http://www.torjo.com/log2/ for more details
-
-
-#include <boost/logging/logging.hpp>
-#include <iostream>
-#include <fstream>
-
-/*
- As simple as it gets: Have a simple non-thread safe logger (filter::no_ts),
- and if the log is enabled, dump to cout.
-
- We log full messages, no using any "<<" when doing logging. That is,
- we do this:
- L_("my message")
-
- not:
- L_ << "my message comes from user " << user << ", with greetings"
-*/
-
-struct write_to_cout {
- void operator()(const std::string & msg) const {
- std::cout << msg << std::endl ;
- }
-};
-
-using namespace boost::logging;
-logger<write_to_cout, filter::no_ts> g_single_log;
-
-// FIXME i need to create a macro for "if ( sink<write_to_cout> s = g_single_log) s.process_msg()"
-#define L_(x) if ( g_single_log) g_single_log.process_msg()(x)
-
-
-void test_simple_dump_to_cout() {
- // read from a file, dump it word by word
- std::ifstream in("readme.txt");
- std::string word;
-
- // we allow only this many words
- int allow_word_count = 100;
-
- int idx = 0;
- for ( ; in >> word; ++idx)
- if ( idx < allow_word_count )
- L_("reading word " + word);
- else if ( idx == allow_word_count )
- // disable the log
- g_single_log.set_enabled(false);
-}
-
-
-#ifdef SINGLE_TEST
-
-int main() {
- test_simple_dump_to_cout();
-}
-
-#endif
-
-// End of file
-

Deleted: sandbox/logging/lib/logging/tests/testfast.cpp
==============================================================================
--- sandbox/logging/lib/logging/tests/testfast.cpp 2007-10-30 06:24:54 EDT (Tue, 30 Oct 2007)
+++ (empty file)
@@ -1,67 +0,0 @@
-
-#define BOOST_LOG_COMPILE_FAST_ON
-#include <boost/logging/format_fwd.hpp>
-
-// Step 1: Optimize : use a cache string, to make formatting the message faster
-BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
-
-#include <boost/logging/format.hpp>
-
-using namespace boost::logging;
-
-// Step 3 : Specify your logging class(es)
-typedef logger_format_write< > log_type;
-
-BOOST_DECLARE_LOG(g_l, log_type)
-
-
-// Step 4: declare which filters and loggers you'll use (usually in a header file)
-BOOST_DECLARE_LOG_FILTER(g_log_filter, filter::no_ts )
-BOOST_DECLARE_LOG(g_l, log_type)
-
-// Step 5: define the macros through which you'll log
-#define L_ BOOST_LOG_USE_LOG_IF_FILTER(g_l, g_log_filter->is_enabled() )
-
-
-void one_logger_one_filter_example() {
- // Step 7: add formatters and destinations
- // That is, how the message is to be formatted and where should it be written to
-
- g_l->writer().add_formatter( formatter::idx() );
- g_l->writer().add_formatter( formatter::append_enter() );
- g_l->writer().add_destination( destination::file("out.txt") );
- g_l->writer().add_destination( destination::cout() );
- g_l->writer().add_destination( destination::dbg_window() );
-
- // Step 8: use it...
- int i = 1;
- L_ << "this is so cool " << i++;
- L_ << "this is so cool again " << i++;
-
- std::string hello = "hello", world = "world";
- L_ << hello << ", " << world;
-
- g_log_filter->set_enabled(false);
- L_ << "this will not be written to the log";
- L_ << "this won't be written to the log";
-
- g_log_filter->set_enabled(true);
- L_ << "good to be back ;) " << i++;
-}
-
-
-
-#ifdef SINGLE_TEST
-
-int main() {
- one_logger_one_filter_example();
-}
-
-#endif
-
-// End of file
-
-// Step 6: Define the filters and loggers you'll use (usually in a source file)
-BOOST_DEFINE_LOG_FILTER(g_log_filter, filter::no_ts )
-BOOST_DEFINE_LOG(g_l, log_type)
-


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