Defines the structure of an ACE logging record. More...
#include <Log_Record.h>
Public Types | |
enum | { MAXLOGMSGLEN = ACE_MAXLOGMSGLEN+1, ALIGN_WORDB = 8, VERBOSE_LEN = 128, MAXVERBOSELOGMSGLEN = VERBOSE_LEN + MAXLOGMSGLEN } |
Public Member Functions | |
ACE_Log_Record (void) | |
ACE_Log_Record (ACE_Log_Priority lp, time_t time_stamp, long pid) | |
ACE_Log_Record (ACE_Log_Priority lp, const ACE_Time_Value &time_stamp, long pid) | |
~ACE_Log_Record (void) | |
Default dtor. | |
int | print (const ACE_TCHAR host_name[], u_long verbose_flag, FILE *fp=stderr) |
int | print (const ACE_TCHAR host_name[], u_long verbose_flag, ACE_OSTREAM_TYPE &stream) |
int | format_msg (const ACE_TCHAR host_name[], u_long verbose_flag, ACE_TCHAR *verbose_msg) |
void | encode (void) |
void | decode (void) |
ACE_UINT32 | type (void) const |
Get the type of the Log_Record. | |
void | type (ACE_UINT32) |
Set the type of the Log_Record. | |
u_long | priority (void) const |
void | priority (u_long num) |
long | length (void) const |
void | length (long) |
ACE_Time_Value | time_stamp (void) const |
Get the time stamp of the Log_Record. | |
void | time_stamp (const ACE_Time_Value &ts) |
Set the time stamp of the Log_Record. | |
long | pid (void) const |
Get the process id of the Log_Record. | |
void | pid (long) |
Set the process id of the Log_Record. | |
const ACE_TCHAR * | msg_data (void) const |
Get the message data of the Log_Record. | |
int | msg_data (const ACE_TCHAR *data) |
size_t | msg_data_len (void) const |
void | dump (void) const |
Dump the state of an object. | |
Static Public Member Functions | |
static const ACE_TCHAR * | priority_name (ACE_Log_Priority p) |
static void | priority_name (ACE_Log_Priority p, const ACE_TCHAR *name) |
IMPORTANT: name must be a statically allocated const ACE_TCHAR*. | |
Public Attributes | |
ACE_ALLOC_HOOK_DECLARE | |
Declare the dynamic allocation hooks. | |
Private Member Functions | |
void | round_up (void) |
Round up to the alignment restrictions. | |
ACE_Log_Record (const ACE_Log_Record &rhs) | |
disallow copying... | |
ACE_Log_Record & | operator= (const ACE_Log_Record &rhs) |
Private Attributes | |
ACE_INT32 | length_ |
ACE_UINT32 | type_ |
Type of logging record. | |
time_t | secs_ |
Time that the logging record was generated. | |
ACE_UINT32 | usecs_ |
ACE_UINT32 | pid_ |
Id of process that generated the logging record. | |
ACE_TCHAR * | msg_data_ |
Logging record data. | |
size_t | msg_data_size_ |
Allocated size of msg_data_ in ACE_TCHARs. |
Defines the structure of an ACE logging record.
Definition at line 37 of file Log_Record.h.
anonymous enum |
Definition at line 40 of file Log_Record.h.
{ /// Maximum size of a logging message. MAXLOGMSGLEN = ACE_MAXLOGMSGLEN+1, /// Most restrictive alignment. ALIGN_WORDB = 8, /// Size used by verbose mode. /// 20 (date) + 15 (host_name) + 10 (pid) + 10 (type) /// + 4 (@) ... + ? (progname) VERBOSE_LEN = 128, /// Maximum size of a logging message with the verbose headers MAXVERBOSELOGMSGLEN = VERBOSE_LEN + MAXLOGMSGLEN };
ACE_Log_Record::ACE_Log_Record | ( | void | ) |
Create a Log_Record and set its priority, time stamp, and process id.
Definition at line 196 of file Log_Record.cpp.
: length_ (0), type_ (0), secs_ (0), usecs_ (0), pid_ (0), msg_data_ (0), msg_data_size_ (0) { // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record"); ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]); if (0 != this->msg_data_) { this->msg_data_size_ = MAXLOGMSGLEN; this->msg_data_[0] = '\0'; } }
ACE_Log_Record::ACE_Log_Record | ( | ACE_Log_Priority | lp, | |
time_t | time_stamp, | |||
long | pid | |||
) |
Definition at line 143 of file Log_Record.cpp.
: length_ (0), type_ (ACE_UINT32 (lp)), secs_ (ts_sec), usecs_ (0), pid_ (ACE_UINT32 (p)), msg_data_ (0), msg_data_size_ (0) { // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record"); ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]); if (0 != this->msg_data_) { this->msg_data_size_ = MAXLOGMSGLEN; this->msg_data_[0] = '\0'; } }
ACE_Log_Record::ACE_Log_Record | ( | ACE_Log_Priority | lp, | |
const ACE_Time_Value & | time_stamp, | |||
long | pid | |||
) |
Definition at line 163 of file Log_Record.cpp.
: length_ (0), type_ (ACE_UINT32 (lp)), secs_ (ts.sec ()), usecs_ ((ACE_UINT32) ts.usec ()), pid_ (ACE_UINT32 (p)), msg_data_ (0), msg_data_size_ (0) { // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record"); ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]); if (0 != this->msg_data_) { this->msg_data_size_ = MAXLOGMSGLEN; this->msg_data_[0] = '\0'; } }
ACE_Log_Record::~ACE_Log_Record | ( | void | ) | [inline] |
Default dtor.
Definition at line 13 of file Log_Record.inl.
ACE_Log_Record::ACE_Log_Record | ( | const ACE_Log_Record & | rhs | ) | [private] |
disallow copying...
void ACE_Log_Record::decode | ( | void | ) | [inline] |
Decode the Log_Record
received from the network.
Definition at line 35 of file Log_Record.inl.
{ ACE_TRACE ("ACE_Log_Record::decode"); #if !defined (ACE_LACKS_NTOHL) ACE_Time_Value tv (this->secs_, ntohl (this->usecs_)); this->secs_ = tv.sec (); this->usecs_ = tv.usec (); this->type_ = ntohl (this->type_); this->pid_ = ntohl (this->pid_); this->length_ = ntohl (this->length_); #endif /* ACE_LACKS_NTOHL */ }
void ACE_Log_Record::dump | ( | void | ) | const |
Dump the state of an object.
Definition at line 106 of file Log_Record.cpp.
{ #if defined (ACE_HAS_DUMP) // ACE_TRACE ("ACE_Log_Record::dump"); ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("length_ = %d\n"), this->length_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntype_ = %u\n"), this->type_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntime_stamp_ = (%:, %d)\n"), this->secs_, this->usecs_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\npid_ = %u\n"), this->pid_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_data_ (0x%@) = %s\n"), this->msg_data_, this->msg_data_)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_data_size_ = %B\n"), this->msg_data_size_)); ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); #endif /* ACE_HAS_DUMP */ }
void ACE_Log_Record::encode | ( | void | ) | [inline] |
Encode the Log_Record
for transmission on the network.
Definition at line 20 of file Log_Record.inl.
{ ACE_TRACE ("ACE_Log_Record::encode"); this->length_ = ACE_HTONL (this->length_); this->type_ = ACE_HTONL (this->type_); // Make sure we don't enclose the sec() and usec() fields until // they've been normalized. // secs_ is commented out because it can be 64 bits. This method is // deprecated; use the CDR operations instead. // this->secs_ = ACE_HTONL (this->secs_); this->usecs_ = ACE_HTONL (this->usecs_); this->pid_ = ACE_HTONL (this->pid_); }
int ACE_Log_Record::format_msg | ( | const ACE_TCHAR | host_name[], | |
u_long | verbose_flag, | |||
ACE_TCHAR * | verbose_msg | |||
) |
Definition at line 215 of file Log_Record.cpp.
{ /* 0123456789012345678901234 */ /* Oct 18 14:25:36.000 1989<nul> */ ACE_TCHAR timestamp[26]; // Only used by VERBOSE and VERBOSE_LITE. // The sprintf format needs to be different for Windows and POSIX // in the wide-char case. #if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) const ACE_TCHAR *time_fmt = ACE_TEXT ("%s.%03ld %s"); const ACE_TCHAR *verbose_fmt = ACE_TEXT ("%s@%s@%u@%s@%s"); const ACE_TCHAR *verbose_lite_fmt = ACE_TEXT ("%s@%s@%s"); #else const ACE_TCHAR *time_fmt = ACE_TEXT ("%ls.%03ld %ls"); const ACE_TCHAR *verbose_fmt = ACE_TEXT ("%ls@%ls@%u@%ls@%ls"); const ACE_TCHAR *verbose_lite_fmt = ACE_TEXT ("%ls@%ls@%ls"); #endif if (ACE_BIT_ENABLED (verbose_flag, ACE_Log_Msg::VERBOSE) || ACE_BIT_ENABLED (verbose_flag, ACE_Log_Msg::VERBOSE_LITE)) { time_t const now = this->secs_; ACE_TCHAR ctp[26]; // 26 is a magic number... if (ACE_OS::ctime_r (&now, ctp, sizeof ctp / sizeof (ACE_TCHAR)) == 0) return -1; /* 01234567890123456789012345 */ /* Wed Oct 18 14:25:36 1989n0 */ ctp[19] = '\0'; // NUL-terminate after the time. ctp[24] = '\0'; // NUL-terminate after the date. ACE_OS::sprintf (timestamp, time_fmt, ctp + 4, ((long) this->usecs_) / 1000, ctp + 20); } if (ACE_BIT_ENABLED (verbose_flag, ACE_Log_Msg::VERBOSE)) { const ACE_TCHAR *lhost_name = ((host_name == 0) ? ACE_TEXT ("<local_host>") : host_name); ACE_OS::sprintf (verbose_msg, verbose_fmt, timestamp, lhost_name, this->pid_, ACE_Log_Record::priority_name (ACE_Log_Priority (this->type_)), this->msg_data_); } else if (ACE_BIT_ENABLED (verbose_flag, ACE_Log_Msg::VERBOSE_LITE)) ACE_OS::sprintf (verbose_msg, verbose_lite_fmt, timestamp, ACE_Log_Record::priority_name (ACE_Log_Priority (this->type_)), this->msg_data_); else ACE_OS::strcpy (verbose_msg, this->msg_data_); return 0; }
long ACE_Log_Record::length | ( | void | ) | const [inline] |
Get the total length of the Log_Record, which includes the size of the various data member fields.
Definition at line 65 of file Log_Record.inl.
void ACE_Log_Record::length | ( | long | l | ) | [inline] |
Set the total length of the Log_Record, which needs to account for the size of the various data member fields.
Definition at line 72 of file Log_Record.inl.
int ACE_Log_Record::msg_data | ( | const ACE_TCHAR * | data | ) |
Set the message data of the record. If data is longer than the current msg_data_ buffer, a new msg_data_ buffer is allocated to fit. If such a reallocation faisl, this method returns -1, else 0.
Definition at line 126 of file Log_Record.cpp.
{ // ACE_TRACE ("ACE_Log_Record::msg_data"); size_t const newlen = ACE_OS::strlen (data) + 1; // Will need room for '\0' if (newlen > this->msg_data_size_) { ACE_TCHAR *new_msg_data = 0; ACE_NEW_RETURN (new_msg_data, ACE_TCHAR[newlen], -1); delete [] this->msg_data_; this->msg_data_ = new_msg_data; this->msg_data_size_ = newlen; } ACE_OS::strcpy (this->msg_data_, data); this->round_up (); return 0; }
const ACE_TCHAR * ACE_Log_Record::msg_data | ( | void | ) | const [inline] |
Get the message data of the Log_Record.
Definition at line 108 of file Log_Record.inl.
size_t ACE_Log_Record::msg_data_len | ( | void | ) | const [inline] |
Get the size of the message data of the Log_Record, including a byte for the NUL.
Definition at line 115 of file Log_Record.inl.
{ ACE_TRACE ("ACE_Log_Record::msg_data_len"); return ACE_OS::strlen (this->msg_data_) + 1; }
ACE_Log_Record& ACE_Log_Record::operator= | ( | const ACE_Log_Record & | rhs | ) | [private] |
long ACE_Log_Record::pid | ( | void | ) | const [inline] |
Get the process id of the Log_Record.
Definition at line 94 of file Log_Record.inl.
void ACE_Log_Record::pid | ( | long | p | ) | [inline] |
Set the process id of the Log_Record.
Definition at line 101 of file Log_Record.inl.
int ACE_Log_Record::print | ( | const ACE_TCHAR | host_name[], | |
u_long | verbose_flag, | |||
ACE_OSTREAM_TYPE & | stream | |||
) |
Write the contents of the logging record to the appropriate stream if the corresponding type is enabled.
Definition at line 385 of file Log_Record.cpp.
{ if (ACE_LOG_MSG->log_priority_enabled (ACE_Log_Priority (this->type_))) { ACE_TCHAR* verbose_msg = 0; ACE_NEW_RETURN (verbose_msg, ACE_TCHAR[MAXVERBOSELOGMSGLEN], -1); int const result = this->format_msg (host_name, verbose_flag, verbose_msg); if (result == 0) { // Since ostream expects only chars, we cannot pass wchar_t's s << ACE_TEXT_ALWAYS_CHAR (verbose_msg); s.flush (); } delete [] verbose_msg; return result; } return 0; }
int ACE_Log_Record::print | ( | const ACE_TCHAR | host_name[], | |
u_long | verbose_flag, | |||
FILE * | fp = stderr | |||
) |
Write the contents of the logging record to the appropriate FILE if the corresponding type is enabled.
Definition at line 285 of file Log_Record.cpp.
{ if (ACE_LOG_MSG->log_priority_enabled (ACE_Log_Priority (this->type_))) { ACE_TCHAR *verbose_msg = 0; ACE_NEW_RETURN (verbose_msg, ACE_TCHAR[MAXVERBOSELOGMSGLEN], -1); int result = this->format_msg (host_name, verbose_flag, verbose_msg); if (result == 0) { if (fp != 0) { int const verbose_msg_len = static_cast<int> (ACE_OS::strlen (verbose_msg)); #if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR) int const fwrite_result = ACE_OS::fprintf (fp, ACE_TEXT ("%ls"), verbose_msg); #else int const fwrite_result = ACE_OS::fprintf (fp, ACE_TEXT ("%s"), verbose_msg); #endif // We should have written everything if (fwrite_result != verbose_msg_len) result = -1; else ACE_OS::fflush (fp); } } delete [] verbose_msg; return result; } else return 0; }
u_long ACE_Log_Record::priority | ( | void | ) | const |
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, as defined by the enums in ACE_Log_Priority).
Definition at line 85 of file Log_Record.cpp.
void ACE_Log_Record::priority | ( | u_long | num | ) |
Set the priority of the Log_Record <type_> (which must be a power of 2, as defined by the enums in ACE_Log_Priority).
Definition at line 96 of file Log_Record.cpp.
void ACE_Log_Record::priority_name | ( | ACE_Log_Priority | p, | |
const ACE_TCHAR * | name | |||
) | [static] |
IMPORTANT: name must be a statically allocated const ACE_TCHAR*.
Definition at line 77 of file Log_Record.cpp.
{ // Name must be a statically allocated string ace_priority_names[ACE::log2 (p)] = name; }
const ACE_TCHAR * ACE_Log_Record::priority_name | ( | ACE_Log_Priority | p | ) | [static] |
Returns a character array with the string form of the ACE_Log_Priority parameter. This is used for the verbose printing format.
Definition at line 71 of file Log_Record.cpp.
{ return ace_priority_names[ACE::log2 (p)]; }
void ACE_Log_Record::round_up | ( | void | ) | [private] |
Round up to the alignment restrictions.
Definition at line 184 of file Log_Record.cpp.
{ // ACE_TRACE ("ACE_Log_Record::round_up"); // Determine the length of the payload. size_t len = sizeof (*this) + (sizeof (ACE_TCHAR) * ((ACE_OS::strlen (this->msg_data_) + 1))); // Round up to the alignment. len = ((len + ACE_Log_Record::ALIGN_WORDB - 1) & ~(ACE_Log_Record::ALIGN_WORDB - 1)); this->length_ = static_cast<ACE_UINT32> (len); }
void ACE_Log_Record::time_stamp | ( | const ACE_Time_Value & | ts | ) | [inline] |
ACE_Time_Value ACE_Log_Record::time_stamp | ( | void | ) | const [inline] |
Get the time stamp of the Log_Record.
Definition at line 79 of file Log_Record.inl.
{ ACE_TRACE ("ACE_Log_Record::time_stamp"); return ACE_Time_Value (this->secs_, (long) this->usecs_); }
ACE_UINT32 ACE_Log_Record::type | ( | void | ) | const [inline] |
Get the type of the Log_Record.
Definition at line 51 of file Log_Record.inl.
void ACE_Log_Record::type | ( | ACE_UINT32 | t | ) | [inline] |
Set the type of the Log_Record.
Definition at line 58 of file Log_Record.inl.
Declare the dynamic allocation hooks.
Definition at line 180 of file Log_Record.h.
ACE_INT32 ACE_Log_Record::length_ [private] |
Total length of the logging record in bytes. This field *must* come first in order for various IPC framing mechanisms to work correctly. In addition, the field must be an ACE_INT32 in order to be passed portably across platforms.
Definition at line 192 of file Log_Record.h.
ACE_TCHAR* ACE_Log_Record::msg_data_ [private] |
Logging record data.
Definition at line 205 of file Log_Record.h.
size_t ACE_Log_Record::msg_data_size_ [private] |
Allocated size of msg_data_ in ACE_TCHARs.
Definition at line 208 of file Log_Record.h.
ACE_UINT32 ACE_Log_Record::pid_ [private] |
Id of process that generated the logging record.
Definition at line 202 of file Log_Record.h.
time_t ACE_Log_Record::secs_ [private] |
Time that the logging record was generated.
Definition at line 198 of file Log_Record.h.
ACE_UINT32 ACE_Log_Record::type_ [private] |
Type of logging record.
Definition at line 195 of file Log_Record.h.
ACE_UINT32 ACE_Log_Record::usecs_ [private] |
Definition at line 199 of file Log_Record.h.