Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Log_Record Class Reference

Defines the structure of an ACE logging record. More...

#include <Log_Record.h>

List of all members.

Public Types

enum  { MAXLOGMSGLEN = ACE_MAXLOGMSGLEN, ALIGN_WORDB = 8, VERBOSE_LEN = 128, MAXVERBOSELOGMSGLEN = VERBOSE_LEN + MAXLOGMSGLEN }

Public Methods

 ACE_Log_Record (void)
 ACE_Log_Record (ACE_Log_Priority lp, long 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. More...

int print (const ACE_TCHAR host_name[], u_long verbose_flag, FILE *fp=stderr)
 Write the contents of the logging record to the appropriate <FILE>. More...

int print (const ACE_TCHAR host_name[], u_long verbose_flag, ostream &stream)
 Write the contents of the logging record to the appropriate <ostream>. More...

int format_msg (const ACE_TCHAR host_name[], u_long verbose_flag, ACE_TCHAR *verbose_msg)
void encode (void)
 Encode the <Log_Record> for transmission on the network. More...

void decode (void)
 Decode the <Log_Record> received from the network. More...

long type (void) const
 Get the type of the <Log_Record>. More...

void type (long)
 Set the type of the <Log_Record>. More...

u_long priority (void) const
void 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>). More...

long length (void) const
 Get the length of the <Log_Record>. More...

void length (long)
 Set the length of the <Log_Record>. More...

ACE_Time_Value time_stamp (void) const
 Get the time stamp of the <Log_Record>. More...

void time_stamp (const ACE_Time_Value &)
 Set the time stamp of the <Log_Record>. More...

long pid (void) const
 Get the process id of the <Log_Record>. More...

void pid (long)
 Set the process id of the <Log_Record>. More...

const ACE_TCHARmsg_data (void) const
 Get the message data of the <Log_Record>. More...

void msg_data (const ACE_TCHAR *data)
 Set the message data of the <Log_Record>. More...

size_t msg_data_len (void) const
 Get the size of the message data of the <Log_Record>, including a byte for the NUL. More...

void dump (void) const
 Dump the state of an object. More...


Static Public Methods

const ACE_TCHARpriority_name (ACE_Log_Priority p)
void priority_name (ACE_Log_Priority p, const ACE_TCHAR *name)

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks. More...


Private Methods

void round_up (void)
 Round up to the alignment restrictions. More...


Private Attributes

ACE_INT32 length_
ACE_UINT32 type_
 Type of logging record. More...

ACE_UINT32 secs_
 Time that the logging record was generated. More...

ACE_UINT32 usecs_
ACE_UINT32 pid_
 Id of process that generated the logging record. More...

ACE_TCHAR msg_data_ [MAXLOGMSGLEN+1]
 Logging record data. More...


Static Private Attributes

const ACE_TCHARpriority_names_ []
 Symbolic names for the <ACE_Log_Priority> enums. More...


Detailed Description

Defines the structure of an ACE logging record.

Definition at line 28 of file Log_Record.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
MAXLOGMSGLEN  Maximum size of a logging message.
ALIGN_WORDB  Most restrictive alignment.
VERBOSE_LEN  Size used by verbose mode. 20 (date) + 15 (host_name) + 10 (pid) + 10 (type) + 4 (@) ... + ? (progname).
MAXVERBOSELOGMSGLEN  Maximum size of a logging message with the verbose headers.

Definition at line 31 of file Log_Record.h.

00032   {
00033     /// Maximum size of a logging message.
00034     MAXLOGMSGLEN = ACE_MAXLOGMSGLEN,
00035 
00036     /// Most restrictive alignment.
00037     ALIGN_WORDB  = 8,
00038 
00039     /// Size used by verbose mode.
00040     /// 20 (date) + 15 (host_name) + 10 (pid) + 10 (type)
00041     ///           + 4 (@) ... + ? (progname)
00042     VERBOSE_LEN = 128,
00043 
00044     /// Maximum size of a logging message with the verbose headers
00045     MAXVERBOSELOGMSGLEN = VERBOSE_LEN + MAXLOGMSGLEN
00046   };


Constructor & Destructor Documentation

ACE_Log_Record::ACE_Log_Record void   
 

Create a <Log_Record> and set its priority, time stamp, and process id. Create a <Log_Record> and set its priority, time stamp, and process id.

