Mascot Parser 2.5 and earlier provided a function: ms_errs::setLoggingFile which saved error and logging messages to the specified file. The problem with this approach is that it's necessary to call this for every Mascot Parser object that is created because there is no global handler. Also, any logging that occurs in the constructor would not go into the log file.
ms_loggingmonitor was introduced in Mascot Parser 2.6. This can be used when an application wants to log its own messages and Parser messages to a single file, rather then to multiple log files.
The following is an example of how to redirect all logging from msparser to a specified file and how to specify the logging level.
main
function, create a file logger: For more complex cases, a custom logger can also be created:
class MyLogger : public matrix_science::ms_logger { public: MyLogger(const std::string & logFile, const unsigned int colsToOutput) : ms_logger(colsToOutput) { ofs.open(logFile.c_str()); } void onLogMessage(matrix_science::ms_loggingmonitor::Level_e eSeverity, matrix_science::ms_loggingmonitor::Source_e eSource, long lMsgId, const std::string &text, long lContextId = 0) { ofs << "0x" << std::hex << std::setw(4) << std::setfill('0') << lMsgId << " " << matrix_science::ms_loggingmonitor::severityAsText(eSeverity) << " " << matrix_science::ms_loggingmonitor::messageSourceAsText(eSource) << " " << text << std::endl; // Or could call matrix_science::ms_logger::formatMessage(eSeverity, eSource, lMsgId, text, lContextId); } private: std::ofstream ofs; }; int main() { matrix_science::ms_loggingmonitor & loggingMonitor = matrix_science::ms_loggingmonitor::getDefaultMonitor(); MyLogger logger("C:/tmp/log.txt", matrix_science::ms_logger::COL_ASC_TIME | matrix_science::ms_logger::COL_MSG); loggingMonitor.addLogEventsHandler(logger); }
Copyright © 2022 Matrix Science Ltd. All Rights Reserved. Generated on Thu Mar 31 2022 01:12:30 |