|
Boost-Commit : |
From: john.groups_at_[hidden]
Date: 2008-01-30 13:42:46
Author: jtorjo
Date: 2008-01-30 13:42:45 EST (Wed, 30 Jan 2008)
New Revision: 43022
URL: http://svn.boost.org/trac/boost/changeset/43022
Log:
[logging]
updated jamfile for testing
Text files modified:
sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp | 114 +++++++++++++++------------------------
sandbox/logging/lib/logging/tests/Jamfile.v2 | 1
2 files changed, 44 insertions(+), 71 deletions(-)
Modified: sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp
==============================================================================
--- sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp (original)
+++ sandbox/logging/lib/logging/internal/vc8/loggingvc8/test_now.cpp 2008-01-30 13:42:45 EST (Wed, 30 Jan 2008)
@@ -1,94 +1,68 @@
-#define BOOST_LOG_BEFORE_INIT_USE_CACHE_FILTER
+/**
+@example mul_levels_one_logger.cpp
-// uncomment this, and all messages inside singleton's constructor will be logged!
-//#define BOOST_LOG_BEFORE_INIT_LOG_ALL
+@copydoc mul_levels_one_logger
-// uncomment this, and NO messages inside singleton's constructor will be logged
-//#define BOOST_LOG_BEFORE_INIT_IGNORE_BEFORE_INIT
+@page mul_levels_one_logger mul_levels_one_logger.cpp Example
-#include <boost/logging/format_fwd.hpp>
+This usage:
+- You have multiple levels (in this example: debug < info < error)
+- You want to format the message before it's written
+ (in this example: prefix it by time, by index, and append newline to it)
+- You have <b>one log</b>, which writes to several log destinations
+ (in this example: the console, the debug output window, and a file)
-BOOST_LOG_FORMAT_MSG( optimize::cache_string_one_str<> )
+In this example, all output will be written to the console, debug output window, and "out.txt" file.
+It will look similar to this one:
-#include <boost/logging/format.hpp>
+@code
+21:03.17.243 [1] this is so cool 1
+21:03.17.243 [2] first error 2
+21:03.17.243 [3] hello, world
+21:03.17.243 [4] second error 3
+21:03.17.243 [5] good to be back ;) 4
+21:03.17.243 [6] third error 5
+@endcode
-typedef boost::logging::logger_format_write< > logger_type;
+*/
-BOOST_DECLARE_LOG_FILTER(g_log_level, boost::logging::level::holder ) // holds the application log level
-BOOST_DECLARE_LOG(g_log_err, logger_type)
-BOOST_DECLARE_LOG(g_log_app, logger_type)
-BOOST_DECLARE_LOG(g_log_dbg, logger_type)
+#include <boost/logging/format/named_write.hpp>
+typedef boost::logging::named_logger<>::type logger_type;
-#define LDBG_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_dbg(), g_log_level(), debug ) << "[dbg] "
-#define LERR_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_err(), g_log_level(), error )
-#define LAPP_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_app(), g_log_level(), info ) << "[app] "
+#define L_(lvl) BOOST_LOG_USE_LOG_IF_LEVEL(g_l(), g_log_level(), lvl )
-BOOST_DEFINE_LOG_FILTER(g_log_level, boost::logging::level::holder )
-BOOST_DEFINE_LOG(g_log_err, logger_type)
-BOOST_DEFINE_LOG(g_log_app, logger_type)
-BOOST_DEFINE_LOG(g_log_dbg, logger_type)
+BOOST_DEFINE_LOG_FILTER(g_log_level, boost::logging::level::holder ) // holds the application log level
+BOOST_DEFINE_LOG(g_l, logger_type)
-using namespace boost::logging;
+void test_mul_levels_one_logger() {
+ // formatting : time [idx] message \n
+ // destinations : console, file "out.txt" and debug window
+ g_l()->writer().write("%time%($hh:$mm.$ss.$mili) [%idx%] |\n", "cout file(out.txt) debug");
+ g_l()->mark_as_initialized();
-struct singleton {
- singleton() {
- // note: these messages are written before logs are initialized
- int i = 1;
- LDBG_ << "this is so cool " << i++;
- LDBG_ << "this is so cool again " << i++;
- LERR_ << "first error " << i++;
+ int i = 1;
+ L_(debug) << "this is so cool " << i++;
+ L_(error) << "first error " << i++;
- std::string hello = "hello", world = "world";
- LAPP_ << hello << ", " << world;
+ std::string hello = "hello", world = "world";
+ L_(debug) << hello << ", " << world;
- LAPP_ << "coolio " << i++;
- LERR_ << "second error " << i++;
- LDBG_ << "some debug message" << i++;
- }
-} s_;
+ using namespace boost::logging;
+ g_log_level()->set_enabled(level::error);
+ L_(debug) << "this will not be written anywhere";
+ L_(info) << "this won't be written anywhere either";
+ L_(error) << "second error " << i++;
-void init_logs() {
- // Err log
- g_log_err()->writer().add_formatter( formatter::idx(), "[%] " );
- g_log_err()->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_log_err()->writer().add_formatter( formatter::append_newline() );
- g_log_err()->writer().add_destination( destination::file("err.txt") );
-
- destination::file out("out.txt");
- // App log
- g_log_app()->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_log_app()->writer().add_formatter( formatter::append_newline() );
- g_log_app()->writer().add_destination( out );
- g_log_app()->writer().add_destination( destination::cout() );
-
- // Debug log
- g_log_dbg()->writer().add_formatter( formatter::time("$hh:$mm.$ss ") );
- g_log_dbg()->writer().add_formatter( formatter::append_newline() );
- g_log_dbg()->writer().add_destination( out );
- g_log_dbg()->writer().add_destination( destination::dbg_window() );
-
- // if you change this, you'll get a different output (more or less verbose)
g_log_level()->set_enabled(level::info);
-
- g_log_err()->mark_as_initialized();
- g_log_app()->mark_as_initialized();
- g_log_dbg()->mark_as_initialized();
+ L_(info) << "good to be back ;) " << i++;
+ L_(error) << "third error " << i++;
}
-void cache_before_init_example() {
- init_logs();
- int i = 10;
- LAPP_ << "after logs have been initialized " << i++;
- g_log_level()->set_enabled(level::debug);
- LDBG_ << "some debug message after logs have been initialized " << i++;
-}
-
-
int main() {
- cache_before_init_example();
+ test_mul_levels_one_logger();
}
Modified: sandbox/logging/lib/logging/tests/Jamfile.v2
==============================================================================
--- sandbox/logging/lib/logging/tests/Jamfile.v2 (original)
+++ sandbox/logging/lib/logging/tests/Jamfile.v2 2008-01-30 13:42:45 EST (Wed, 30 Jan 2008)
@@ -9,7 +9,6 @@
: requirements
<include>../../../..
<include>$(BOOST_ROOT)
- <include>D:/john/code/latest_boost
<library>/boost/thread//boost_thread
;
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