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, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef EVENTLOGGER_H
26 #define EVENTLOGGER_H
27 
28 #include <logger/Logger.hpp>
29 #include <kernel/kernel_types.h>
30 #include <kernel/LogLevel.hpp>
31 #include <kernel/signaldata/EventReport.hpp>
32 
33 class EventLoggerBase {
34 public:
35   virtual ~EventLoggerBase();
36 
37   /**
38    * LogLevel settings
39    */
40   LogLevel m_logLevel;
41 
42   /**
43    * This matrix defines which event should be printed when
44    *
45    * threshold - is in range [0-15]
46    * severity  - DEBUG to ALERT (Type of log message)
47    */
48   typedef void (* EventTextFunction)(char *,size_t,const Uint32*, Uint32 len);
49 
50   struct EventRepLogLevelMatrix {
51     Ndb_logevent_type       eventType;
52     LogLevel::EventCategory eventCategory;
53     Uint32                  threshold;
54     Logger::LoggerLevel     severity;
55     EventTextFunction       textF;
56   };
57 
58   static const EventRepLogLevelMatrix matrix[];
59   static const Uint32 matrixSize;
60   static int event_lookup(int eventType,
61 			  LogLevel::EventCategory &cat,
62 			  Uint32 &threshold,
63 			  Logger::LoggerLevel &severity,
64 			  EventTextFunction &textF);
65 };
66 
67 /**
68  * The EventLogger is primarily used for logging NDB events
69  * in the Management Server. It inherits all logging functionality of Logger.
70  *
71  * HOW TO USE
72  *
73  * 1) Create an EventLogger
74  *
75  *   EventLogger myEventLogger = new EventLogger();
76  *
77  * 2) Log NDB events and other log messages.
78  *
79  *   myEventLogger->info("Changing log levels.");
80  *
81  *   EventReport* report = (EventReport*)&theSignalData[0];
82  *   myEventLogger->log(eventReport->getEventType(), theSignalData, aNodeId);
83  *
84  *
85  * The following NDB event categories and log levels are enabled as default:
86  *
87  *  EVENT-CATEGORY LOG-LEVEL
88  *
89  *  Startup         4
90  *  Shutdown        1
91  *  Statistic       2
92  *  Checkpoint      5
93  *  NodeRestart     8
94  *  Connection      2
95  *  Error          15
96  *  Info           10
97  *
98  * @see Logger
99  * @version #@ $Id: EventLogger.hpp,v 1.3 2003/09/01 10:15:52 innpeno Exp $
100  */
101 class EventLogger : public EventLoggerBase, public Logger
102 {
103 public:
104   /**
105    * Default constructor. Enables default log levels and
106    * sets the log category to 'EventLogger'.
107    */
108   EventLogger();
109 
110   /**
111    * Destructor.
112    */
113   virtual ~EventLogger();
114 
115   /**
116    * Closes the eventlog.
117    */
118   void close();
119 
120   /**
121    * Logs the NDB event.
122    *
123    * @param eventType the type of event.
124    * @param theData the event data.
125    * @param nodeId the node id of event origin.
126    */
127   virtual void log(int, const Uint32*, Uint32 len, NodeId = 0,const class LogLevel * = 0);
128 
129 
130   /**
131    * Returns the event text for the specified event report type.
132    *
133    * @param textF print function for the event
134    * @param theData the event data.
135    * @param nodeId a node id.
136    * @return the event report text.
137    */
138   static const char* getText(char * dst, size_t dst_len,
139 			     EventTextFunction textF,
140 			     const Uint32* theData, Uint32 len,
141 			     NodeId nodeId = 0);
142 
143 private:
144   /** Prohibit */
145   EventLogger(const EventLogger&);
146   EventLogger operator = (const EventLogger&);
147   bool operator == (const EventLogger&);
148 
149   STATIC_CONST(MAX_TEXT_LENGTH = 256);
150 };
151 
152 extern void getRestartAction(Uint32 action, BaseString &str);
153 #endif
154