Definition at line 153 of file Log_Record.cpp.

00154   : length_ (0),
00155     type_ (0),
00156     secs_ (0),
00157     usecs_ (0),
00158     pid_ (0)
00159 {
00160   // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
00161 }

ACE_Log_Record::ACE_Log_Record ACE_Log_Priority    lp,
long    time_stamp,
long    pid
 

Definition at line 115 of file Log_Record.cpp.

References ACE_Log_Priority.

00118   : length_ (0),
00119     type_ (ACE_UINT32 (lp)),
00120     secs_ (ts_sec),
00121     usecs_ (0),
00122     pid_ (ACE_UINT32 (p))
00123 {
00124   // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
00125 }

ACE_Log_Record::ACE_Log_Record ACE_Log_Priority    lp,
const ACE_Time_Value   time_stamp,
long    pid
 

Definition at line 127 of file Log_Record.cpp.

References ACE_Log_Priority.

00130   : length_ (0),
00131     type_ (ACE_UINT32 (lp)),
00132     secs_ ((ACE_UINT32) ts.sec ()),
00133     usecs_ ((ACE_UINT32) ts.usec ()),
00134     pid_ (ACE_UINT32 (p))
00135 {
00136   // ACE_TRACE ("ACE_Log_Record::ACE_Log_Record");
00137 }

ASYS_INLINE ACE_Log_Record::~ACE_Log_Record void   
 

Default dtor.

Definition at line 7 of file Log_Record.i.

00008 {
00009 }


Member Function Documentation

ASYS_INLINE void ACE_Log_Record::decode void   
 

Decode the <Log_Record> received from the network.

Definition at line 25 of file Log_Record.i.

References ACE_TRACE, length_, pid_, ACE_Time_Value::sec, secs_, type_, ACE_Time_Value::usec, and usecs_.

00026 {
00027   ACE_TRACE ("ACE_Log_Record::decode");
00028   ACE_Time_Value tv (ntohl (this->secs_),
00029                      ntohl (this->usecs_));
00030 
00031   this->secs_ = tv.sec ();
00032   this->usecs_ = tv.usec ();
00033   this->type_ = ntohl (this->type_);
00034   this->pid_ = ntohl (this->pid_);
00035   this->length_ = ntohl (this->length_);
00036 }

void ACE_Log_Record::dump void    const
 

Dump the state of an object.

Definition at line 93 of file Log_Record.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_LIB_TEXT, and LM_DEBUG.

00094 {
00095   // ACE_TRACE ("ACE_Log_Record::dump");
00096 
00097   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00098   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("length_ = %d\n"), this->length_));
00099   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ntype_ = %u\n"), this->type_));
00100   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\ntime_stamp_ = (%d, %d)\n"), this->secs_, this->usecs_));
00101   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\npid_ = %u\n"), this->pid_));
00102   ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("\nmsg_data_ = %s\n"), this->msg_data_));
00103   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00104 }

ASYS_INLINE void ACE_Log_Record::encode void   
 

Encode the <Log_Record> for transmission on the network.

Definition at line 12 of file Log_Record.i.

References ACE_TRACE, length_, pid_, secs_, type_, and usecs_.

00013 {
00014   ACE_TRACE ("ACE_Log_Record::encode");
00015   this->length_ = htonl (this->length_);
00016   this->type_ = htonl (this->type_);
00017   // Make sure we don't enclose the sec() and usec() fields until
00018   // they've been normalized.
00019   this->secs_ = htonl (this->secs_);
00020   this->usecs_ = htonl (this->usecs_);
00021   this->pid_ = htonl (this->pid_);
00022 }

int ACE_Log_Record::format_msg const ACE_TCHAR    host_name[],
u_long    verbose_flag,
ACE_TCHAR   verbose_msg
 

Definition at line 164 of file Log_Record.cpp.

References ACE_BIT_ENABLED, ACE_LIB_TEXT, ACE_Log_Priority, ACE_TCHAR, ACE_OS::ctime_r, priority_name, secs_, ACE_OS::sprintf, ACE_Log_Msg::VERBOSE, and ACE_Log_Msg::VERBOSE_LITE.

Referenced by print.

