EventLogger.hpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:5k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #ifndef EVENTLOGGER_H
  14. #define EVENTLOGGER_H
  15. #include <Logger.hpp>
  16. #include <FileLogHandler.hpp>
  17. #include <GrepError.hpp>
  18. #include <kernel_types.h>
  19. #include <kernel/LogLevel.hpp>
  20. #include <signaldata/EventReport.hpp>
  21. class EventLoggerBase {
  22. public:
  23.   virtual ~EventLoggerBase();
  24.   /**
  25.    * LogLevel settings
  26.    */
  27.   LogLevel m_logLevel;
  28.   
  29.   /**
  30.    * This matrix defines which event should be printed when
  31.    *
  32.    * threshold - is in range [0-15]
  33.    * severity  - DEBUG to ALERT (Type of log message)
  34.    */  
  35.   struct EventRepLogLevelMatrix {
  36.     EventReport::EventType        eventType;
  37.     LogLevel::EventCategory   eventCategory;
  38.     Uint32                        threshold;
  39.     Logger::LoggerLevel            severity;
  40.   };
  41.   static const EventRepLogLevelMatrix matrix[];
  42.   static const Uint32 matrixSize;
  43.   static int event_lookup(int eventType,
  44.   LogLevel::EventCategory &cat,
  45.   Uint32 &threshold, 
  46.   Logger::LoggerLevel &severity);
  47. };
  48. /**
  49.  * The EventLogger is primarily used for logging NDB events 
  50.  * in the Management Server. It inherits all logging functionality of Logger.
  51.  *
  52.  * HOW TO USE
  53.  *
  54.  * 1) Create an EventLogger
  55.  * 
  56.  *   EventLogger myEventLogger = new EventLogger();
  57.  * 
  58.  * 2) Log NDB events and other log messages.
  59.  *
  60.  *   myEventLogger->info("Changing log levels.");
  61.  *   
  62.  *   EventReport* report = (EventReport*)&theSignalData[0];
  63.  *   myEventLogger->log(eventReport->getEventType(), theSignalData, aNodeId);
  64.  * 
  65.  *
  66.  * The following NDB event categories and log levels are enabled as default:
  67.  *
  68.  *  EVENT-CATEGORY LOG-LEVEL
  69.  *
  70.  *  Startup         4
  71.  *  Shutdown        1
  72.  *  Statistic       2 
  73.  *  Checkpoint      5
  74.  *  NodeRestart     8
  75.  *  Connection      2
  76.  *  Error          15 
  77.  *  Info           10 
  78.  *
  79.  * @see Logger
  80.  * @version #@ $Id: EventLogger.hpp,v 1.3 2003/09/01 10:15:52 innpeno Exp $
  81.  */
  82. class EventLogger : public EventLoggerBase, public Logger
  83. {
  84. public:
  85.   /**
  86.    * Default constructor. Enables default log levels and 
  87.    * sets the log category to 'EventLogger'.
  88.    */
  89.   EventLogger();
  90.   /**
  91.    * Destructor.
  92.    */
  93.   virtual ~EventLogger();
  94.   /**
  95.    * Opens/creates the eventlog with the specified filename.
  96.    *
  97.    * @param aFileName the eventlog filename.
  98.    * @param maxNoFiles the maximum no of archived eventlog files.
  99.    * @param maxFileSize the maximum eventlog file size.
  100.    * @param maxLogEntries the maximum number of log entries before 
  101.    *                      checking time to archive.
  102.    * @return true if successful.
  103.    */
  104.   bool open(const char* logFileName,
  105.     int maxNoFiles = FileLogHandler::MAX_NO_FILES, 
  106.     long int maxFileSize = FileLogHandler::MAX_FILE_SIZE,
  107.     unsigned int maxLogEntries = FileLogHandler::MAX_LOG_ENTRIES);
  108.   /**
  109.    * Closes the eventlog.
  110.    */
  111.   void close();
  112.   /**
  113.    * Logs the NDB event.
  114.    *
  115.    * @param eventType the type of event.
  116.    * @param theData the event data.
  117.    * @param nodeId the node id of event origin.
  118.    */
  119.   virtual void log(int, const Uint32*, NodeId = 0,const class LogLevel * = 0);
  120.   
  121.   /**
  122.    * Returns the event text for the specified event report type.
  123.    *
  124.    * @param type the event type.
  125.    * @param theData the event data.
  126.    * @param nodeId a node id.
  127.    * @return the event report text.
  128.    */
  129.   static const char* getText(char * dst, size_t dst_len,
  130.      int type,
  131.      const Uint32* theData, NodeId nodeId = 0);
  132.   
  133.   /**
  134.    * Returns the log level that is used to filter an event. The event will not
  135.    * be logged unless its event category's log level is <= levelFilter.
  136.    *
  137.    * @return the log level filter that is used for all event categories.
  138.    */
  139.   int getFilterLevel() const;
  140.   /**
  141.    * Sets log level filter. The event will be logged if 
  142.    * the event category's log level is <= 'filterLevel'.
  143.    *
  144.    * @param level the log level to filter.
  145.    */
  146.   void setFilterLevel(int filterLevel);
  147. private:
  148.   /** Prohibit */
  149.   EventLogger(const EventLogger&);
  150.   EventLogger operator = (const EventLogger&);
  151.   bool operator == (const EventLogger&);
  152.   Uint32 m_filterLevel;
  153.   STATIC_CONST(MAX_TEXT_LENGTH = 256);
  154.   char m_text[MAX_TEXT_LENGTH];
  155. };
  156. #endif