MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Logger.hpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef Logger_H
19 #define Logger_H
20 
21 #include <ndb_global.h>
22 #include <BaseString.hpp>
23 #include <NdbOut.hpp>
24 
25 #define MAX_LOG_MESSAGE_SIZE 1024
26 
27 class LogHandler;
28 class LogHandlerList;
29 
102 class Logger
103 {
104 public:
108  enum LoggerLevel {LL_ON, LL_DEBUG, LL_INFO, LL_WARNING, LL_ERROR,
109  LL_CRITICAL, LL_ALERT, LL_ALL};
110 
114  static const char* LoggerLevelNames[];
115 
119  Logger();
120 
124  virtual ~Logger();
125 
131  void setCategory(const char* pCategory);
132 
138  bool createConsoleHandler(NdbOut &out= ndbout);
139 
143  void removeConsoleHandler();
144 
153  bool createEventLogHandler(const char* source_name);
154 
160  bool createFileHandler(char* filename= 0);
161 
165  void removeFileHandler();
166 
172  bool createSyslogHandler();
173 
177  void removeSyslogHandler();
178 
185  bool addHandler(LogHandler* pHandler);
186 
195  bool addHandler(const BaseString &logstring, int *err, int len, char* errStr);
196 
203  bool removeHandler(LogHandler* pHandler);
204 
208  void removeAllHandlers();
209 
215  bool isEnable(LoggerLevel logLevel) const;
216 
222  void enable(LoggerLevel logLevel);
223 
230  void enable (LoggerLevel fromLogLevel, LoggerLevel toLogLevel);
231 
237  void disable(LoggerLevel logLevel);
238 
244  virtual void alert(const char* pMsg, ...) const
245  ATTRIBUTE_FORMAT(printf, 2, 3);
246  virtual void alert(BaseString &pMsg) const { alert("%s", pMsg.c_str()); };
247 
253  virtual void critical(const char* pMsg, ...) const
254  ATTRIBUTE_FORMAT(printf, 2, 3);
255  virtual void critical(BaseString &pMsg) const { critical("%s", pMsg.c_str()); };
256 
262  virtual void error(const char* pMsg, ...) const
263  ATTRIBUTE_FORMAT(printf, 2, 3);
264  virtual void error(BaseString &pMsg) const { error("%s", pMsg.c_str()); };
265 
271  virtual void warning(const char* pMsg, ...) const
272  ATTRIBUTE_FORMAT(printf, 2, 3);
273  virtual void warning(BaseString &pMsg) const { warning("%s", pMsg.c_str()); };
274 
280  virtual void info(const char* pMsg, ...) const
281  ATTRIBUTE_FORMAT(printf, 2, 3);
282  virtual void info(BaseString &pMsg) const { info("%s", pMsg.c_str()); };
283 
289  virtual void debug(const char* pMsg, ...) const
290  ATTRIBUTE_FORMAT(printf, 2, 3);
291  virtual void debug(BaseString &pMsg) const { debug("%s", pMsg.c_str()); };
292 
293  /*
294  * Set repeat frequency, 0 means disable special repeated message handling
295  */
296  virtual void setRepeatFrequency(unsigned val);
297 
298 protected:
299 
300  NdbMutex *m_mutex;
301 
302  void log(LoggerLevel logLevel, const char* msg, va_list ap) const;
303 
304 private:
306  Logger(const Logger&);
307  Logger operator = (const Logger&);
308  bool operator == (const Logger&);
309 
310  STATIC_CONST( MAX_LOG_LEVELS = 8 );
311 
312  bool m_logLevels[MAX_LOG_LEVELS];
313 
314  LogHandlerList* m_pHandlerList;
315  const char* m_pCategory;
316 
317  /* Default handlers */
318  NdbMutex *m_handler_mutex;
319  LogHandler* m_pConsoleHandler;
320  LogHandler* m_pFileHandler;
321  LogHandler* m_pSyslogHandler;
322 };
323 
324 #endif