00167 {
00168   /* 0123456789012345678901234     */
00169   /* Oct 18 14:25:36.000 1989<nul> */
00170   ACE_TCHAR timestamp[26]; // Only used by VERBOSE and VERBOSE_LITE.
00171 
00172   if (ACE_BIT_ENABLED (verbose_flag,
00173                        ACE_Log_Msg::VERBOSE)
00174       || ACE_BIT_ENABLED (verbose_flag,
00175                           ACE_Log_Msg::VERBOSE_LITE))
00176     {
00177       time_t now = this->secs_;
00178       ACE_TCHAR ctp[26]; // 26 is a magic number...
00179 
00180       if (ACE_OS::ctime_r (&now, ctp, sizeof ctp) == 0)
00181         return -1;
00182 
00183       /* 01234567890123456789012345 */
00184       /* Wed Oct 18 14:25:36 1989n0 */
00185 
00186       ctp[19] = '\0'; // NUL-terminate after the time.
00187       ctp[24] = '\0'; // NUL-terminate after the date.
00188 
00189       ACE_OS::sprintf (timestamp,
00190                        ACE_LIB_TEXT ("%s.%03ld %s"),
00191                        ctp + 4,
00192                        ((long) this->usecs_) / 1000,
00193                        ctp + 20);
00194     }
00195 
00196   if (ACE_BIT_ENABLED (verbose_flag,
00197                        ACE_Log_Msg::VERBOSE))
00198     {
00199 # if defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS)
00200       const ACE_TCHAR *lhost_name =  (const ACE_TCHAR *) ((host_name == 0)
00201                                                             ? ((char *) ACE_LIB_TEXT ("<local_host>"))
00202                                                             : ((char *) host_name));
00203 # else /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */
00204       const ACE_TCHAR *lhost_name = ((host_name == 0)
00205                                       ? ACE_LIB_TEXT ("<local_host>")
00206                                       : host_name);
00207 # endif /* ! defined (ACE_HAS_BROKEN_CONDITIONAL_STRING_CASTS) */
00208       ACE_OS::sprintf (verbose_msg,
00209                        ACE_LIB_TEXT ("%s@%s@%u@%s@%s"),
00210                        timestamp,
00211                        lhost_name,
00212                        this->pid_,
00213                        ACE_Log_Record::priority_name (ACE_Log_Priority (this->type_)),
00214                        this->msg_data_);
00215     }
00216   else if (ACE_BIT_ENABLED (verbose_flag, ACE_Log_Msg::VERBOSE_LITE))
00217     ACE_OS::sprintf (verbose_msg,
00218                      ACE_LIB_TEXT ("%s@%s@%s"),
00219                      timestamp,
00220                      ACE_Log_Record::priority_name (ACE_Log_Priority (this->type_)),
00221                      this->msg_data_);
00222   else
00223     ACE_OS::sprintf (verbose_msg,
00224                      ACE_LIB_TEXT ("%s"),
00225                      this->msg_data_);
00226   return 0;
00227 }

ASYS_INLINE void ACE_Log_Record::length long   
 

Set the length of the <Log_Record>.

Definition at line 60 of file Log_Record.i.

References ACE_TRACE, and length_.

00061 {
00062   ACE_TRACE ("ACE_Log_Record::length");
00063   this->length_ = ACE_static_cast (ACE_UINT32, l);
00064 }

ASYS_INLINE long ACE_Log_Record::length void    const
 

Get the length of the <Log_Record>.

Definition at line 53 of file Log_Record.i.

References ACE_TRACE, and length_.

Referenced by ACE_Log_Msg_IPC::log.

00054 {
00055   ACE_TRACE ("ACE_Log_Record::length");
00056   return (long) this->length_;
00057 }

void ACE_Log_Record::msg_data const ACE_TCHAR   data
 

Set the message data of the <Log_Record>.

Definition at line 107 of file Log_Record.cpp.

References ACE_TCHAR, round_up, and ACE_OS_String::strsncpy.

00108 {
00109   // ACE_TRACE ("ACE_Log_Record::msg_data");
00110   ACE_OS::strsncpy (this->msg_data_, data,
00111                     (sizeof this->msg_data_ / sizeof (ACE_TCHAR)));
00112   this->round_up ();
00113 }

ASYS_INLINE const ACE_TCHAR * ACE_Log_Record::msg_data void    const
 

Get the message data of the <Log_Record>.

Definition at line 96 of file Log_Record.i.

References ACE_TRACE, and msg_data_.

Referenced by ACE_Log_Msg::log.

