OnixS C++ CME MDP Streamlined Market Data Handler  1.2.0
API Documentation
LogEvents.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
27 
29 
31 
32 /// By default, logging machinery provides access
33 /// to the entry with ability to store arbitrary text.
34 /// Given class adds basic information about time of
35 /// entry record, category and source of log entry.
36 /// It also enhances API with ability to put data into
37 /// log entries in simple and elegant way by using
38 /// streaming operators.
40 {
41  LogEntry& entry_;
42  std::string& message_;
43 
44  // Object copying is not assumed.
45 
46  LogEvent(const LogEvent&);
47  LogEvent& operator =(const LogEvent&);
48 
49 public:
50  /// Initializes event with LogEntry instance.
52  LogEntry& entry,
53  LogCategory::Enum category,
54  const StrRef& source)
55  : entry_(entry)
56  , message_(entry.message())
57  {
58  entry_.category(category);
59  entry_.source(source);
60  }
61 
62  /// Commits entry to the log.
64  {
65  entry_.commit();
66  }
67 
68  /// Informational message to be added to a log.
69  std::string& message()
70  {
71  return message_;
72  }
73 
74  /// Informational message to be added to a log.
75  const std::string& message() const
76  {
77  return message_;
78  }
79 };
80 
81 // A few descendants for a particular purposes.
82 
83 /// Specializes LogEvent to log errors.
85 {
86  /// Initializes event as error.
88  LogEntry& entry,
89  const Char* source)
90  : LogEvent(
91  entry,
92  LogCategory::Error,
93  toStrRef(source))
94  {
95  }
96 
97  /// Initializes event as error.
99  LogEntry& entry,
100  const StrRef& source)
101  : LogEvent(
102  entry,
103  LogCategory::Error,
104  source)
105  {
106  }
107 
108  /// Initializes event as error.
110  LogEntry& entry,
111  const std::string& source)
112  : LogEvent(
113  entry,
114  LogCategory::Error,
115  toStrRef(source))
116  {
117  }
118 };
119 
120 /// Specializes LogEvent to log warnings.
122 {
123  /// Initializes event as warning.
125  LogEntry& entry,
126  const Char* source)
127  : LogEvent(
128  entry,
129  LogCategory::Warning,
130  toStrRef(source))
131  {
132  }
133 
134  /// Initializes event as warning.
136  LogEntry& entry,
137  const StrRef& source)
138  : LogEvent(
139  entry,
140  LogCategory::Warning,
141  source)
142  {
143  }
144 
145  /// Initializes event as warning.
147  LogEntry& entry,
148  const std::string& source)
149  : LogEvent(
150  entry,
151  LogCategory::Warning,
152  toStrRef(source))
153  {
154  }
155 };
156 
157 /// Specializes LogEvent to log informations.
159 {
160  /// Initializes event as information.
162  LogEntry& entry,
163  const Char* source)
164  : LogEvent(
165  entry,
166  LogCategory::Info,
167  toStrRef(source))
168  {
169  }
170 
171  /// Initializes event as information.
173  LogEntry& entry,
174  const StrRef& source)
175  : LogEvent(
176  entry,
177  LogCategory::Info,
178  source)
179  {
180  }
181 
182  /// Initializes event as information.
184  LogEntry& entry,
185  const std::string& source)
186  : LogEvent(
187  entry,
188  LogCategory::Info,
189  toStrRef(source))
190  {
191  }
192 };
193 
194 /// Specializes LogEvent to log debug information.
196 {
197  /// Initializes event as debug information.
199  LogEntry& entry,
200  const Char* source)
201  : LogEvent(
202  entry,
203  LogCategory::Debug,
204  toStrRef(source))
205  {
206  }
207 
208  /// Initializes event as debug information.
210  LogEntry& entry,
211  const StrRef& source)
212  : LogEvent(
213  entry,
214  LogCategory::Debug,
215  source)
216  {
217  }
218 
219  /// Initializes event as debug information.
221  LogEntry& entry,
222  const std::string& source)
223  : LogEvent(
224  entry,
225  LogCategory::Debug,
226  toStrRef(source))
227  {
228  }
229 };
230 
231 // Sugar-coat for adding basic type data to log entry.
232 
233 /// Prevents data of unrecognized type to be
234 /// logged without properly defined serialization.
235 template
236 <
237  typename Undefined
238 >
239 LogEvent&
241  LogEvent& event,
242  Undefined undefined)
243 {
244  struct
245  DefineOperatorForGivenType
246  {}
247  var = undefined;
248 
249  return event;
250 }
251 
252 /// Logs zero-terminated string.
253 inline
254 LogEvent&
256  LogEvent& event,
257  const Char* cStr)
258 {
259  event.message() += cStr;
260 
261  return event;
262 }
263 
264 /// Logs standard string.
265 inline
266 LogEvent&
268  LogEvent& event,
269  const std::string& str)
270 {
271  event.message() += str;
272 
273  return event;
274 }
275 
276 /// Logs string by its reference.
277 inline
278 LogEvent&
280  LogEvent& event,
281  const StrRef& strRef)
282 {
283  toStr(
284  event.message(),
285  strRef);
286 
287  return event;
288 }
289 
290 /// Logs single character.
291 inline
292 LogEvent&
294  LogEvent& event,
295  Char character)
296 {
297  event.message() += character;
298 
299  return event;
300 }
301 
302 /// Logs an integer.
303 inline
304 LogEvent&
306  LogEvent& event,
307  Int8 number)
308 {
309  toStr(
310  event.message(),
311  number);
312 
313  return event;
314 }
315 
316 /// Logs an integer.
317 inline
318 LogEvent&
320  LogEvent& event,
321  UInt8 number)
322 {
323  toStr(
324  event.message(),
325  number);
326 
327  return event;
328 }
329 
330 /// Logs an integer.
331 inline
332 LogEvent&
334  LogEvent& event,
335  Int16 number)
336 {
337  toStr(
338  event.message(),
339  number);
340 
341  return event;
342 }
343 
344 /// Logs an integer.
345 inline
346 LogEvent&
348  LogEvent& event,
349  UInt16 number)
350 {
351  toStr(
352  event.message(),
353  number);
354 
355  return event;
356 }
357 
358 /// Logs an integer.
359 inline
360 LogEvent&
362  LogEvent& event,
363  Int32 number)
364 {
365  toStr(
366  event.message(),
367  number);
368 
369  return event;
370 }
371 
372 /// Logs an integer.
373 inline
374 LogEvent&
376  LogEvent& event,
377  UInt32 number)
378 {
379  toStr(
380  event.message(),
381  number);
382 
383  return event;
384 }
385 
386 /// Logs an integer.
387 inline
388 LogEvent&
390  LogEvent& event,
391  Int64 number)
392 {
393  toStr(
394  event.message(),
395  number);
396 
397  return event;
398 }
399 
400 /// Logs an integer.
401 inline
402 LogEvent&
404  LogEvent& event,
405  UInt64 number)
406 {
407  toStr(
408  event.message(),
409  number);
410 
411  return event;
412 }
413 
414 /// Logs decimal number.
415 template
416 <
417  class Mantissa,
418  class Exponent
419 >
420 inline
421 LogEvent&
423  LogEvent& event,
424  const
426  <
427  Mantissa,
428  Exponent
429  >& number)
430 {
431  toStr(
432  event.message(),
433  number);
434 
435  return event;
436 }
437 
438 // Logs timestamp.
439 inline
440 LogEvent&
442  LogEvent& event,
443  const Timestamp& timestamp)
444 {
445  toStr(
446  event.message(),
447  timestamp);
448 
449  return event;
450 }
451 
452 // Logs time span.
453 inline
454 LogEvent&
456  LogEvent& event,
457  const TimeSpan& timeSpan)
458 {
459  toStr(
460  event.message(),
461  timeSpan);
462 
463  return event;
464 }
465 
StrRef toStrRef(const std::string &str)
Constructs StrRef instance over std::string content.
Definition: String.h:166
LogDebug(LogEntry &entry, const std::string &source)
Initializes event as debug information.
Definition: LogEvents.h:220
Represents time point without time-zone information.
Definition: Time.h:447
~LogEvent()
Commits entry to the log.
Definition: LogEvents.h:63
Enum
Categories for information being logged.
Definition: Logger.h:96
UInt64 UInt64
uInt64.
Definition: Fields.h:187
LogWarning(LogEntry &entry, const std::string &source)
Initializes event as warning.
Definition: LogEvents.h:146
LogError(LogEntry &entry, const StrRef &source)
Initializes event as error.
Definition: LogEvents.h:98
LogDebug(LogEntry &entry, const StrRef &source)
Initializes event as debug information.
Definition: LogEvents.h:209
UInt16 UInt16
uInt16.
Definition: Fields.h:179
LogError(LogEntry &entry, const Char *source)
Initializes event as error.
Definition: LogEvents.h:87
LogInfo(LogEntry &entry, const StrRef &source)
Initializes event as information.
Definition: LogEvents.h:172
Categories for information being logged.
Definition: Logger.h:90
LogInfo(LogEntry &entry, const Char *source)
Initializes event as information.
Definition: LogEvents.h:161
By default, logging machinery provides access to the entry with ability to store arbitrary text...
Definition: LogEvents.h:39
Represents real number with constant exponent.
Definition: Decimal.h:41
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_END
Definition: Bootstrap.h:173
#define ONIXS_CMESTREAMLINEDMDH_LTWT_CLASS
Definition: Bootstrap.h:111
LogEvent(LogEntry &entry, LogCategory::Enum category, const StrRef &source)
Initializes event with LogEntry instance.
Definition: LogEvents.h:51
char Char
Character type alias.
Definition: String.h:36
Specializes LogEvent to log informations.
Definition: LogEvents.h:158
Abstraction of log entry in logging services.
Definition: Logger.h:141
void toStr(std::string &str, const Decimal &number)
Definition: Decimal.h:502
LogError(LogEntry &entry, const std::string &source)
Initializes event as error.
Definition: LogEvents.h:109
virtual void commit()=0
Commits entry into a log and releases the instance.
LogWarning(LogEntry &entry, const StrRef &source)
Initializes event as warning.
Definition: LogEvents.h:135
Specializes LogEvent to log debug information.
Definition: LogEvents.h:195
virtual void category(LogCategory::Enum)=0
Specifies category of information being logged.
LogEvent & operator<<(LogEvent &event, const TimeSpan &timeSpan)
Definition: LogEvents.h:455
LogWarning(LogEntry &entry, const Char *source)
Initializes event as warning.
Definition: LogEvents.h:124
Provides efficient way of accessing text-based FIX field values.
Definition: String.h:39
const std::string & message() const
Informational message to be added to a log.
Definition: LogEvents.h:75
LogInfo(LogEntry &entry, const std::string &source)
Initializes event as information.
Definition: LogEvents.h:183
Specializes LogEvent to log errors.
Definition: LogEvents.h:84
Represents time interval.
Definition: Time.h:104
#define ONIXS_CMESTREAMLINEDMDH_LTWT_STRUCT
Definition: Bootstrap.h:115
UInt32 UInt32
uInt32.
Definition: Fields.h:183
LogDebug(LogEntry &entry, const Char *source)
Initializes event as debug information.
Definition: LogEvents.h:198
std::string & message()
Informational message to be added to a log.
Definition: LogEvents.h:69
Specializes LogEvent to log warnings.
Definition: LogEvents.h:121
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:169
virtual void source(const StrRef &)=0
Specifies source of information being logged.