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,#if!defined(ACE_HAS_WINCE) 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 | |
| FILE * | fp |
| 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.
00041 { 00042 /// Maximum size of a logging message. 00043 MAXLOGMSGLEN = ACE_MAXLOGMSGLEN+1, 00044 00045 /// Most restrictive alignment. 00046 ALIGN_WORDB = 8, 00047 00048 /// Size used by verbose mode. 00049 /// 20 (date) + 15 (host_name) + 10 (pid) + 10 (type) 00050 /// + 4 (@) ... + ? (progname) 00051 VERBOSE_LEN = 128, 00052 00053 /// Maximum size of a logging message with the verbose headers 00054 MAXVERBOSELOGMSGLEN = VERBOSE_LEN + MAXLOGMSGLEN 00055 };
| 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.
00197 : length_ (0), 00198 type_ (0), 00199 secs_ (0), 00200 usecs_ (0), 00201 pid_ (0), 00202 msg_data_ (0), 00203 msg_data_size_ (0) 00204 { 00205 // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record"); 00206 ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]); 00207 if (0 != this->msg_data_) 00208 { 00209 this->msg_data_size_ = MAXLOGMSGLEN; 00210 this->msg_data_[0] = '\0'; 00211 } 00212 }
| 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.
00146 : length_ (0), 00147 type_ (ACE_UINT32 (lp)), 00148 secs_ (ts_sec), 00149 usecs_ (0), 00150 pid_ (ACE_UINT32 (p)), 00151 msg_data_ (0), 00152 msg_data_size_ (0) 00153 { 00154 // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record"); 00155 ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]); 00156 if (0 != this->msg_data_) 00157 { 00158 this->msg_data_size_ = MAXLOGMSGLEN; 00159 this->msg_data_[0] = '\0'; 00160 } 00161 }
| 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.
00166 : length_ (0), 00167 type_ (ACE_UINT32 (lp)), 00168 secs_ (ts.sec ()), 00169 usecs_ ((ACE_UINT32) ts.usec ()), 00170 pid_ (ACE_UINT32 (p)), 00171 msg_data_ (0), 00172 msg_data_size_ (0) 00173 { 00174 // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record"); 00175 ACE_NEW_NORETURN (this->msg_data_, ACE_TCHAR[MAXLOGMSGLEN]); 00176 if (0 != this->msg_data_) 00177 { 00178 this->msg_data_size_ = MAXLOGMSGLEN; 00179 this->msg_data_[0] = '\0'; 00180 } 00181 }
| ACE_Log_Record::~ACE_Log_Record | ( | void | ) |
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 | ) |
Decode the Log_Record received from the network.
Definition at line 35 of file Log_Record.inl.
00036 { 00037 ACE_TRACE ("ACE_Log_Record::decode"); 00038 #if !defined (ACE_LACKS_NTOHL) 00039 ACE_Time_Value tv (this->secs_, 00040 ntohl (this->usecs_)); 00041 00042 this->secs_ = tv.sec (); 00043 this->usecs_ = tv.usec (); 00044 this->type_ = ntohl (this->type_); 00045 this->pid_ = ntohl (this->pid_); 00046 this->length_ = ntohl (this->length_); 00047 #endif /* ACE_LACKS_NTOHL */ 00048 }
| void ACE_Log_Record::dump | ( | void | ) | const |
Dump the state of an object.
Definition at line 106 of file Log_Record.cpp.
00107 { 00108 #if defined (ACE_HAS_DUMP) 00109 // ACE_TRACE ("ACE_Log_Record::dump"); 00110 00111 ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this)); 00112 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("length_ = %d\n"), this->length_)); 00113 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntype_ = %u\n"), this->type_)); 00114 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\ntime_stamp_ = (%:, %d)\n"), 00115 this->secs_, this->usecs_)); 00116 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\npid_ = %u\n"), this->pid_)); 00117 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_data_ (0x%@) = %s\n"), 00118 this->msg_data_, this->msg_data_)); 00119 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nmsg_data_size_ = %B\n"), 00120 this->msg_data_size_)); 00121 ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP)); 00122 #endif /* ACE_HAS_DUMP */ 00123 }
| void ACE_Log_Record::encode | ( | void | ) |
Encode the Log_Record for transmission on the network.
Definition at line 20 of file Log_Record.inl.
00021 { 00022 ACE_TRACE ("ACE_Log_Record::encode"); 00023 this->length_ = ACE_HTONL (this->length_); 00024 this->type_ = ACE_HTONL (this->type_); 00025 // Make sure we don't enclose the sec() and usec() fields until 00026 // they've been normalized. 00027 // secs_ is commented out because it can be 64 bits. This method is 00028 // deprecated; use the CDR operations instead. 00029 // this->secs_ = ACE_HTONL (this->secs_); 00030 this->usecs_ = ACE_HTONL (this->usecs_); 00031 this->pid_ = ACE_HTONL (this->pid_); 00032 }
| 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.
00218 { 00219 /* 0123456789012345678901234 */ 00220 /* Oct 18 14:25:36.000 1989<nul> */ 00221 ACE_TCHAR timestamp[26]; // Only used by VERBOSE and VERBOSE_LITE. 00222 00223 // The sprintf format needs to be different for Windows and POSIX 00224 // in the wide-char case. 00225 #if defined (ACE_WIN32) || !defined (ACE_USES_WCHAR) 00226 const ACE_TCHAR *time_fmt = ACE_TEXT ("%s.%03ld %s"); 00227 const ACE_TCHAR *verbose_fmt = ACE_TEXT ("%s@%s@%u@%s@%s"); 00228 const ACE_TCHAR *verbose_lite_fmt = ACE_TEXT ("%s@%s@%s"); 00229 #else 00230 const ACE_TCHAR *time_fmt = ACE_TEXT ("%ls.%03ld %ls"); 00231 const ACE_TCHAR *verbose_fmt = ACE_TEXT ("%ls@%ls@%u@%ls@%ls"); 00232 const ACE_TCHAR *verbose_lite_fmt = ACE_TEXT ("%ls@%ls@%ls"); 00233 #endif 00234 00235 if (ACE_BIT_ENABLED (verbose_flag, 00236 ACE_Log_Msg::VERBOSE) 00237 || ACE_BIT_ENABLED (verbose_flag, 00238 ACE_Log_Msg::VERBOSE_LITE)) 00239 { 00240 time_t const now = this->secs_; 00241 ACE_TCHAR ctp[26]; // 26 is a magic number... 00242 00243 if (ACE_OS::ctime_r (&now, ctp, sizeof ctp / sizeof (ACE_TCHAR)) == 0) 00244 return -1; 00245 00246 /* 01234567890123456789012345 */ 00247 /* Wed Oct 18 14:25:36 1989n0 */ 00248 00249 ctp[19] = '\0'; // NUL-terminate after the time. 00250 ctp[24] = '\0'; // NUL-terminate after the date. 00251 00252 ACE_OS::sprintf (timestamp, 00253 time_fmt, 00254 ctp + 4, 00255 ((long) this->usecs_) / 1000, 00256 ctp + 20); 00257 } 00258 00259 if (ACE_BIT_ENABLED (verbose_flag, 00260 ACE_Log_Msg::VERBOSE)) 00261 { 00262 const ACE_TCHAR *lhost_name = ((host_name == 0) 00263 ? ACE_TEXT ("<local_host>") 00264 : host_name); 00265 ACE_OS::sprintf (verbose_msg, 00266 verbose_fmt, 00267 timestamp, 00268 lhost_name, 00269 this->pid_, 00270 ACE_Log_Record::priority_name (ACE_Log_Priority (this->type_)), 00271 this->msg_data_); 00272 } 00273 else if (ACE_BIT_ENABLED (verbose_flag, ACE_Log_Msg::VERBOSE_LITE)) 00274 ACE_OS::sprintf (verbose_msg, 00275 verbose_lite_fmt, 00276 timestamp, 00277 ACE_Log_Record::priority_name (ACE_Log_Priority (this->type_)), 00278 this->msg_data_); 00279 else 00280 ACE_OS::strcpy (verbose_msg, this->msg_data_); 00281 return 0; 00282 }
| void ACE_Log_Record::length | ( | long | l | ) |
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.
| long ACE_Log_Record::length | ( | void | ) | const |
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.
| 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.
00127 { 00128 // ACE_TRACE ("ACE_Log_Record::msg_data"); 00129 size_t const newlen = ACE_OS::strlen (data) + 1; // Will need room for '\0' 00130 if (newlen > this->msg_data_size_) 00131 { 00132 ACE_TCHAR *new_msg_data = 0; 00133 ACE_NEW_RETURN (new_msg_data, ACE_TCHAR[newlen], -1); 00134 delete [] this->msg_data_; 00135 this->msg_data_ = new_msg_data; 00136 this->msg_data_size_ = newlen; 00137 } 00138 ACE_OS::strcpy (this->msg_data_, data); 00139 this->round_up (); 00140 return 0; 00141 }
| const ACE_TCHAR * ACE_Log_Record::msg_data | ( | void | ) | const |
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 |
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.
00116 { 00117 ACE_TRACE ("ACE_Log_Record::msg_data_len"); 00118 return ACE_OS::strlen (this->msg_data_) + 1; 00119 }
| ACE_Log_Record& ACE_Log_Record::operator= | ( | const ACE_Log_Record & | rhs | ) | [private] |
| void ACE_Log_Record::pid | ( | long | p | ) |
Set the process id of the <Log_Record>.
Definition at line 101 of file Log_Record.inl.
| long ACE_Log_Record::pid | ( | void | ) | const |
Get the process id of the <Log_Record>.
Definition at line 94 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.
00388 { 00389 if (ACE_LOG_MSG->log_priority_enabled (ACE_Log_Priority (this->type_))) 00390 { 00391 ACE_TCHAR* verbose_msg = 0; 00392 ACE_NEW_RETURN (verbose_msg, ACE_TCHAR[MAXVERBOSELOGMSGLEN], -1); 00393 00394 int const result = this->format_msg (host_name, verbose_flag, verbose_msg); 00395 00396 if (result == 0) 00397 { 00398 // Since ostream expects only chars, we cannot pass wchar_t's 00399 s << ACE_TEXT_ALWAYS_CHAR (verbose_msg); 00400 s.flush (); 00401 } 00402 00403 delete [] verbose_msg; 00404 00405 return result; 00406 } 00407 return 0; 00408 }
| int ACE_Log_Record::print | ( | const ACE_TCHAR | host_name[], | |
| u_long | verbose_flag, | |||
| #if!defined(ACE_HAS_WINCE) FILE * | fp = stderr | |||
| ) |
Write the contents of the logging record to the appropriate <FILE> if the corresponding type is enabled.
| 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.
| 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.
00086 { 00087 ACE_TRACE ("ACE_Log_Record::priority"); 00088 00089 // Get the priority of the <Log_Record> <type_>. This is computed 00090 // as the base 2 logarithm of <type_> (which must be a power of 2, 00091 // as defined by the enums in <ACE_Log_Priority>). 00092 return ACE::log2 ((u_long) this->type_); 00093 }
| 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.
00079 { 00080 // Name must be a statically allocated string 00081 ace_priority_names[ACE::log2 (p)] = name; 00082 }
| 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.
00072 { 00073 return ace_priority_names[ACE::log2 (p)]; 00074 }
| void ACE_Log_Record::round_up | ( | void | ) | [private] |
Round up to the alignment restrictions.
Definition at line 184 of file Log_Record.cpp.
00185 { 00186 // ACE_TRACE ("ACE_Log_Record::round_up"); 00187 // Determine the length of the payload. 00188 size_t len = sizeof (*this) + (sizeof (ACE_TCHAR) * ((ACE_OS::strlen (this->msg_data_) + 1))); 00189 00190 // Round up to the alignment. 00191 len = ((len + ACE_Log_Record::ALIGN_WORDB - 1) 00192 & ~(ACE_Log_Record::ALIGN_WORDB - 1)); 00193 this->length_ = static_cast<ACE_UINT32> (len); 00194 }
| void ACE_Log_Record::time_stamp | ( | const ACE_Time_Value & | ts | ) |
| ACE_Time_Value ACE_Log_Record::time_stamp | ( | void | ) | const |
Get the time stamp of the <Log_Record>.
Definition at line 79 of file Log_Record.inl.
00080 { 00081 ACE_TRACE ("ACE_Log_Record::time_stamp"); 00082 return ACE_Time_Value (this->secs_, (long) this->usecs_); 00083 }
| void ACE_Log_Record::type | ( | ACE_UINT32 | t | ) |
Set the type of the <Log_Record>.
Definition at line 58 of file Log_Record.inl.
| ACE_UINT32 ACE_Log_Record::type | ( | void | ) | const |
Get the type of the <Log_Record>.
Definition at line 51 of file Log_Record.inl.
Declare the dynamic allocation hooks.
Definition at line 175 of file Log_Record.h.
| FILE* ACE_Log_Record::fp |
Definition at line 81 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 187 of file Log_Record.h.
ACE_TCHAR* ACE_Log_Record::msg_data_ [private] |
Logging record data.
Definition at line 200 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 203 of file Log_Record.h.
ACE_UINT32 ACE_Log_Record::pid_ [private] |
Id of process that generated the logging record.
Definition at line 197 of file Log_Record.h.
time_t ACE_Log_Record::secs_ [private] |
Time that the logging record was generated.
Definition at line 193 of file Log_Record.h.
ACE_UINT32 ACE_Log_Record::type_ [private] |
Type of logging record.
Definition at line 190 of file Log_Record.h.
ACE_UINT32 ACE_Log_Record::usecs_ [private] |
Definition at line 194 of file Log_Record.h.
1.6.1