diff options
author | huangh <huangh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2013-04-11 19:46:15 +0000 |
---|---|---|
committer | huangh <huangh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2013-04-11 19:46:15 +0000 |
commit | 1ac4b17c0ebfc337c072a0ebc5998e7b045798ee (patch) | |
tree | 360ba8321d0190422a449b87be00a6b34cd4decd | |
parent | 432d3732add8423c4c199942b977cee7d8f7af39 (diff) | |
download | ATCD-1ac4b17c0ebfc337c072a0ebc5998e7b045798ee.tar.gz |
Thu Apr 11 19:42:14 UTC 2013 Huang-Ming Huang <huangh@ociweb.com>
-rw-r--r-- | ACE/ChangeLog | 8 | ||||
-rw-r--r-- | ACE/ace/Log_Category.h | 57 | ||||
-rw-r--r-- | ACE/tests/Log_Msg_Test.cpp | 104 |
3 files changed, 162 insertions, 7 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 8c29baf8a83..ade7c8fea9c 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,11 @@ +Thu Apr 11 19:42:14 UTC 2013 Huang-Ming Huang <huangh@ociweb.com> + + * ace/Log_Category.h: + Fixed ACE_ERROR_RETURN() control reaches end of non-void function warning. + + * tests/Log_Msg_Test.cpp: + Added test for ACE_Log_Category + Thu Apr 11 17:54:55 UTC 2013 Huang-Ming Huang <huangh@ociweb.com> * ace/ace_for_tao.mpc: diff --git a/ACE/ace/Log_Category.h b/ACE/ace/Log_Category.h index 9bad1b208fb..73274be42f6 100644 --- a/ACE/ace/Log_Category.h +++ b/ACE/ace/Log_Category.h @@ -69,7 +69,7 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL do { \ int const __ace_error = ACE_Log_Msg::last_error_adapter (); \ ACE_Log_Category_TSS *ace___ = ACE_Log_Category::ace_lib().per_thr_obj(); \ - if (ace___ == 0) break;\ + if (ace___ == 0) return Y;\ ace___->conditional_set (__FILE__, __LINE__, Y, __ace_error); \ ace___->log X; \ return Y; \ @@ -104,6 +104,15 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL class ACE_Log_Msg; class ACE_Log_Category; + +/** + * @class ACE_Log_Category_TSS + * + * @brief The thread specific object for a ACE_Log_Categy object. + * + * @see{ACE_Log_Categy} for detailed explaination. + */ + class ACE_Export ACE_Log_Category_TSS { public: @@ -164,16 +173,50 @@ private: u_long priority_mask_; }; - +/** + * @class ACE_Log_Category + * + * @brief Provides a categorized message logging + * abstraction. + * + * This class added another level of abstraction to + * @c ACE_Log_Msg to separate log messages into different + * categories. Logs in different categories can be independently + * enabled or disabled. Each cateogry can have a name which + * is fixed at construction. The name is not used for + * formating the messages. However, it can be used by a + * message backend object for identification and reformat + * accordingly. + * + * To log a message into a category. Create a new @c ACE_Log_Category + * and then use @c per_thr_obj() for logging. For example, + * + * \code{.cpp} + * ACE_Log_Category test_catogory("Test"); + * test_cateogry.per_thr_obj(LM_DEBUG, "Log into the Test category."); + * + * // set the process wide priority mask + * test_catogory.priority_mask(LM_DEBUG|LM_ERROR); + * + * // set the thread specific priority mask + * test_cateogry.per_thr_obj.priority_mask(LM_DEBUG); + * \endcode + */ class ACE_Export ACE_Log_Category { public: - /// Notice that ACE_Log_Category does not - /// deep copy the passed \a name; therefore, - /// you must keep the lifetime of \a name - /// longer than the newly create ACE_Log_Category - /// object. + /** + * Initialize the logger with a name. + * + * Notice that ACE_Log_Category does not + * deep copy the passed \a name; therefore, + * you must keep the lifetime of \a name + * longer than the newly create ACE_Log_Category + * object. The rational for the design is to avoid + * static initialization problem when the ACE_Log_Category + * is created in static storage. + */ ACE_Log_Category(const char* name); ~ACE_Log_Category(); diff --git a/ACE/tests/Log_Msg_Test.cpp b/ACE/tests/Log_Msg_Test.cpp index 0c5055733e7..40a6a1fc589 100644 --- a/ACE/tests/Log_Msg_Test.cpp +++ b/ACE/tests/Log_Msg_Test.cpp @@ -352,6 +352,108 @@ test_log_msg_features (const ACE_TCHAR *program) ACE_TEXT ("This LM_DEBUG message should not print!\n"))); } +// For testing how many log records has been output +class Log_Count : public ACE_Log_Msg_Callback +{ + int count_; +public: + /// logging! + Log_Count () : count_(0) + { + } + + /// Logging callback + void log (ACE_Log_Record &) + { + ++count_; + } + + int count() const + { + return count_; + } +}; + +static int +test_acelib_category() +{ + int failed = 0; + + Log_Count counter; + + ACE_LOG_MSG->msg_callback (&counter); + + // Disable the LM_DEBUG and LM_INFO messages. + u_long priority_mask = + ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS); + ACE_CLR_BITS (priority_mask, + LM_DEBUG | LM_INFO); + ACE_Log_Category::ace_lib().priority_mask (priority_mask); + + ACELIB_DEBUG ((LM_INFO, + ACE_TEXT ("This LM_INFO message should not print!\n"))); + ACELIB_DEBUG ((LM_DEBUG, + ACE_TEXT ("This LM_DEBUG message should not print!\n"))); + + if (counter.count() != 0) + { + ++failed; + } + + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("This LM_INFO message should print!\n"))); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("This LM_DEBUG message should print!\n"))); + + if (counter.count() != 2) + { + ++failed; + } + + ACE_SET_BITS (priority_mask, + LM_INFO); + ACE_Log_Category::ace_lib().priority_mask (priority_mask); + + ACELIB_DEBUG ((LM_INFO, + ACE_TEXT ("This LM_INFO message should print!\n"))); + + if (counter.count() != 3) + { + ++failed; + } + + ACELIB_DEBUG ((LM_DEBUG, + ACE_TEXT ("This LM_DEBUG message should not print!\n"))); + + if (counter.count() != 3) + { + ++failed; + } + + ACE_CLR_BITS (priority_mask, LM_INFO); + ACE_Log_Category::ace_lib().priority_mask (priority_mask); + + ACELIB_DEBUG ((LM_INFO, + ACE_TEXT ("This LM_INFO message should not print!\n"))); + ACELIB_DEBUG ((LM_DEBUG, + ACE_TEXT ("This LM_DEBUG message should not print!\n"))); + + if (counter.count() != 3) + { + ++failed; + } + + + if (failed == 0) { + ACE_DEBUG((LM_DEBUG, "All ace lib category log passed\n")); + } + else { + ACE_ERROR((LM_ERROR, "Some ace lib category log failed\n")); + } + ACE_LOG_MSG->msg_callback (0); + return failed; +} + static int test_ostream (void) { @@ -726,6 +828,8 @@ run_main (int argc, ACE_TCHAR *argv[]) status = 1; } + status += test_acelib_category(); + ACE_END_TEST; return status; } |