Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
ms_logging.hpp
1/*
2##############################################################################
3# File: ms_logging.hpp #
4# Mascot Parser toolkit #
5# Encapsulates general purpose objects which act as conduits for receiving #
6# and processing logging events #
7##############################################################################
8# COPYRIGHT NOTICE #
9# Copyright 2015-2016 Matrix Science Limited All Rights Reserved. #
10# #
11##############################################################################
12# $Source: parser/inc/ms_logging.hpp $
13# $Author: villek@matrixscience.com $
14# $Date: 2023-02-02 12:03:35 +0000 $
15# $Revision: 8c2d6b85f91e6cca912bc94ab2625c1a32b7a55c | MSPARSER_REL_3_0_0-2024-09-24-0-g93ebaeb4f4 $
16##############################################################################
17*/
18
19#ifndef MS_LOGGING_HPP
20#define MS_LOGGING_HPP
21
22
23// Includes from the standard template library
24#include <string>
25#include <vector>
26#include <list>
27
28namespace msparser_internal {
29 class ms_loggingmonitor_impl;
30}
31
32namespace matrix_science {
33 class ms_logger;
34
40
43 class MS_MASCOTRESFILE_API ms_loggingmonitor
44 {
45 public:
47
51 enum Level_e {
52 LVL_NONE = 0,
53 LVL_ERROR = 1,
54 LVL_WARNING = 2,
55 LVL_INFO = 4,
56 LVL_DEBUG1 = 8,
57 LVL_DEBUG2 = 16,
58 LVL_DEBUG3 = 32
59 }; // enum LogLevel_e
60
62
65 enum Source_e {
66 SRC_APPLICATION = 1,
67 SRC_MASCOTSERVER = 2,
68 SRC_MSPARSER = 3,
69 SRC_MDRO = 4,
70 SRC_MSQUANTLIB = 5,
71 SRC_PURIFIERAPI = 6,
72 SRC_PURIFIERAPP = 7,
73 SRC_DENOVOLIB = 8,
74 SRC_VENDORSTART = 100,
75 SRC_ALL = 0xFFFF
76 }; // enum LogSource_e
77
78 private:
79 msparser_internal::ms_loggingmonitor_impl *pImpl_;
80 static ms_loggingmonitor defaultLoggingMonitor;
81
82 public:
85
87 virtual ~ms_loggingmonitor();
88
90 virtual int addLogEventsHandler(ms_logger& logger);
91
93 virtual bool removeLogEventsHandler(const int uid);
94
96 virtual ms_logger * getLogEventsHandler(const int uid);
97
99 virtual int getNumLogEventsHandlers() const;
100
102 virtual void logMessage(Level_e eSeverity,
103 Source_e eSource,
104 long lMsgId,
105 const std::string & text,
106 const char * srcFileName,
107 const int srcFileLineNum,
108 long lContextId=0) const;
109
111 virtual long getLogMask(unsigned source = SRC_ALL);
112
114 virtual void setLogMask(long newVal, unsigned source = SRC_ALL);
115
117 static matrix_science::ms_loggingmonitor & getDefaultMonitor();
119 static void setDefaultMonitor(ms_loggingmonitor & loggingMonitor);
120
122 static std::string messageSourceAsText(Source_e eSource);
123
125 static std::string severityAsText(Level_e eSeverity);
126
127 }; // class ms_loggingmonitor
128
130
137 class MS_MASCOTRESFILE_API ms_logger {
138 public:
140
152 COL_ASC_TIME = 0x0001,
153 COL_ISO8601_TIME = 0x0002,
154 COL_IP_ADDRESS = 0x0004,
155 COL_MSG_NUM_DEC = 0x0008,
156 COL_MSG_NUM_HEX = 0x0010,
157 COL_SEVERITY_NUM = 0x0020,
158 COL_SEVERITY_TXT = 0x0040,
159 COL_MSG_SOURCE_TXT = 0x0080,
160 COL_SRC_FILE = 0x0100,
161 COL_SRC_LINENUM = 0x0200,
162 COL_THREAD_ID = 0x0400,
163 COL_MSG = 0x0800,
164
165 COL_TSV = 0x1000,
166 COL_QUOTES = 0x2000,
167 COL_HEADERS = 0x4000,
168
169 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
170 };
171
173 ms_logger(const unsigned int colsToOutput = COL_MSG);
174
176 virtual ~ms_logger() {}
177
181 long lMsgId,
182 const std::string & text,
183 const char * srcFileName,
184 const int srcFileLineNum,
185 long lContextId=0)=0;
186
188 virtual unsigned int getColsToOutput() const;
189
191 virtual void setColsToOutput(const unsigned int colsToOutput);
192
194 std::string formatMessage(ms_loggingmonitor::Level_e eSeverity,
196 long lMsgId,
197 const std::string & text,
198 const char * srcFileName,
199 const int srcFileLineNum,
200 long lContextId) const;
201
203 std::string getHeaderLine() const;
204
205 protected:
206 unsigned int colsToOutput_;
207 }; // class ms_logger
208
210 class MS_MASCOTRESFILE_API ms_stdout_logger : public ms_logger {
211 public:
213 ms_stdout_logger(unsigned int colsToOutput = ms_logger::COL_LOGGER_DEFAULTS);
215 virtual ~ms_stdout_logger();
216
218 virtual void onLogMessage(ms_loggingmonitor::Level_e eSeverity,
220 long lMsgId,
221 const std::string & text,
222 const char * srcFileName,
223 const int srcFileLineNum,
224 long lContextId=0);
225
226 }; // class ms_stdout_logger
227
229 class MS_MASCOTRESFILE_API ms_file_logger : public ms_logger {
230 public:
232 ms_file_logger(const std::string logFileName, unsigned int colsToOutput = ms_logger::COL_LOGGER_DEFAULTS);
233
235 virtual ~ms_file_logger();
236
238 std::string getLogFilename();
239
241 virtual void onLogMessage(ms_loggingmonitor::Level_e eSeverity,
243 long lMsgId,
244 const std::string & text,
245 const char * srcFileName,
246 const int srcFileLineNum,
247 long lContextId=0);
248
249 private:
250 std::string logfilename_;
251
252 }; // class ms_file_logger
253
255 class MS_MASCOTRESFILE_API ms_buffer_logger : public ms_logger {
256 public:
258 ms_buffer_logger(unsigned int colsToOutput = ms_logger::COL_LOGGER_DEFAULTS);
259
261 virtual ~ms_buffer_logger();
262
264 std::vector<std::string> flush();
265
267 virtual void onLogMessage(ms_loggingmonitor::Level_e eSeverity,
269 long lMsgId,
270 const std::string & text,
271 const char * srcFileName,
272 const int srcFileLineNum,
273 long lContextId=0);
274
275 private:
276 std::list<std::string> messages_;
277 std::list<std::string>::size_type numMessages_;
278
279 }; // class ms_file_logger
280 // end of error_handling_group
282} // namespace matrix_science
283
284#endif // MS_LOGGING_HPP
285
286/*------------------------------- End of File -------------------------------*/
Concrete class which implements ms_logger and stores log text in memory.
Definition: ms_logging.hpp:255
Concrete class which implements ms_logger and outputs log text to the specified file.
Definition: ms_logging.hpp:229
Abstract class which provides the interface used by ms_logging monitor to delegate logging events.
Definition: ms_logging.hpp:137
virtual ~ms_logger()
Destructor.
Definition: ms_logging.hpp:176
LogOutputColumns_e
Logging output columns.
Definition: ms_logging.hpp:151
virtual void onLogMessage(ms_loggingmonitor::Level_e eSeverity, ms_loggingmonitor::Source_e eSource, long lMsgId, const std::string &text, const char *srcFileName, const int srcFileLineNum, long lContextId=0)=0
Processes and handles the passed logging message.
Monitor class to delegate logging events generated from multiple sources.
Definition: ms_logging.hpp:44
Level_e
Logging severity levels.
Definition: ms_logging.hpp:51
Source_e
Logging event source.
Definition: ms_logging.hpp:65
virtual void logMessage(Level_e eSeverity, Source_e eSource, long lMsgId, const std::string &text, const char *srcFileName, const int srcFileLineNum, long lContextId=0) const
Logs the passed message with all registered ms_logger objects.
Concrete class which implements ms_logger and outputs log text to standard out.
Definition: ms_logging.hpp:210