1 \addtogroup logging-options
3 \brief Describes Logger concept and logging services.
5 \section logger-abstraction Logger Abstraction
7 The logging services have been advanced in the SDK starting with
8 this major release. Now it exposes abstraction of logging services
9 defining the way for users to bring custom solutions more suitable
12 Logger abstraction is based on two primary classes:
14 - The OnixS::CME::MDH::Logger which serves as a primary logging instrument, and
15 - The OnixS::CME::MDH::LogEntry which represents an abstraction of a logged entry.
17 The OnixS::CME::MDH::Logger defines an interface for adding entries
18 to the logger. The OnixS::CME::MDH::LogEntry in its turn defines an
19 interface of the entry being added to a log.
21 The SDK contains a few utility classes like OnixS::CME::MDH::LogEvent
22 and its descendants to improve the experience with using logging services.
24 A typical use-case for the logger inside the Handler looks like following:
28 using namespace OnixS::CME::MDH;
31 logger.addEntry(LogSeverity::Important))
33 LogWarning warning(*entry, warningSource);
35 static_cast<LogEvent&>(warning) << warningDescription;
40 Adding a new entry into a log is done by the
41 OnixS::CME::MD3::Logger::addEntry member. It returns
42 instance of OnixS::CME::MDH::Entry which should be
43 used to put information to be logged.
45 An important aspect of Logger abstraction is the fact Logger may
46 return NULL instance of OnixS::CME::MDH::LogEntry. That may happen
47 if the information, which is added to a log, has lower severity than
48 a logger configured with it. For example, an implementation may log
49 only important events and thus regular and debug information is ignored.
50 Therefore, when a caller of the OnixS::CME::MDH::Logger::addEntry supplies
51 a lower severity level, the member returns a NULL instance.
53 A valid (non-NULL) instance of the OnixS::CME::MDH::LogEntry class it can be
54 filled with any information. Once the entry is set up, information in it must be
55 committed to the log by invoking the OnixS::CME::MDH::LogEntry::commit member.
57 \note An instance of OnixS::CME::MDH::Logger successor can be bound
58 to multiple instances of OnixS:CME::MDH::Handler. Therefore, successors
59 of the Logger abstraction must take into consideration the fact the
60 OnixS::CME::MDH::Logger::addEntry member can be invoked simultaneously.
62 \warning It's up to the implementation to allow allocation of the new entries
63 while another entry is in the process of fulfilling with data to be logged.
64 However, the common rule while using a logger is to avoid adding multiple
65 entries at the same time as other implementations may not allow that.
67 \warning Logging issues should not affect market data processing and thus
68 should be exposed through own way. For example, the OnixS::CME::MDH::FileLogger
69 can be associated with an instance of the OnixS::CME::MDH::FileLoggerListener
70 class upon the instance construction. In case of failure like the inability
71 to log an event into a file, an issue is raised and delivered through the
72 OnixS::CME::MDH::FileLoggerListener::onFileLoggerIssue member.
74 \section logger-implementations Ready-to-use Logger Implementations
76 The SDK comes with a few ready-to-use implementations of the Logger
77 abstractions allowing the users to build their solutions quickly:
79 Logger Implementation | Description
80 ---------------------------|-------------------------------------------------------------
81 OnixS::CME:MDH::FileLogger | Implements logging services over text-based files. Logged data is stored into files which may be limited by size. Once volume reaches its limit, Logger detaches logged data, backs it up and starts a new volume.
82 OnixS::CME:MDH::NullLogger | Logs nothings. The Handler suppresses logging at all, if the instance of given class is bound to it.
84 \section bind-logger-to-handler Binding Logger to the Handler
86 The Handler logs important aspects of its execution with the help
87 of Logger abstraction explained above. Logging includes network data
88 received and processed by the Handler, states of books and, of course,
89 errors occurred at execution time.
91 The following example demonstrates how to configure
92 and bind file-based logger to the Handler:
96 using namespace OnixS::CME::MDH;
98 // Implementing logger listener to get notified on
99 // issues which are not raised through other ways.
101 struct FileLoggerIssueTracer
104 // Member is invoked when file logger experience
105 // issue solely beloning to logging subsystem.
108 const FileLogger& logger,
113 "Issue occurred while logging data. "
121 HandlerSettings handlerSettings;
123 handlerSettings.channel(310);
124 handlerSettings.feeds().connectivityConfigurationFile("config.xml");
126 handlerSettings.debugLogging().traceMessages(MessageTracing::SbeFormat);
128 Handler handler(handlerSettings);
130 FileLoggerSettings loggerSettings;
132 loggerSettings.filename(makeLogFilename(handlerSettings.channel()));
133 loggerSettings.severityLevel(LogSeverity::Debug);
135 FileLoggerIssueTracer loggerTracer;
137 FileLogger logger(loggerSettings, &loggerTracer);
139 handler.bindLogger(logger);