summaryrefslogtreecommitdiff
path: root/ACE/ace/Log_Record.h
blob: 152e2940eb43f6c58a0f28074bc5e2b810c6fe61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Log_Record.h
 *
 *  @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
 */
//=============================================================================

// These need to go outside of the #ifdef to avoid problems with
// circular dependencies...

#include "ace/Log_Priority.h"

#ifndef ACE_LOG_RECORD_H
#define ACE_LOG_RECORD_H
#include /**/ "ace/pre.h"

#include /**/ "ace/ACE_export.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Default_Constants.h"
#include "ace/Basic_Types.h"
#include "ace/iosfwd.h"

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
{
public:
  enum
  {
    /// 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
  };

  // = Initialization
  /**
   * Create a Log_Record and set its priority, time stamp, and
   * process id.
   */
  ACE_Log_Record ();
  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);

  /// Default dtor.
  ~ACE_Log_Record ();

  /// Write the contents of the logging record to the appropriate
  /// FILE if the corresponding type is enabled.
  int print (const ACE_TCHAR host_name[],
             u_long verbose_flag,
#if !defined (ACE_LACKS_STDERR)
             FILE *fp = stderr);
#else
             FILE *fp);
#endif /* ACE_LACKS_STDERR */

#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)
  /// Write the contents of the logging record to the appropriate
  /// @a stream if the corresponding type is enabled.
  int print (const ACE_TCHAR host_name[],
             u_long verbose_flag,
             ACE_OSTREAM_TYPE &stream);
#endif /* ! ACE_LACKS_IOSTREAM_TOTALLY */

  int format_msg (const ACE_TCHAR host_name[],
                  u_long verbose_flag,
                  ACE_TCHAR *verbose_msg,
                  size_t verbose_msg_size);

  /**
   * Returns a character array with the string form of the
   * ACE_Log_Priority parameter.  This is used for the verbose
   * printing format.
   */
  static const ACE_TCHAR *priority_name (ACE_Log_Priority p);

  /// IMPORTANT: @a name must be a statically allocated const ACE_TCHAR*
  static void priority_name (ACE_Log_Priority p, const ACE_TCHAR *name);

  /// Get the type of the Log_Record.
  ACE_UINT32 type () const;

  /// Set the type of the Log_Record.
  void type (ACE_UINT32);

  /// Get the category of the Log_Record.
  ACE_Log_Category_TSS* category () 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,
   * as defined by the enums in ACE_Log_Priority).
   */
  u_long priority () const;

  /// Set the priority of the Log_Record <type_> (which must be a
  /// power of 2, as defined by the enums in ACE_Log_Priority).
  void priority (u_long num);

  /// Get the total length of the Log_Record, which includes the
  /// size of the various data member fields.
  long length () const;

  /// Set the total length of the Log_Record, which needs to account for
  /// the size of the various data member fields.
  void length (long);

  /// Get the time stamp of the Log_Record.
  ACE_Time_Value time_stamp () const;

  /// Set the time stamp of the Log_Record.
  void time_stamp (const ACE_Time_Value &ts);

  /// Get the process id of the Log_Record.
  long pid () const;

  /// Set the process id of the Log_Record.
  void pid (long);

  /// Get the message data of the Log_Record.
  const ACE_TCHAR *msg_data () const;

  /// Set the message data of the record. If @a data is longer than the
  /// current msg_data_ buffer, a new msg_data_ buffer is allocated to
  /// fit. If such a reallocation fails, this method returns -1, else 0.
  int msg_data (const ACE_TCHAR *data);

  /// Get the size of the message data of the Log_Record, including
  /// a byte for the NUL.
  size_t msg_data_len () const;

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

  /// Declare the dynamic allocation hooks.
  ACE_ALLOC_HOOK_DECLARE;

private:
  /// Round up to the alignment restrictions.
  void round_up ();

  /**
   * 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 portable across platforms.
   */
  ACE_INT32 length_;

  /// Type of logging record.
  ACE_UINT32 type_;

  /// Time that the logging record was generated.
  time_t secs_;
  ACE_UINT32 usecs_;

  /// Id of process that generated the logging record.
  ACE_UINT32 pid_;

  /// Logging record data
  ACE_TCHAR *msg_data_;   // Heap-allocated text message area

  /// Allocated size of msg_data_ in ACE_TCHARs
  size_t msg_data_size_;

  ///
  ACE_Log_Category_TSS* category_;

  ACE_Log_Record (const ACE_Log_Record&) = delete;
  ACE_Log_Record& operator= (const ACE_Log_Record&) = delete;
  ACE_Log_Record (ACE_Log_Record&&) = delete;
  ACE_Log_Record& operator= (ACE_Log_Record&& rhs) = delete;
};

// Forward decls.
class ACE_InputCDR;
class ACE_OutputCDR;

// iostream operators for ACE_Log_Record.
ACE_Export int operator>> (ACE_InputCDR &cdr, ACE_Log_Record &log_record);
ACE_Export int operator<< (ACE_OutputCDR &cdr, const ACE_Log_Record &log_record);

ACE_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
#include "ace/Log_Record.inl"
#endif /* __ACE_INLINE__ */

#include /**/ "ace/post.h"
#endif /* ACE_LOG_RECORD_H */