OnixS C++ CME MDP Premium Market Data Handler  5.8.9
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 
23 #include <OnixS/CME/MDH/String.h>
24 #include <OnixS/CME/MDH/Integral.h>
25 #include <OnixS/CME/MDH/Decimal.h>
26 #include <OnixS/CME/MDH/Time.h>
27 
28 #include <OnixS/CME/MDH/Logger.h>
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 public:
42  /// Initializes event with LogEntry instance.
43  LogEvent(LogEntry& entry, LogCategory::Enum category, const StrRef& source)
44  : entry_(entry)
45  , message_(entry.message())
46  {
47  entry_.category(category);
48  entry_.source(source);
49  }
50 
51  /// Commits entry to the log.
53  {
54  entry_.commit();
55  }
56 
57  /// Informational message to be added to a log.
58  std::string& message()
59  {
60  return message_;
61  }
62 
63  /// Informational message to be added to a log.
64  const std::string& message() const
65  {
66  return message_;
67  }
68 
69 private:
70  LogEntry& entry_;
71  std::string& message_;
72 
73  // Object copying is not assumed.
74 
75  LogEvent(const LogEvent&);
76  LogEvent& operator=(const LogEvent&);
77 };
78 
79 // A few descendants for a particular purposes.
80 
81 /// Specializes LogEvent to log errors.
83 {
84  /// Initializes event as error.
85  LogError(LogEntry& entry, const Char* source)
86  : LogEvent(entry, LogCategory::Error, toStrRef(source))
87  {
88  }
89 
90  /// Initializes event as error.
91  LogError(LogEntry& entry, const StrRef& source)
92  : LogEvent(entry, LogCategory::Error, source)
93  {
94  }
95 
96  /// Initializes event as error.
97  LogError(LogEntry& entry, const std::string& source)
98  : LogEvent(entry, LogCategory::Error, toStrRef(source))
99  {
100  }
101 };
102 
103 /// Specializes LogEvent to log warnings.
105 {
106  /// Initializes event as warning.
107  LogWarning(LogEntry& entry, const Char* source)
108  : LogEvent(entry, LogCategory::Warning, toStrRef(source))
109  {
110  }
111 
112  /// Initializes event as warning.
113  LogWarning(LogEntry& entry, const StrRef& source)
114  : LogEvent(entry, LogCategory::Warning, source)
115  {
116  }
117 
118  /// Initializes event as warning.
119  LogWarning(LogEntry& entry, const std::string& source)
120  : LogEvent(entry, LogCategory::Warning, toStrRef(source))
121  {
122  }
123 };
124 
125 /// Specializes LogEvent to log information.
127 {
128  /// Initializes event as information.
129  LogInfo(LogEntry& entry, const Char* source)
130  : LogEvent(entry, LogCategory::Info, toStrRef(source))
131  {
132  }
133 
134  /// Initializes event as information.
135  LogInfo(LogEntry& entry, const StrRef& source)
136  : LogEvent(entry, LogCategory::Info, source)
137  {
138  }
139 
140  /// Initializes event as information.
141  LogInfo(LogEntry& entry, const std::string& source)
142  : LogEvent(entry, LogCategory::Info, toStrRef(source))
143  {
144  }
145 };
146 
147 /// Specializes LogEvent to log debug information.
149 {
150  /// Initializes event as debug information.
151  LogDebug(LogEntry& entry, const Char* source)
152  : LogEvent(entry, LogCategory::Debug, toStrRef(source))
153  {
154  }
155 
156  /// Initializes event as debug information.
157  LogDebug(LogEntry& entry, const StrRef& source)
158  : LogEvent(entry, LogCategory::Debug, source)
159  {
160  }
161 
162  /// Initializes event as debug information.
163  LogDebug(LogEntry& entry, const std::string& source)
164  : LogEvent(entry, LogCategory::Debug, toStrRef(source))
165  {
166  }
167 };
168 
169 // Sugar-coat for adding basic type data to log entry.
170 
171 /// Prevents data of unrecognized type to be
172 /// logged without properly defined serialization.
173 template <typename Undefined>
174 LogEvent& operator<<(LogEvent& event, Undefined undefined)
175 {
176  struct DefineOperatorForGivenType
177  {
178  } var = undefined;
179 
180  return event;
181 }
182 
183 /// Logs zero-terminated string.
184 inline LogEvent& operator<<(LogEvent& event, const Char* cStr)
185 {
186  event.message() += cStr;
187 
188  return event;
189 }
190 
191 /// Logs standard string.
192 inline LogEvent& operator<<(LogEvent& event, const std::string& str)
193 {
194  event.message() += str;
195 
196  return event;
197 }
198 
199 /// Logs string by its reference.
200 inline LogEvent& operator<<(LogEvent& event, const StrRef& strRef)
201 {
202  toStr(event.message(), strRef);
203 
204  return event;
205 }
206 
207 /// Logs single character.
208 inline LogEvent& operator<<(LogEvent& event, Char character)
209 {
210  event.message() += character;
211 
212  return event;
213 }
214 
215 /// Logs an integer.
216 inline LogEvent& operator<<(LogEvent& event, Int8 number)
217 {
218  toStr(event.message(), number);
219 
220  return event;
221 }
222 
223 /// Logs an integer.
224 inline LogEvent& operator<<(LogEvent& event, UInt8 number)
225 {
226  toStr(event.message(), number);
227 
228  return event;
229 }
230 
231 /// Logs an integer.
232 inline LogEvent& operator<<(LogEvent& event, Int16 number)
233 {
234  toStr(event.message(), number);
235 
236  return event;
237 }
238 
239 /// Logs an integer.
240 inline LogEvent& operator<<(LogEvent& event, UInt16 number)
241 {
242  toStr(event.message(), number);
243 
244  return event;
245 }
246 
247 /// Logs an integer.
248 inline LogEvent& operator<<(LogEvent& event, Int32 number)
249 {
250  toStr(event.message(), number);
251 
252  return event;
253 }
254 
255 /// Logs an integer.
256 inline LogEvent& operator<<(LogEvent& event, UInt32 number)
257 {
258  toStr(event.message(), number);
259 
260  return event;
261 }
262 
263 /// Logs an integer.
264 inline LogEvent& operator<<(LogEvent& event, Int64 number)
265 {
266  toStr(event.message(), number);
267 
268  return event;
269 }
270 
271 /// Logs an integer.
272 inline LogEvent& operator<<(LogEvent& event, UInt64 number)
273 {
274  toStr(event.message(), number);
275 
276  return event;
277 }
278 
279 /// Logs decimal number.
280 template <class Mantissa, class Exponent>
281 inline LogEvent& operator<<(LogEvent& event, const FixedPointDecimal<Mantissa, Exponent>& number)
282 {
283  toStr(event.message(), number);
284 
285  return event;
286 }
287 
288 // Logs timestamp.
290 {
291  toStr(event.message(), timestamp);
292 
293  return event;
294 }
295 
296 // Logs time span.
297 inline LogEvent& operator<<(LogEvent& event, const TimeSpan& timeSpan)
298 {
299  toStr(event.message(), timeSpan);
300 
301  return event;
302 }
303 
LogInfo(LogEntry &entry, const Char *source)
Initializes event as information.
Definition: LogEvents.h:129
LogError(LogEntry &entry, const Char *source)
Initializes event as error.
Definition: LogEvents.h:85
Int32 Int32
int32.
Definition: Fields.h:60
LogWarning(LogEntry &entry, const Char *source)
Initializes event as warning.
Definition: LogEvents.h:107
LogDebug(LogEntry &entry, const Char *source)
Initializes event as debug information.
Definition: LogEvents.h:151
LogEvent & operator<<(LogEvent &event, const TimeSpan &timeSpan)
Definition: LogEvents.h:297
UInt32 UInt32
uInt32.
Definition: Fields.h:192
LogDebug(LogEntry &entry, const std::string &source)
Initializes event as debug information.
Definition: LogEvents.h:163
LogInfo(LogEntry &entry, const std::string &source)
Initializes event as information.
Definition: LogEvents.h:141
Specializes LogEvent to log warnings.
Definition: LogEvents.h:104
Represents time point without time-zone information.
Definition: Time.h:387
LogError(LogEntry &entry, const StrRef &source)
Initializes event as error.
Definition: LogEvents.h:91
Specializes LogEvent to log debug information.
Definition: LogEvents.h:148
LogInfo(LogEntry &entry, const StrRef &source)
Initializes event as information.
Definition: LogEvents.h:135
Timestamp timestamp(const MultiContainer &, Tag)
Retrieves last update time field value.
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
Abstraction of log entry in logging services.
Definition: Logger.h:121
~LogEvent()
Commits entry to the log.
Definition: LogEvents.h:52
UInt8 UInt8
uInt8.
Definition: Fields.h:198
char Char
Character type alias.
Definition: String.h:36
UInt64 UInt64
uInt64.
Definition: Fields.h:195
void toStr(std::string &str, const Message &message)
Serializes FIX message into tag=value format.
Definition: Message.h:318
Represents time interval.
Definition: Time.h:104
By default, logging machinery provides access to the entry with ability to store arbitrary text...
Definition: LogEvents.h:39
Int16 Int16
int16.
Definition: Fields.h:57
Provides efficient way of accessing text-based values without copying content of the text being refer...
Definition: String.h:41
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
std::ostream & operator<<(std::ostream &stream, const IssueArgs &args)
LogWarning(LogEntry &entry, const std::string &source)
Initializes event as warning.
Definition: LogEvents.h:119
Categories for information being logged.
Definition: Logger.h:80
LogWarning(LogEntry &entry, const StrRef &source)
Initializes event as warning.
Definition: LogEvents.h:113
LogDebug(LogEntry &entry, const StrRef &source)
Initializes event as debug information.
Definition: LogEvents.h:157
LogEvent(LogEntry &entry, LogCategory::Enum category, const StrRef &source)
Initializes event with LogEntry instance.
Definition: LogEvents.h:43
StrRef toStrRef(const std::string &str)
Constructs StrRef instance over std::string content.
Definition: String.h:155
std::string & message()
Informational message to be added to a log.
Definition: LogEvents.h:58
Specializes LogEvent to log errors.
Definition: LogEvents.h:82
UInt16 UInt16
uInt16 optional.
Definition: Fields.h:189
Int8 Int8
int8.
Definition: Fields.h:63
LogError(LogEntry &entry, const std::string &source)
Initializes event as error.
Definition: LogEvents.h:97
Specializes LogEvent to log information.
Definition: LogEvents.h:126
Enum
Categories for information being logged.
Definition: Logger.h:86
const std::string & message() const
Informational message to be added to a log.
Definition: LogEvents.h:64
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68