MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LogHandler.hpp
1 /*
2  Copyright (C) 2003-2006, 2008 MySQL AB, 2008 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef LOGHANDLER_H
20 #define LOGHANDLER_H
21 
22 #include "Logger.hpp"
23 
43 {
44 public:
48  LogHandler();
49 
53  virtual ~LogHandler();
54 
55  virtual const char* handler_type() {return "NONE";};
56 
62  virtual bool open() = 0;
63 
69  virtual bool close() = 0;
70 
76  virtual bool is_open() = 0;
77 
88  void append(const char* pCategory, Logger::LoggerLevel level,
89  const char* pMsg);
90  void append_impl(const char* pCategory, Logger::LoggerLevel level,
91  const char* pMsg);
92 
102  const char* getDefaultHeader(char* pStr, const char* pCategory,
103  Logger::LoggerLevel level) const;
104 
110  const char* getDefaultFooter() const;
111 
117  const char* getDateTimeFormat() const;
118 
125  void setDateTimeFormat(const char* pFormat);
126 
130  int getErrorCode() const;
131 
137  void setErrorCode(int code);
138 
142  char* getErrorStr();
143 
149  void setErrorStr(const char* str);
150 
158  bool parseParams(const BaseString &params);
159 
166  virtual bool setParam(const BaseString &param, const BaseString &value) = 0;
167 
173  virtual bool checkParams();
174 
175  /*
176  * Set repeat frequency, 0 means disable special repeated message handling
177  */
178  virtual void setRepeatFrequency(unsigned val);
179 
187  virtual bool getParams(BaseString &config) {return false;};
188 
189  virtual off_t getCurrentSize() {return -1;};
190  virtual off_t getMaxSize() {return -1;};
191 
192 protected:
194  STATIC_CONST( MAX_DATE_TIME_HEADER_LENGTH = 64 );
196  STATIC_CONST( MAX_HEADER_LENGTH = 128 );
198  STATIC_CONST( MAX_FOOTER_LENGTH = 128 );
199 
206  virtual void writeHeader(const char* category, Logger::LoggerLevel level) = 0;
207 
213  virtual void writeMessage(const char* pMsg) = 0;
214 
219  virtual void writeFooter() = 0;
220 
221 private:
228  char* getTimeAsString(char* pStr) const;
229  time_t m_now;
230 
232  LogHandler(const LogHandler&);
233  LogHandler* operator = (const LogHandler&);
234  bool operator == (const LogHandler&);
235 
236  const char* m_pDateTimeFormat;
237  int m_errorCode;
238  char* m_errorStr;
239 
240  // for handling repeated messages
241  unsigned m_count_repeated_messages;
242  unsigned m_max_repeat_frequency;
243  time_t m_last_log_time;
244  char m_last_category[MAX_HEADER_LENGTH];
245  char m_last_message[MAX_LOG_MESSAGE_SIZE];
246  Logger::LoggerLevel m_last_level;
247 };
248 
249 #endif