The logging services have been advanced in the SDK starting with this major release. Now it exposes abstraction of logging services defining the way for users to bring custom solutions more suitable for their purposes.
Logger abstraction is based on two primary classes:
The SDK contains a few utility classes like OnixS::CME::MDH::LogEvent and its descendants to improve the experience with using logging services.
A typical use-case for the logger inside the Handler looks like following:
Adding a new entry into a log is done by the OnixS::CME::MD3::Logger::addEntry member. It returns instance of OnixS::CME::MDH::Entry which should be used to put information to be logged.
An important aspect of Logger abstraction is the fact Logger may return NULL instance of OnixS::CME::MDH::LogEntry. That may happen if the information, which is added to a log, has lower severity than a logger configured with it. For example, an implementation may log only important events and thus regular and debug information is ignored. Therefore, when a caller of the OnixS::CME::MDH::Logger::addEntry supplies a lower severity level, the member returns a NULL instance.
A valid (non-NULL) instance of the OnixS::CME::MDH::LogEntry class it can be filled with any information. Once the entry is set up, information in it must be committed to the log by invoking the OnixS::CME::MDH::LogEntry::commit member.
The SDK comes with a few ready-to-use implementations of the Logger abstractions allowing the users to build their solutions quickly:
|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.|
|OnixS::CME:MDH::NullLogger||Logs nothings. The Handler suppresses logging at all, if the instance of given class is bound to it.|
The Handler logs important aspects of its execution with the help of Logger abstraction explained above. Logging includes network data received and processed by the Handler, states of books and, of course, errors occurred at execution time.
The following example demonstrates how to configure and bind file-based logger to the Handler: