summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhuangh <huangh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2013-04-11 15:22:24 +0000
committerhuangh <huangh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2013-04-11 15:22:24 +0000
commita08557f02035be6fc24c6653c37431de9b489bd3 (patch)
tree5755b3de138b2438649f9418a033484c9fbd8fac
parent6e69cd84b73e8117f5666c200ad6a5bbe4df35ce (diff)
downloadATCD-a08557f02035be6fc24c6653c37431de9b489bd3.tar.gz
Thu Apr 11 15:20:21 UTC 2013 Huang-Ming Huang <huangh@ociweb.com>
-rw-r--r--ACE/ChangeLog15
-rw-r--r--ACE/ace/Log_Category.cpp107
-rw-r--r--ACE/ace/Log_Category.h223
-rw-r--r--ACE/ace/Log_Category.inl159
-rw-r--r--ACE/ace/Log_Msg.cpp89
-rw-r--r--ACE/ace/Log_Msg.h8
-rw-r--r--ACE/ace/Log_Record.cpp19
-rw-r--r--ACE/ace/Log_Record.h9
-rw-r--r--ACE/ace/Log_Record.inl15
-rw-r--r--ACE/ace/ace.mpc1
-rw-r--r--ACE/tests/Log_Msg_Test.cpp3
11 files changed, 605 insertions, 43 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog
index d56e9edad1d..c4f0dbbb681 100644
--- a/ACE/ChangeLog
+++ b/ACE/ChangeLog
@@ -1,3 +1,18 @@
+Thu Apr 11 15:20:21 UTC 2013 Huang-Ming Huang <huangh@ociweb.com>
+
+ * ace/Log_Category.h:
+ * ace/Log_Category.inl:
+ * ace/Log_Category.cpp:
+ * ace/Log_Msg.h:
+ * ace/Log_Msg.cpp:
+ * ace/Log_Record.h:
+ * ace/Log_Record.inl:
+ * ace/Log_Record.cpp:
+ * ace/ace.mpc:
+ * tests/Log_Msg_Test.cpp:
+ Added ACE_Log_Category class so that log messages can be separated into
+ different categories and be enabled/disabled independently.
+
Thu Apr 11 11:13:34 UTC 2013 Douglas C. Schmidt <schmidt@dre.vanderbilt.edu>
* README: Updated this file, which was horribly out of date!
diff --git a/ACE/ace/Log_Category.cpp b/ACE/ace/Log_Category.cpp
new file mode 100644
index 00000000000..6ca315a9380
--- /dev/null
+++ b/ACE/ace/Log_Category.cpp
@@ -0,0 +1,107 @@
+// $Id$
+
+#include "ace/Log_Msg.h"
+#include "ace/Log_Category.h"
+#include "ace/Atomic_Op.h"
+#include "ace/OS_NS_Thread.h"
+
+
+#if !defined (__ACE_INLINE__)
+#include "ace/Log_Category.inl"
+#endif /* __ACE_INLINE__ */
+
+
+ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
+ACE_Log_Category::ACE_Log_Category(const char* name)
+ : name_(name)
+ , id_(0)
+/// Default per-process priority mask
+/// By default, all priorities are enabled.
+ , priority_mask_(LM_SHUTDOWN
+ | LM_TRACE
+ | LM_DEBUG
+ | LM_INFO
+ | LM_NOTICE
+ | LM_WARNING
+ | LM_STARTUP
+ | LM_ERROR
+ | LM_CRITICAL
+ | LM_ALERT
+ | LM_EMERGENCY)
+{
+}
+
+ACE_Log_Category::~ACE_Log_Category()
+{
+ ACE_GUARD (ACE_Thread_Mutex, ace_mon, this->keylock_);
+
+ if (this->id_ > 0)
+ {
+ ACE_OS::thr_keyfree (this->key_);
+ }
+}
+
+ACE_Log_Category_TSS::ACE_Log_Category_TSS(ACE_Log_Category* category)
+ : category_(category)
+ , logger_(ACE_Log_Msg::instance ())
+ , priority_mask_(0)
+{
+}
+
+ACE_Log_Category_TSS*
+ACE_Log_Category::per_thr_obj()
+{
+ {
+ // Ensure that we are serialized!
+ ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->keylock_, 0);
+
+ // make sure we only create the key once!
+ if (this->id_ == 0)
+ {
+ static ACE_Atomic_Op<ACE_Thread_Mutex, unsigned int> log_category_id_assigner(1);
+ id_ = log_category_id_assigner++; // for atomic integers, post increment is more efficient
+
+ if (ACE_OS::thr_keycreate (&this->key_,
+ &ACE_Log_Category::tss_destroy) != 0)
+ return 0; // Major problems, this should *never* happen!
+ }
+ }
+
+ void *temp = 0;
+ if (ACE_OS::thr_getspecific (this->key_, &temp) == -1)
+ {
+ return 0; // This should not happen!
+ }
+ if (temp != 0)
+ return static_cast <ACE_Log_Category_TSS *> (temp);
+
+ ACE_Log_Category_TSS * result;
+
+ ACE_NEW_RETURN(result,
+ ACE_Log_Category_TSS(this),
+ 0);
+
+ if (ACE_OS::thr_setspecific (this->key_,
+ result) != 0)
+ {
+ return 0;
+ }
+
+ return result;
+}
+
+void
+ACE_Log_Category::tss_destroy(void * p)
+{
+ delete static_cast<ACE_Log_Category_TSS*>(p);
+}
+
+ACE_Log_Category&
+ACE_Log_Category::ace_lib()
+{
+ static ACE_Log_Category ace_lib_category("ACE");
+ return ace_lib_category;
+}
+
+ACE_END_VERSIONED_NAMESPACE_DECL
diff --git a/ACE/ace/Log_Category.h b/ACE/ace/Log_Category.h
new file mode 100644
index 00000000000..fbbb1a81fc1
--- /dev/null
+++ b/ACE/ace/Log_Category.h
@@ -0,0 +1,223 @@
+// -*- C++ -*-
+
+//=============================================================================
+/**
+ * @file Log_Category.h
+ *
+ * $Id$
+ *
+ * @author Huang-Ming Huang <huangh@ociweb.com>
+ */
+//=============================================================================
+
+#ifndef ACE_LOG_CATEGORY_H
+#define ACE_LOG_CATEGORY_H
+
+#include /**/ "ace/pre.h"
+
+#include "ace/Log_Priority.h"
+#include "ace/Thread_Mutex.h"
+
+ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
+#if defined (ACE_NLOGGING)
+#if !defined (ACELIB_HEX_DUMP)
+# define ACELIB_HEX_DUMP(X) do {} while (0)
+#endif
+#if !defined (ACELIB_RETURN)
+# define ACELIB_RETURN(Y) do { return (Y); } while (0)
+#endif
+#if !defined (ACELIB_ERROR_RETURN)
+# define ACELIB_ERROR_RETURN(X, Y) return (Y)
+#endif
+#if !defined (ACELIB_ERROR_BREAK)
+# define ACELIB_ERROR_BREAK(X) { break; }
+#endif
+#if !defined (ACELIB_ERROR)
+# define ACELIB_ERROR(X) do {} while (0)
+#endif
+#if !defined (ACELIB_DEBUG)
+# define ACELIB_DEBUG(X) do {} while (0)
+#endif
+#if !defined (ACELIB_ERROR_INIT)
+# define ACELIB_ERROR_INIT(VALUE, FLAGS)
+#endif
+#else
+#if !defined (ACELIB_HEX_DUMP)
+#define ACELIB_HEX_DUMP(X) \
+ 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;\
+ ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \
+ ace___->log_hexdump X; \
+ } while (0)
+#endif
+#if !defined (ACELIB_RETURN)
+#define ACELIB_RETURN(Y) \
+ do { \
+ int const __ace_error = ACE_Log_Msg::last_error_adapter (); \
+ ACE_Log_Msg *ace___ = ACE_Log_Msg::instance(); \
+ ace___->set (__FILE__, __LINE__, Y, __ace_error, ace___->restart (), \
+ ace___->msg_ostream (), ace___->msg_callback ()); \
+ return Y; \
+ } while (0)
+#endif
+#if !defined (ACELIB_ERROR_RETURN)
+#define ACELIB_ERROR_RETURN(X, Y) \
+ 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;\
+ ace___->conditional_set (__FILE__, __LINE__, Y, __ace_error); \
+ ace___->log X; \
+ return Y; \
+ } while (0)
+#endif
+#if !defined (ACELIB_ERROR)
+#define ACELIB_ERROR(X) \
+ 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;\
+ ace___->conditional_set (__FILE__, __LINE__, -1, __ace_error); \
+ ace___->log X; \
+ } while (0)
+#endif
+#if !defined (ACELIB_DEBUG)
+#define ACELIB_DEBUG(X) \
+ 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;\
+ ace___->conditional_set (__FILE__, __LINE__, 0, __ace_error); \
+ ace___->log X; \
+ } while (0)
+#endif
+#if !defined (ACELIB_ERROR_BREAK)
+#define ACELIB_ERROR_BREAK(X) { ACELIB_ERROR (X); break; }
+#endif
+#endif /* ACE_NLOGGING */
+
+
+class ACE_Log_Msg;
+class ACE_Log_Category;
+
+class ACE_Export ACE_Log_Category_TSS
+{
+public:
+ ACE_Log_Category_TSS(ACE_Log_Category* category);
+
+ const char* name();
+ unsigned int id();
+
+ ACE_Log_Msg* logger();
+ /// Get the current ACE_Log_Priority mask.
+ u_long priority_mask ();
+
+ /// Set the ACE_Log_Priority mask, returns original mask.
+ u_long priority_mask (u_long);
+ /// Return true if the requested priority is enabled.
+ int log_priority_enabled (ACE_Log_Priority log_priority);
+
+ /**
+ * Set the line number, file name, operational status, error number,
+ * restart flag, ostream, and the callback object. This combines
+ * all the other set methods into a single method.
+ */
+ void set (const char *file,
+ int line,
+ int op_status = -1,
+ int errnum = 0);
+
+ /// These values are only actually set if the requested priority is
+ /// enabled.
+ void conditional_set (const char *file,
+ int line,
+ int op_status,
+ int errnum);
+
+ ssize_t log (ACE_Log_Priority priority, const ACE_TCHAR *format, ...);
+
+#if defined (ACE_HAS_WCHAR)
+ ssize_t log (ACE_Log_Priority priority, const ACE_ANTI_TCHAR *format, ...);
+#endif /* ACE_HAS_WCHAR */
+
+ ssize_t log (const ACE_TCHAR *format,
+ ACE_Log_Priority priority,
+ va_list argp);
+
+ /**
+ * Method to log hex dump. This is useful for debugging. Calls
+ * log() to do the actual print, but formats first to make the chars
+ * printable.
+ */
+ int log_hexdump (ACE_Log_Priority log_priority,
+ const char * buffer,
+ size_t size,
+ const ACE_TCHAR *text = 0);
+
+private:
+ ACE_Log_Category* category_;
+ ACE_Log_Msg* logger_;
+ u_long priority_mask_;
+};
+
+
+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.
+ ACE_Log_Category(const char* name);
+ ~ACE_Log_Category();
+
+ unsigned int id();
+ const char* name();
+
+ ACE_Log_Category_TSS* per_thr_obj();
+
+ /// Get the process ACE_Log_Priority mask.
+ u_long priority_mask ();
+
+ /// Set the process ACE_Log_Priority mask, returns original mask.
+ u_long priority_mask (u_long);
+
+
+ static ACE_Log_Category& ace_lib();
+
+private:
+ friend class ACE_Log_Category_TSS;
+ static void tss_destroy(void * p);
+
+ // disable copying
+ ACE_Log_Category(const ACE_Log_Category&);
+ ACE_Log_Category& operator = (const ACE_Log_Category&);
+
+ const char* name_;
+ unsigned int id_;
+ u_long priority_mask_;
+
+ /// we couldn't directly use ACE_TSS because it would
+ /// create circular dependency
+
+ /// Avoid race conditions during initialization.
+ ACE_Thread_Mutex keylock_;
+ /// "First time in" flag.
+ /// Key for the thread-specific error data.
+ ACE_thread_key_t key_;
+};
+
+
+ACE_END_VERSIONED_NAMESPACE_DECL
+
+#if defined (__ACE_INLINE__)
+#include "ace/Log_Category.inl"
+#endif /* __ACE_INLINE__ */
+
+#include /**/ "ace/post.h"
+#endif /* ACE_LOG_CATEGORY_H */
diff --git a/ACE/ace/Log_Category.inl b/ACE/ace/Log_Category.inl
new file mode 100644
index 00000000000..7649da7f3b8
--- /dev/null
+++ b/ACE/ace/Log_Category.inl
@@ -0,0 +1,159 @@
+// -*- C++ -*-
+//
+// $Id$
+
+ACE_BEGIN_VERSIONED_NAMESPACE_DECL
+
+ACE_INLINE unsigned int
+ACE_Log_Category::id()
+{
+ return id_;
+}
+
+ACE_INLINE const char*
+ACE_Log_Category::name ()
+{
+ return name_;
+}
+
+ACE_INLINE unsigned int
+ACE_Log_Category_TSS::id()
+{
+ return category_->id_;
+}
+
+ACE_INLINE const char*
+ACE_Log_Category_TSS::name ()
+{
+ return category_->name_;
+}
+
+ACE_INLINE ACE_Log_Msg*
+ACE_Log_Category_TSS::logger ()
+{
+ return logger_;
+}
+
+/// Get the current ACE_Log_Priority mask.
+ACE_INLINE u_long
+ACE_Log_Category_TSS::priority_mask ()
+{
+ return priority_mask_;
+}
+
+/// Set the ACE_Log_Priority mask, returns original mask.
+ACE_INLINE u_long
+ACE_Log_Category_TSS::priority_mask (u_long n_mask)
+{
+ u_long o_mask = this->priority_mask_;
+ this->priority_mask_ = n_mask;
+ return o_mask;
+}
+/// Return true if the requested priority is enabled.
+ACE_INLINE int
+ACE_Log_Category_TSS::log_priority_enabled (ACE_Log_Priority log_priority)
+{
+ return ACE_BIT_ENABLED (this->priority_mask_ |
+ category_->priority_mask(),
+ log_priority);
+}
+
+ACE_INLINE void
+ACE_Log_Category_TSS::set (const char *file,
+ int line,
+ int op_status,
+ int errnum)
+{
+ logger_->set(file, line, op_status, errnum, logger_->restart (), logger_->msg_ostream (), logger_->msg_callback ());
+}
+
+/// These values are only actually set if the requested priority is
+/// enabled.
+ACE_INLINE
+void ACE_Log_Category_TSS::conditional_set (const char *file,
+ int line,
+ int op_status,
+ int errnum)
+{
+ logger_->conditional_set(file, line, op_status, errnum);
+}
+
+ACE_INLINE ssize_t
+ACE_Log_Category_TSS::log (ACE_Log_Priority priority, const ACE_TCHAR *format_str, ...)
+{
+ // Start of variable args section.
+ va_list argp;
+
+ va_start (argp, format_str);
+
+ ssize_t const result = this->log (format_str,
+ priority,
+ argp);
+ va_end (argp);
+
+ return result;
+}
+
+#if defined (ACE_HAS_WCHAR)
+ACE_INLINE ssize_t
+ACE_Log_Category_TSS::log (ACE_Log_Priority priority, const ACE_ANTI_TCHAR *format_str, ...)
+{
+ // Start of variable args section.
+ va_list argp;
+
+ va_start (argp, format_str);
+
+ ssize_t const result = this->log (ACE_TEXT_ANTI_TO_TCHAR (format_str),
+ priority,
+ argp);
+ va_end (argp);
+
+ return result;
+}
+#endif /* ACE_HAS_WCHAR */
+
+/**
+ * An alternative logging mechanism that makes it possible to
+ * integrate variable argument lists from other logging mechanisms
+ * into the ACE mechanism.
+ */
+
+ACE_INLINE ssize_t
+ACE_Log_Category_TSS::log (const ACE_TCHAR *format,
+ ACE_Log_Priority priority,
+ va_list argp)
+{
+ if (this->log_priority_enabled (priority) == 0)
+ return 0;
+ return logger_->log(format, priority, argp, this);
+}
+
+
+ACE_INLINE int
+ACE_Log_Category_TSS::log_hexdump (ACE_Log_Priority priority,
+ const char *buffer,
+ size_t size,
+ const ACE_TCHAR *text)
+{
+ if (this->log_priority_enabled (priority) == 0)
+ return 0;
+ return logger_->log_hexdump(priority, buffer, size, text, this);
+}
+
+/// Get the current ACE_Log_Priority mask.
+ACE_INLINE u_long
+ACE_Log_Category::priority_mask ()
+{
+ return priority_mask_;
+}
+
+/// Set the ACE_Log_Priority mask, returns original mask.
+ACE_INLINE u_long
+ACE_Log_Category::priority_mask (u_long n_mask)
+{
+ u_long o_mask = this->priority_mask_;
+ this->priority_mask_ = n_mask;
+ return o_mask;
+}
+
+ACE_END_VERSIONED_NAMESPACE_DECL
diff --git a/ACE/ace/Log_Msg.cpp b/ACE/ace/Log_Msg.cpp
index 957a6628ae6..47a368abb8d 100644
--- a/ACE/ace/Log_Msg.cpp
+++ b/ACE/ace/Log_Msg.cpp
@@ -971,7 +971,8 @@ ACE_Log_Msg::log (ACE_Log_Priority log_priority,
ssize_t
ACE_Log_Msg::log (const ACE_TCHAR *format_str,
ACE_Log_Priority log_priority,
- va_list argp)
+ va_list argp,
+ ACE_Log_Category_TSS* category)
{
ACE_TRACE ("ACE_Log_Msg::log");
// External decls.
@@ -1009,6 +1010,8 @@ ACE_Log_Msg::log (const ACE_TCHAR *format_str,
ACE_OS::gettimeofday (),
this->getpid ());
+ log_record.category(category);
+
// bp is pointer to where to put next part of logged message.
// bspace is the number of characters remaining in msg_.
ACE_TCHAR *bp = const_cast<ACE_TCHAR *> (this->msg ());
@@ -2292,61 +2295,73 @@ int
ACE_Log_Msg::log_hexdump (ACE_Log_Priority log_priority,
const char *buffer,
size_t size,
- const ACE_TCHAR *text)
+ const ACE_TCHAR *text,
+ ACE_Log_Category_TSS* category)
{
// Only print the message if <priority_mask_> hasn't been reset to
// exclude this logging priority.
if (this->log_priority_enabled (log_priority) == 0)
return 0;
- ACE_TCHAR* buf = 0;
- size_t const buf_sz =
- ACE_Log_Record::MAXLOGMSGLEN - ACE_Log_Record::VERBOSE_LEN - 58;
- ACE_NEW_RETURN (buf, ACE_TCHAR[buf_sz], -1);
+ size_t text_sz = 0;
+ if (text)
+ text_sz = ACE_OS::strlen (text);
- ACE_TCHAR *msg_buf = 0;
- const size_t text_sz = text ? ACE_OS::strlen(text) : 0;
- ACE_NEW_RETURN (msg_buf,
- ACE_TCHAR[text_sz + 58],
- -1);
+ size_t total_buffer_size = ACE_Log_Record::MAXLOGMSGLEN - ACE_Log_Record::VERBOSE_LEN +text_sz;
- buf[0] = 0; // in case size = 0
+ ACE_Array<ACE_TCHAR> msg_buf(total_buffer_size);
+ if (msg_buf.size() == 0)
+ return -1;
- size_t const len = ACE::format_hexdump
- (buffer, size, buf, buf_sz / sizeof (ACE_TCHAR) - text_sz);
+ ACE_TCHAR* end_ptr = &msg_buf[0] + total_buffer_size;
+ ACE_TCHAR* wr_ptr = &msg_buf[0];
+ msg_buf[0] = 0; // in case size = 0
- int sz = 0;
if (text)
- sz = ACE_OS::sprintf (msg_buf,
+ wr_ptr += ACE_OS::snprintf (wr_ptr,
+ end_ptr - wr_ptr,
#if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
- ACE_TEXT ("%ls - "),
+ ACE_TEXT ("%ls - "),
#else
- ACE_TEXT ("%s - "),
+ ACE_TEXT ("%s - "),
#endif
- text);
-
- sz += ACE_OS::sprintf (msg_buf + sz,
- ACE_TEXT ("HEXDUMP ")
- ACE_SIZE_T_FORMAT_SPECIFIER
- ACE_TEXT (" bytes"),
- size);
+ text);
+
+ wr_ptr += ACE_OS::snprintf (wr_ptr,
+ end_ptr - wr_ptr,
+ ACE_TEXT ("HEXDUMP ")
+ ACE_SIZE_T_FORMAT_SPECIFIER
+ ACE_TEXT (" bytes"),
+ size);
+
+ // estimate how many bytes can be output
+ // We can fit 16 bytes output in text mode per line, 4 chars per byte;
+ // i.e. we need 68 bytes of buffer per line.
+ size_t hexdump_size = (end_ptr - wr_ptr -58)/68*16;
+
+ if (hexdump_size < size) {
+ wr_ptr += ACE_OS::snprintf (wr_ptr,
+ end_ptr - wr_ptr,
+ ACE_TEXT (" (showing first ")
+ ACE_SIZE_T_FORMAT_SPECIFIER
+ ACE_TEXT (" bytes)"),
+ hexdump_size);
+ size = hexdump_size;
+ }
- if (len < size)
- ACE_OS::sprintf (msg_buf + sz,
- ACE_TEXT (" (showing first ")
- ACE_SIZE_T_FORMAT_SPECIFIER
- ACE_TEXT (" bytes)"),
- len);
+ *wr_ptr++ = '\n';
+ ACE::format_hexdump(buffer, size, wr_ptr, end_ptr - wr_ptr);
// Now print out the formatted buffer.
- this->log (log_priority,
- ACE_TEXT ("%s\n%s"),
- msg_buf,
- buf);
+ ACE_Log_Record log_record (log_priority,
+ ACE_OS::gettimeofday (),
+ this->getpid ());
+
+ log_record.category(category);
+ log_record.msg_data(&msg_buf[0]);
- delete [] msg_buf;
- delete [] buf;
+ this->log (log_record, false);
return 0;
}
diff --git a/ACE/ace/Log_Msg.h b/ACE/ace/Log_Msg.h
index f847c4ede0e..0f837babcd2 100644
--- a/ACE/ace/Log_Msg.h
+++ b/ACE/ace/Log_Msg.h
@@ -143,6 +143,7 @@ class ACE_Log_Msg_Backend;
// Forward declaration
class ACE_Thread_Descriptor;
class ACE_Log_Record;
+class ACE_Log_Category_TSS;
template<typename M, typename T> class ACE_Atomic_Op;
/**
@@ -539,7 +540,8 @@ public:
*/
ssize_t log (const ACE_TCHAR *format,
ACE_Log_Priority priority,
- va_list argp);
+ va_list argp,
+ ACE_Log_Category_TSS* category=0);
/// Log a custom built log record to the currently enabled logging
/// sinks.
@@ -554,7 +556,8 @@ public:
int log_hexdump (ACE_Log_Priority log_priority,
const char *buffer,
size_t size,
- const ACE_TCHAR *text = 0);
+ const ACE_TCHAR *text = 0,
+ ACE_Log_Category_TSS* category=0);
/**
* Init hook, create a Log_Msg_Attribute object, initialize its
@@ -743,6 +746,7 @@ ACE_TSS_CLEANUP_NAME (void *ptr);
# endif /* ACE_HAS_THREAD_SPECIFIC_STORAGE || ACE_HAS_TSS_EMULATION */
#endif /* ACE_MT_SAFE */
+
#if defined (__ACE_INLINE__)
#include "ace/Log_Msg.inl"
#endif /* __ACE_INLINE__ */
diff --git a/ACE/ace/Log_Record.cpp b/ACE/ace/Log_Record.cpp
index 299b66bb480..79b972acd13 100644
--- a/ACE/ace/Log_Record.cpp
+++ b/ACE/ace/Log_Record.cpp
@@ -8,6 +8,7 @@
#include "ace/CDR_Stream.h"
#include "ace/Auto_Ptr.h"
#include "ace/Truncate.h"
+#include "ace/Log_Category.h"
#if !defined (__ACE_INLINE__)
# include "ace/Log_Record.inl"
@@ -146,7 +147,8 @@ ACE_Log_Record::ACE_Log_Record (ACE_Log_Priority lp,
usecs_ (0),
pid_ (ACE_UINT32 (p)),
msg_data_ (0),
- msg_data_size_ (0)
+ msg_data_size_ (0),
+ category_(0)
{
// ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]);
@@ -166,7 +168,8 @@ ACE_Log_Record::ACE_Log_Record (ACE_Log_Priority lp,
usecs_ ((ACE_UINT32) ts.usec ()),
pid_ (ACE_UINT32 (p)),
msg_data_ (0),
- msg_data_size_ (0)
+ msg_data_size_ (0),
+ category_(0)
{
// ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]);
@@ -269,12 +272,20 @@ ACE_Log_Record::format_msg (const ACE_TCHAR host_name[],
return 0;
}
+inline bool
+log_priority_enabled(ACE_Log_Category_TSS* category, ACE_Log_Priority priority)
+{
+ if (category && !category->log_priority_enabled (priority))
+ return false;
+ return ACE_LOG_MSG->log_priority_enabled (priority);
+}
+
int
ACE_Log_Record::print (const ACE_TCHAR host_name[],
u_long verbose_flag,
FILE *fp)
{
- if (ACE_LOG_MSG->log_priority_enabled (ACE_Log_Priority (this->type_)))
+ if ( log_priority_enabled(this->category(), ACE_Log_Priority (this->type_)) )
{
ACE_TCHAR *verbose_msg = 0;
ACE_NEW_RETURN (verbose_msg, ACE_TCHAR[MAXVERBOSELOGMSGLEN], -1);
@@ -374,7 +385,7 @@ ACE_Log_Record::print (const ACE_TCHAR host_name[],
u_long verbose_flag,
ACE_OSTREAM_TYPE &s)
{
- if (ACE_LOG_MSG->log_priority_enabled (ACE_Log_Priority (this->type_)))
+ if ( log_priority_enabled(this->category(), ACE_Log_Priority (this->type_)) )
{
ACE_TCHAR* verbose_msg = 0;
ACE_NEW_RETURN (verbose_msg, ACE_TCHAR[MAXVERBOSELOGMSGLEN], -1);
diff --git a/ACE/ace/Log_Record.h b/ACE/ace/Log_Record.h
index e4c9dcff4bf..cf05c940f74 100644
--- a/ACE/ace/Log_Record.h
+++ b/ACE/ace/Log_Record.h
@@ -32,6 +32,7 @@
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
class ACE_Time_Value;
+class ACE_Log_Category_TSS;
/// Defines the structure of an ACE logging record.
class ACE_Export ACE_Log_Record
@@ -109,6 +110,11 @@ public:
/// Set the type of the Log_Record.
void type (ACE_UINT32);
+ /// Get the category of the Log_Record.
+ ACE_Log_Category_TSS* category (void) const;
+ /// Set the category of the Log_Record.
+ void category (ACE_Log_Category_TSS*);
+
/**
* Get the priority of the Log_Record <type_>. This is computed
* as the base 2 logarithm of <type_> (which must be a power of 2,
@@ -186,6 +192,9 @@ private:
/// Allocated size of msg_data_ in ACE_TCHARs
size_t msg_data_size_;
+ ///
+ ACE_Log_Category_TSS* category_;
+
/// disallow copying...
ACE_Log_Record (const ACE_Log_Record& rhs);
ACE_Log_Record& operator= (const ACE_Log_Record& rhs);
diff --git a/ACE/ace/Log_Record.inl b/ACE/ace/Log_Record.inl
index bf283301335..37557542584 100644
--- a/ACE/ace/Log_Record.inl
+++ b/ACE/ace/Log_Record.inl
@@ -24,6 +24,21 @@ ACE_Log_Record::type (void) const
}
ACE_INLINE void
+ACE_Log_Record::category (ACE_Log_Category_TSS* t)
+{
+ ACE_TRACE ("ACE_Log_Record::category");
+ this->category_ = t;
+}
+
+
+ACE_INLINE ACE_Log_Category_TSS*
+ACE_Log_Record::category (void) const
+{
+ ACE_TRACE ("ACE_Log_Record::type");
+ return this->category_;
+}
+
+ACE_INLINE void
ACE_Log_Record::type (ACE_UINT32 t)
{
ACE_TRACE ("ACE_Log_Record::type");
diff --git a/ACE/ace/ace.mpc b/ACE/ace/ace.mpc
index 7dddd64d40d..affa87a3034 100644
--- a/ACE/ace/ace.mpc
+++ b/ACE/ace/ace.mpc
@@ -92,6 +92,7 @@ project(ACE) : ace_output, acedefaults, install, other, codecs, token, svcconf,
Lib_Find.cpp
Local_Memory_Pool.cpp
Lock.cpp
+ Log_Category.cpp
Log_Msg.cpp
Log_Msg_Backend.cpp
Log_Msg_Callback.cpp
diff --git a/ACE/tests/Log_Msg_Test.cpp b/ACE/tests/Log_Msg_Test.cpp
index 9601961af85..0c5055733e7 100644
--- a/ACE/tests/Log_Msg_Test.cpp
+++ b/ACE/tests/Log_Msg_Test.cpp
@@ -243,6 +243,9 @@ test_log_msg_features (const ACE_TCHAR *program)
big[ACE_Log_Record::MAXLOGMSGLEN] = ACE_TEXT ('\0');
ACE_DEBUG ((LM_INFO, ACE_TEXT ("This is too big: %s\n"), big));
+ ACE_DEBUG ((LM_INFO, ACE_TEXT ("******\n")));
+ ACE_HEX_DUMP((LM_INFO, big, ACE_Log_Record::MAXLOGMSGLEN ));
+
// Exercise many different combinations of OSTREAM.
double f = 3.1416 * counter++;