Matrix Science header

ms_logging.hpp

00001 /*
00002 ##############################################################################
00003 # File: ms_logging.hpp                                                       #
00004 # Mascot Parser toolkit                                                      #
00005 # Encapsulates general purpose objects which act as conduits for receiving   #
00006 # and processing logging events                                              #
00007 ##############################################################################
00008 # COPYRIGHT NOTICE                                                           #
00009 # Copyright 2015-2016 Matrix Science Limited  All Rights Reserved.           #
00010 #                                                                            #
00011 ##############################################################################
00012 #    $Source: parser/inc/ms_logging.hpp $
00013 #    $Author: dcreasy@matrixscience.com $ 
00014 #      $Date: 2020-02-17 11:11:01 +0000 $ 
00015 #  $Revision: 568c8a55fee82c07355ed0cee4a6cbf220d9a6fe | MSPARSER_REL_2_8_1-0-gea32989045 $
00016 ##############################################################################
00017 */
00018 
00019 #ifndef MS_LOGGING_HPP
00020 #define MS_LOGGING_HPP
00021 
00022 
00023 // Includes from the standard template library
00024 #include <string>
00025 #include <vector>
00026 #include <list>
00027 
00028 namespace msparser_internal {
00029     class ms_loggingmonitor_impl;
00030 }
00031 
00032 namespace matrix_science {
00033     class ms_logger;        
00034     
00039 
00040 
00043     class MS_MASCOTRESFILE_API ms_loggingmonitor 
00044     {
00045     public:
00047 
00051         enum Level_e {
00052             LVL_NONE     = 0,   
00053             LVL_ERROR    = 1,   
00054             LVL_WARNING  = 2,   
00055             LVL_INFO     = 4,   
00056             LVL_DEBUG1   = 8,   
00057             LVL_DEBUG2   = 16,  
00058             LVL_DEBUG3   = 32   
00059         }; // enum LogLevel_e
00060 
00062 
00065         enum Source_e {
00066             SRC_APPLICATION  = 1,     
00067             SRC_MASCOTSERVER = 2,     
00068             SRC_MSPARSER     = 3,     
00069             SRC_MDRO         = 4,     
00070             SRC_MSQUANTLIB   = 5,     
00071             SRC_PURIFIERAPI  = 6,     
00072             SRC_PURIFIERAPP  = 7,     
00073             SRC_DENOVOLIB    = 8,     
00074             SRC_VENDORSTART  = 100,   
00075             SRC_ALL          = 0xFFFF 
00076         }; // enum LogSource_e
00077 
00078     private:        
00079         msparser_internal::ms_loggingmonitor_impl *pImpl_;
00080         static ms_loggingmonitor defaultLoggingMonitor;
00081 
00082     public:
00084         ms_loggingmonitor();
00085 
00087         virtual ~ms_loggingmonitor();
00088 
00090         virtual int addLogEventsHandler(ms_logger& logger);
00091 
00093         virtual bool removeLogEventsHandler(const int uid);
00094 
00096         virtual ms_logger * getLogEventsHandler(const int uid);
00097 
00099         virtual int getNumLogEventsHandlers() const;
00100 
00102         virtual void logMessage(Level_e eSeverity,
00103             Source_e eSource,
00104             long lMsgId,
00105             const std::string & text,
00106             const char * srcFileName,
00107             const int srcFileLineNum,
00108             long lContextId=0) const;
00109 
00111         virtual long getLogMask(unsigned source = SRC_ALL);
00112 
00114         virtual void setLogMask(long newVal, unsigned source = SRC_ALL);
00115 
00117         static matrix_science::ms_loggingmonitor & getDefaultMonitor();
00119         static void setDefaultMonitor(ms_loggingmonitor & loggingMonitor);
00120 
00122         static std::string messageSourceAsText(Source_e eSource);
00123 
00125         static std::string severityAsText(Level_e eSeverity);
00126 
00127     }; // class ms_loggingmonitor
00128 
00130 
00135     class MS_MASCOTRESFILE_API ms_logger {
00136     public:
00138 
00149         enum LogOutputColumns_e {
00150             COL_ASC_TIME         = 0x0001, 
00151             COL_ISO8601_TIME     = 0x0002, 
00152             COL_IP_ADDRESS       = 0x0004, 
00153             COL_MSG_NUM_DEC      = 0x0008, 
00154             COL_MSG_NUM_HEX      = 0x0010, 
00155             COL_SEVERITY_NUM     = 0x0020, 
00156             COL_SEVERITY_TXT     = 0x0040, 
00157             COL_MSG_SOURCE_TXT   = 0x0080, 
00158             COL_SRC_FILE         = 0x0100, 
00159             COL_SRC_LINENUM      = 0x0200, 
00160             COL_THREAD_ID        = 0x0400, 
00161             COL_MSG              = 0x0800, 
00162 
00163             COL_TSV              = 0x1000, 
00164             COL_QUOTES           = 0x2000, 
00165             COL_HEADERS          = 0x4000, 
00166 
00167             COL_LOGGER_DEFAULTS = COL_ISO8601_TIME | COL_MSG_NUM_HEX | COL_SEVERITY_TXT | COL_MSG_SOURCE_TXT | COL_SRC_FILE | COL_SRC_LINENUM | COL_MSG | COL_HEADERS 
00168         };
00169 
00171         ms_logger(const unsigned int colsToOutput = COL_MSG);
00172 
00174         virtual ~ms_logger() {}
00175 
00177         virtual void onLogMessage(ms_loggingmonitor::Level_e eSeverity,
00178             ms_loggingmonitor::Source_e eSource,
00179             long lMsgId,
00180             const std::string & text,
00181             const char * srcFileName,
00182             const int srcFileLineNum,
00183             long lContextId=0)=0;
00184 
00186         virtual unsigned int getColsToOutput() const;
00187 
00189         virtual void setColsToOutput(const unsigned int colsToOutput);
00190 
00192         std::string formatMessage(ms_loggingmonitor::Level_e eSeverity,
00193                                   ms_loggingmonitor::Source_e eSource,
00194                                   long lMsgId,
00195                                   const std::string & text,
00196                                   const char * srcFileName,
00197                                   const int srcFileLineNum,
00198                                   long lContextId) const;
00199 
00201         std::string getHeaderLine() const;
00202 
00203     protected:
00204         unsigned int colsToOutput_;
00205     }; // class ms_logger
00206 
00208     class MS_MASCOTRESFILE_API ms_stdout_logger : public ms_logger {
00209     public:
00211         ms_stdout_logger(unsigned int colsToOutput = ms_logger::COL_LOGGER_DEFAULTS);
00213         virtual ~ms_stdout_logger();
00214 
00216         virtual void onLogMessage(ms_loggingmonitor::Level_e eSeverity,
00217             ms_loggingmonitor::Source_e eSource,
00218             long lMsgId,
00219             const std::string & text,
00220             const char * srcFileName,
00221             const int srcFileLineNum,
00222             long lContextId=0);
00223 
00224     }; // class ms_stdout_logger
00225 
00227     class MS_MASCOTRESFILE_API ms_file_logger : public ms_logger {
00228     public:
00230         ms_file_logger(const std::string logFileName, unsigned int colsToOutput = ms_logger::COL_LOGGER_DEFAULTS);
00231 
00233         virtual ~ms_file_logger();
00234 
00236         std::string getLogFilename();
00237 
00239         virtual void onLogMessage(ms_loggingmonitor::Level_e eSeverity,
00240             ms_loggingmonitor::Source_e eSource,
00241             long lMsgId,
00242             const std::string & text,
00243             const char * srcFileName,
00244             const int srcFileLineNum,
00245             long lContextId=0);
00246 
00247     private:
00248         std::string logfilename_;
00249 
00250     }; // class ms_file_logger
00251 
00253     class MS_MASCOTRESFILE_API ms_buffer_logger : public ms_logger {
00254     public:
00256         ms_buffer_logger(unsigned int colsToOutput = ms_logger::COL_LOGGER_DEFAULTS);
00257 
00259         virtual ~ms_buffer_logger();
00260 
00262         std::vector<std::string> flush();
00263 
00265         virtual void onLogMessage(ms_loggingmonitor::Level_e eSeverity,
00266             ms_loggingmonitor::Source_e eSource,
00267             long lMsgId,
00268             const std::string & text,
00269             const char * srcFileName,
00270             const int srcFileLineNum,
00271             long lContextId=0);
00272 
00273     private:
00274         std::list<std::string> messages_;
00275         std::list<std::string>::size_type numMessages_;
00276 
00277     }; // class ms_file_logger
00278  // end of error_handling_group
00280 } // namespace matrix_science
00281 
00282 #endif // MS_LOGGING_HPP
00283 
00284 /*------------------------------- End of File -------------------------------*/

Copyright © 2022 Matrix Science Ltd.  All Rights Reserved. Generated on Thu Mar 31 2022 01:12:29