Logging
The Optimizer provides useful text logging messages for indicating progress during the optimization algorithms and for indicating the status of certain important commands such as XPRSreadprob. The messages from the optimization algorithms report information on iterations of the algorithm. The most important use of the logging, however, is to convey error messages reported by the Optimizer. Note that once a system is in production the error messages are typically the only messages of interest to the user.
Conveniently, Console Optimizer automatically writes the logging messages for its problem pointer to the console screen. Although message management for the library users is more complicated than for Console Optimizer users, library users have more flexibility with the handling and routing of messages. The library user can route messages directly to file or they can intercept the messages via callback and marshal the message strings to appropriate destinations depending on the type of message and/or the problem pointer from which the message originates.
To write the messages sent from a problem pointer directly to file the user can call XPRSsetlogfile with specification of an output file name. To get messages sent from a problem pointer to the library user's application the user will define and then register a messaging callback function with a call to the XPRSaddcbmessage routine.
{ XPRSprob prob; XPRScreateprob(&prob); XPRSsetlogfile(prob, "logfile.log"); XPRSdestroyprob(prob); }
Note that a high level messaging framework is also available — which handles messages from all problem pointers created by the Optimizer library and messages related to initialization of the library itself — by calling the XPRS_ge_setcbmsghandler function. A convenient use of this callback, particularly when developing and debugging an application, is to trap all messages to file. The following line of code shows how to use the library function XPRSlogfilehandler together with XPRS_ge_setcbmsghandler to write all library message output to the file log.txt.
XPRS_ge_setcbmsghandler(XPRSlogfilehandler, "log.txt");
Details about the use of callback functions can be found in section Using the Callbacks.