OnixS C++ CME MDP Premium Market Data Handler  5.8.9
API Documentation
LoggingSettings.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>
27 
29 
30 /// Defines how SBE messages are traced.
32 {
33  /// Integral type used as basement for constants.
34  typedef UInt32 Base;
35 
36  /// Defines how SBE messages are traced.
37  enum Enum
38  {
39  /// Message tracing is disabled.
41 
42  /// Messages are traced using SBE naming from
43  /// coding templates for fields and their values.
45 
46  /// Messages are traced in FIX tag=value format.
47  FixFormat
48  };
49 };
50 
51 /// Serializes message tracing constant into a string.
53 void toStr(std::string&, MessageTracing::Enum);
54 
55 /// Serializes message tracing constant into a string.
56 inline std::string toStr(MessageTracing::Enum tracing)
57 {
58  std::string str;
59 
60  toStr(str, tracing);
61 
62  return str;
63 }
64 
65 /// Deserializes message tracing constant from a string.
67 bool fromStr(MessageTracing::Enum&, const Char*, size_t);
68 
69 /// Parameters affecting what's logged at a debug level.
71 {
72 public:
73  /// Initializes default settings.
75  : group_(group ? *group : SettingGroup::null())
76  , traceFeeds_(false)
77  , traceMessages_(MessageTracing::Disabled)
78  , traceBooks_(false)
79  {
80  }
81 
82  /// Initializes as a copy.
84  : group_(SettingGroup::null())
85  , traceFeeds_(other.traceFeeds_)
86  , traceMessages_(other.traceMessages_)
87  , traceBooks_(other.traceBooks_)
88  {
89  }
90 
91  /// Cleans everything up (if necessary).
93 
94  /// Defines whether feeds are to be traced.
95  /// @note By default, feeds are not traced.
96  bool traceFeeds() const
97  {
98  return traceFeeds_;
99  }
100 
101  /// Defines whether feeds are to be traced.
103  {
104  group_.controlAssignment("Trace Feeds", traceFeeds_, status);
105 
106  return *this;
107  }
108 
109  /// Defines the way SBE messages are traced.
110  /// @note By default, messages are not traced.
112  {
113  return traceMessages_;
114  }
115 
116  /// Defines the way SBE messages are traced.
118  {
119  group_.controlAssignment("Trace Messages", traceMessages_, tracing);
120 
121  return *this;
122  }
123 
124  /// Indicates whether books are traced.
125  /// @note By default, books are not traced.
126  bool traceBooks() const
127  {
128  return traceBooks_;
129  }
130 
131  /// Indicates whether books are traced.
133  {
134  group_.controlAssignment("TraceBooks", traceBooks_, status);
135 
136  return *this;
137  }
138 
139  /// Re-initializes as a copy.
141  {
142  group_.controlChange("Debug Logging Settings", &DebugLoggingSettings::assignNoControl, *this, other);
143 
144  return *this;
145  }
146 
147 protected:
148  // To let assignment be controlled
149  // by the master container.
151 
152  // Re-initializes the given instance
153  // as a copy of the other one without
154  // involving assignment control service.
156  {
157  traceFeeds_ = other.traceFeeds_;
158 
159  traceMessages_ = other.traceMessages_;
160 
161  traceBooks_ = other.traceBooks_;
162  }
163 
164 private:
165  const SettingGroup& group_;
166 
167  bool traceFeeds_;
168  MessageTracing::Enum traceMessages_;
169  bool traceBooks_;
170 };
171 
172 #if !defined(ONIXS_CMEMDH_NO_DEPRECATED)
173 
175 
176 #endif // ONIXS_CMEMDH_NO_DEPRECATED
177 
178 /// Serializes Handler debug logging settings into a string.
180 void toStr(std::string&, const DebugLoggingSettings&);
181 
182 /// Serializes Handler debug logging settings into a string.
183 inline std::string toStr(const DebugLoggingSettings& settings)
184 {
185  std::string str;
186 
187  toStr(str, settings);
188 
189  return str;
190 }
191 
192 /// Provides default functionality
193 /// for the logging-related services.
195 {
196  /// Returns an instance of the default logger.
197  static Logger& logger();
198 
199  static const char* fileName()
200  {
201  return "OnixS.CmeMdpPremiumCppHandlers.log";
202  }
203 
204 private:
205  static FileLoggerSettings createSettings()
206  {
207  FileLoggerSettings fileLoggerSettings;
208  fileLoggerSettings.filename(fileName());
209 
210  return fileLoggerSettings;
211  }
212 };
213 
214 /// The collection of settings affecting
215 /// use of logging subsystem by the Handler.
217 {
218 public:
219  /// Initializes the instance with the default values.
221  : SettingGroup(controller)
222  , logger_(&LoggingDefaults::logger())
223  , debug_(&group())
224  {
225  }
226 
227  /// Initializes as a copy of the other instance.
229  : SettingGroup()
230  , logger_(other.logger_)
231  , debug_(other.debug_)
232  {
233  }
234 
235  /// The Logger instance to be used by the
236  /// Handler while logging various events.
237  ///
238  /// No instance may be returned identifying
239  /// no logger is associated and thus nothing
240  /// is to be logged by the Handler.
241  Logger* logger() const
242  {
243  return (&LoggingDefaults::logger() != logger_ ? logger_ : ONIXS_CMEMDH_NULLPTR);
244  }
245 
246  /// The Logger instance to be used by the
247  /// Handler while logging various events.
248  ///
249  /// If no instance was assigned by the user,
250  /// the default logger is provided.
252  {
253  return *logger_;
254  }
255 
256  /// Assigns the given logger to the Handler.
257  ///
258  /// Null instance tells the Handler to do not log
259  /// any data and thus reduces general processing time.
261  {
262  group().controlAssignment("Logger", logger_, logger ? logger : &LoggingDefaults::logger());
263 
264  return *this;
265  }
266 
267  /// The collection of settings
268  /// affecting debug-level logging.
269  ///
270  /// The Handler may log a lot of data at
271  /// debug level. The given collection allows
272  /// to filter debug information being logged.
274  {
275  return debug_;
276  }
277 
278  /// The collection of settings
279  /// affecting debug-level logging.
280  ///
281  /// The Handler may log a lot of data at
282  /// debug level. The given collection allows
283  /// to filter debug information being logged.
285  {
286  return debug_;
287  }
288 
289  /// Re-initializes the instance
290  /// as a copy of the other one.
292  {
293  group().controlChange("Logging Settings", &LoggingSettings::assignNoControl, *this, other);
294 
295  return *this;
296  }
297 
298 private:
300 
301  Logger* logger_;
302 
303  DebugLoggingSettings debug_;
304 
305  const SettingGroup& group() const
306  {
307  return *this;
308  }
309 
310  void assignNoControl(const LoggingSettings& other)
311  {
312  logger_ = other.logger_;
313 
314  debug_.assignNoControl(other.debug_);
315  }
316 };
317 
318 /// Serializes Handler debug logging settings into a string.
320 void toStr(std::string&, const LoggingSettings&);
321 
322 /// Serializes Handler debug logging settings into a string.
323 inline std::string toStr(const LoggingSettings& settings)
324 {
325  std::string str;
326 
327  toStr(str, settings);
328 
329  return str;
330 }
331 
bool traceFeeds() const
Defines whether feeds are to be traced.
Defines how SBE messages are traced.
LoggingSettings(SettingChangeController *controller=nullptr)
Initializes the instance with the default values.
Handler&#39;s configuration settings.
bool traceBooks() const
Indicates whether books are traced.
Provides default functionality for the logging-related services.
UInt32 UInt32
uInt32.
Definition: Fields.h:192
#define ONIXS_CMEMDH_NULLPTR
Definition: Compiler.h:167
Base parameters affecting synchronous logging services.
Definition: FileLogger.h:32
Enum
Defines how SBE messages are traced.
DebugLoggingSettings & traceBooks(bool status)
Indicates whether books are traced.
DebugLoggingSettings & operator=(const DebugLoggingSettings &other)
Re-initializes as a copy.
const DebugLoggingSettings & debug() const
The collection of settings affecting debug-level logging.
The collection of settings affecting use of logging subsystem by the Handler.
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
~DebugLoggingSettings()
Cleans everything up (if necessary).
void controlAssignment(const Char *description, Assignee &assignee, Value value) const
Guarded assignment of the given value to the given variable.
Definition: SettingGroup.h:107
Parameters affecting what&#39;s logged at a debug level.
char Char
Character type alias.
Definition: String.h:36
const std::string & filename() const
Log file name.
Definition: FileLogger.h:50
UInt32 Base
Integral type used as basement for constants.
Message tracing is disabled.
LoggingSettings & operator=(const LoggingSettings &other)
Re-initializes the instance as a copy of the other one.
static const char * fileName()
DebugLoggingSettings(const SettingGroup *group=nullptr)
Initializes default settings.
LoggingSettings(const LoggingSettings &other)
Initializes as a copy of the other instance.
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
bool fromStr(MessageTracing::Enum &, const Char *, size_t)
Deserializes message tracing constant from a string.
std::string toStr(const LoggingSettings &settings)
Serializes Handler debug logging settings into a string.
Base services for settings grouped by a certain criteria.
Definition: SettingGroup.h:91
DebugLoggingSettings & traceFeeds(bool status)
Defines whether feeds are to be traced.
LoggingSettings & logger(Logger *logger)
Assigns the given logger to the Handler.
Logger * logger() const
The Logger instance to be used by the Handler while logging various events.
DebugLoggingSettings & debug()
The collection of settings affecting debug-level logging.
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:160
#define ONIXS_CMEMDH_LTWT_CLASS_DECL(name)
Definition: Bootstrap.h:48
DebugLoggingSettings & traceMessages(MessageTracing::Enum tracing)
Defines the way SBE messages are traced.
Abstraction of logger.
Definition: Logger.h:155
Represents a service controlling change/update operations for the collections of settings.
Definition: SettingGroup.h:33
Messages are traced using SBE naming from coding templates for fields and their values.
DebugLoggingSettings HandlerDebugLoggingSettings
MessageTracing::Enum traceMessages() const
Defines the way SBE messages are traced.
void assignNoControl(const DebugLoggingSettings &other)
DebugLoggingSettings(const DebugLoggingSettings &other)
Initializes as a copy.
void controlChange(const Char *description, void(Changeable::*change)(), Changeable &changeable) const
Guarded invoke of the given routine which assumes complex change or update for the given object...
Definition: SettingGroup.h:118
Logger & loggerOrDefault() const
The Logger instance to be used by the Handler while logging various events.
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68