00097 {
00098   ACE_TRACE ("ACE_Log_Record::msg_data");
00099   return this->msg_data_;
00100 }

ASYS_INLINE 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 103 of file Log_Record.i.

References ACE_TRACE, and ACE_OS_String::strlen.

00104 {
00105   ACE_TRACE ("ACE_Log_Record::msg_data_len");
00106   return ACE_OS::strlen (this->msg_data_) + 1;
00107 }

ASYS_INLINE void ACE_Log_Record::pid long   
 

Set the process id of the <Log_Record>.

Definition at line 89 of file Log_Record.i.

References ACE_TRACE, and pid_.

00090 {
00091   ACE_TRACE ("ACE_Log_Record::pid");
00092   this->pid_ = (ACE_UINT32) p;
00093 }

ASYS_INLINE long ACE_Log_Record::pid void    const
 

Get the process id of the <Log_Record>.

Definition at line 82 of file Log_Record.i.

References ACE_TRACE, and pid_.

00083 {
00084   ACE_TRACE ("ACE_Log_Record::pid");
00085   return (long) this->pid_;
00086 }

int ACE_Log_Record::print const ACE_TCHAR    host_name[],
u_long    verbose_flag,
ostream &    stream
 

Write the contents of the logging record to the appropriate <ostream>.

Definition at line 261 of file Log_Record.cpp.

References ACE_TCHAR, ACE_TEXT_ALWAYS_CHAR, format_msg, and MAXVERBOSELOGMSGLEN.

00264 {
00265   ACE_TCHAR verbose_msg [MAXVERBOSELOGMSGLEN];
00266   int result = this->format_msg (host_name, verbose_flag, verbose_msg);
00267 
00268   if (result == 0)
00269     {
00270       // Since ostream expects only chars, we cannot pass wchar_t's
00271       s << ACE_TEXT_ALWAYS_CHAR (verbose_msg);
00272       s.flush ();
00273     }
00274 
00275   return result;
00276 }

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>.

Definition at line 230 of file Log_Record.cpp.

References ACE_LIB_TEXT, ACE_TCHAR, ACE_OS::fflush, format_msg, ACE_OS::fprintf, MAXVERBOSELOGMSGLEN, and ACE_OS_String::strlen.

Referenced by ACE_Log_Msg::log.

00233 {
00234   ACE_TCHAR verbose_msg [MAXVERBOSELOGMSGLEN];
00235   int result = this->format_msg (host_name,
00236                                  verbose_flag,
00237                                  verbose_msg);
00238 
00239   if (result == 0)
00240     {
00241       if (fp != 0)
00242         {
00243           int verbose_msg_len = ACE_static_cast (int,
00244                                                  ACE_OS::strlen (verbose_msg));
00245           int fwrite_result = ACE_OS::fprintf (fp, ACE_LIB_TEXT ("%s"), verbose_msg);
00246 
00247           // We should have written everything
00248           if (fwrite_result != verbose_msg_len)
00249             result = -1;
00250           else
00251             ACE_OS::fflush (fp);
00252         }
00253     }
00254 
00255   return result;
00256 }

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 83 of file Log_Record.cpp.

References ACE_TRACE, and type_.

00084 {
00085   ACE_TRACE ("ACE_Log_Record::priority");
00086 
00087   // Set the priority of the <Log_Record> <type_> (which must be a
00088   // power of 2, as defined by the enums in <ACE_Log_Priority>).
00089   this->type_ = (ACE_UINT32) p;
00090 }

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 72 of file Log_Record.cpp.

References ACE_TRACE, and ACE::log2.

Referenced by ACE_Log_Msg_IPC::log.

00073 {
00074   ACE_TRACE ("ACE_Log_Record::priority");
00075 
00076   // Get the priority of the <Log_Record> <type_>.  This is computed
00077   // as the base 2 logarithm of <type_> (which must be a power of 2,
00078   // as defined by the enums in <ACE_Log_Priority>).
00079   return ACE::log2 ((u_long) this->type_);
00080 }

void ACE_Log_Record::priority_name ACE_Log_Priority    p,
const ACE_TCHAR   name
[static]
 

Definition at line 64 of file Log_Record.cpp.

References ACE_Log_Priority, ACE_TCHAR, ACE::log2, and priority_names_.

00066 {
00067   // Name must be a statically allocated string
00068   ACE_Log_Record::priority_names_[ACE::log2 (p)] = name;
00069 }

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 58 of file Log_Record.cpp.

References ACE_Log_Priority, ACE::log2, and priority_names_.

Referenced by format_msg, and ACE_Log_Msg::log.

00059 {
00060   return ACE_Log_Record::priority_names_[ACE::log2 (p)];
00061 }

void ACE_Log_Record::round_up void    [private]
 

Round up to the alignment restrictions.

Definition at line 140 of file Log_Record.cpp.

References ALIGN_WORDB, length_, msg_data_, and ACE_OS_String::strlen.

Referenced by msg_data.

00141 {
00142   // ACE_TRACE ("ACE_Log_Record::round_up");
00143   // Determine the length of the payload.
00144   size_t len = (sizeof (*this) - sizeof (this->msg_data_))
00145     + (sizeof (ACE_TCHAR) * ((ACE_OS::strlen (this->msg_data_) + 1)));
00146 
00147   // Round up to the alignment.
00148   len = ((len + ACE_Log_Record::ALIGN_WORDB - 1)
00149          & ~(ACE_Log_Record::ALIGN_WORDB - 1));
00150   this->length_ = ACE_static_cast (ACE_UINT32, len);
00151 }

ASYS_INLINE void ACE_Log_Record::time_stamp const ACE_Time_Value  
 

Set the time stamp of the <Log_Record>.

Definition at line 74 of file Log_Record.i.

References ACE_TRACE, ACE_Time_Value::sec, secs_, ACE_Time_Value::usec, and usecs_.

00075 {
00076   ACE_TRACE ("ACE_Log_Record::time_stamp");
00077   this->secs_ = (ACE_UINT32) ts.sec ();
00078   this->usecs_ = (ACE_UINT32) ts.usec ();
00079 }

ASYS_INLINE ACE_Time_Value ACE_Log_Record::time_stamp void    const
 

Get the time stamp of the <Log_Record>.

Definition at line 67 of file Log_Record.i.

References ACE_TRACE.

00068 {
00069   ACE_TRACE ("ACE_Log_Record::time_stamp");
00070   return ACE_Time_Value ((long) this->secs_, (long) this->usecs_);
00071 }

ASYS_INLINE void ACE_Log_Record::type long   
 

Set the type of the <Log_Record>.

Definition at line 46 of file Log_Record.i.

References ACE_TRACE, and type_.

00047 {
00048   ACE_TRACE ("ACE_Log_Record::type");
00049   this->type_ = (ACE_UINT32) t;
00050 }

ASYS_INLINE long ACE_Log_Record::type void    const
 

Get the type of the <Log_Record>.

Definition at line 39 of file Log_Record.i.

References ACE_TRACE, and type_.

00040 {
00041   ACE_TRACE ("ACE_Log_Record::type");
00042   return (long) this->type_;
00043 }


Member Data Documentation

ACE_Log_Record::ACE_ALLOC_HOOK_DECLARE
 

Declare the dynamic allocation hooks.

Definition at line 158 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 170 of file Log_Record.h.

Referenced by decode, encode, length, and round_up.

ACE_TCHAR ACE_Log_Record::msg_data_[MAXLOGMSGLEN + 1] [private]
 

Logging record data.

Definition at line 183 of file Log_Record.h.

Referenced by msg_data, and round_up.

ACE_UINT32 ACE_Log_Record::pid_ [private]
 

Id of process that generated the logging record.

Definition at line 180 of file Log_Record.h.

Referenced by decode, encode, and pid.

const ACE_TCHAR * ACE_Log_Record::priority_names_ [static, private]
 

Symbolic names for the <ACE_Log_Priority> enums.

Definition at line 20 of file Log_Record.cpp.

Referenced by priority_name.

ACE_UINT32 ACE_Log_Record::secs_ [private]
 

Time that the logging record was generated.

Definition at line 176 of file Log_Record.h.

Referenced by decode, encode, format_msg, and time_stamp.

ACE_UINT32 ACE_Log_Record::type_ [private]
 

Type of logging record.

Definition at line 173 of file Log_Record.h.

Referenced by decode, encode, priority, and type.

ACE_UINT32 ACE_Log_Record::usecs_ [private]
 

Definition at line 177 of file Log_Record.h.

Referenced by decode, encode, and time_stamp.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:49:34 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002