1 /* Copyright (c) 2003-2005 MySQL AB
2 Use is subject to license terms
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 Street, Fifth Floor, Boston, MA 02110-1301, USA */
16
17 #ifndef _LOG_LEVEL_HPP
18 #define _LOG_LEVEL_HPP
19
20 #include <ndb_global.h>
21 #include <mgmapi_config_parameters.h>
22
23 /**
24 *
25 */
26 class LogLevel {
27 friend class Config;
28 public:
29 /**
30 * Constructor
31 */
32 LogLevel();
33
34 /**
35 * Howto add a new event category:
36 * 1. Add the new event category to EventCategory below
37 * 2. Update #define _LOGLEVEL_CATEGORIES (found below) with the number of
38 * items in EventCategory
39 * 3. Update LogLevelCategoryName in LogLevel.cpp
40 * 4. Add the event in EventLogger
41 */
42
43
44 /**
45 * Copy operator
46 */
47 LogLevel & operator= (const LogLevel &);
48
49 enum EventCategory {
50 llInvalid = -1,
51 llStartUp = CFG_LOGLEVEL_STARTUP - CFG_MIN_LOGLEVEL,
52 llShutdown = CFG_LOGLEVEL_SHUTDOWN - CFG_MIN_LOGLEVEL,
53 llStatistic = CFG_LOGLEVEL_STATISTICS - CFG_MIN_LOGLEVEL,
54 llCheckpoint = CFG_LOGLEVEL_CHECKPOINT - CFG_MIN_LOGLEVEL,
55 llNodeRestart = CFG_LOGLEVEL_NODERESTART - CFG_MIN_LOGLEVEL,
56 llConnection = CFG_LOGLEVEL_CONNECTION - CFG_MIN_LOGLEVEL,
57 llInfo = CFG_LOGLEVEL_INFO - CFG_MIN_LOGLEVEL,
58 llWarning = CFG_LOGLEVEL_WARNING - CFG_MIN_LOGLEVEL,
59 llError = CFG_LOGLEVEL_ERROR - CFG_MIN_LOGLEVEL,
60 llCongestion = CFG_LOGLEVEL_CONGESTION - CFG_MIN_LOGLEVEL,
61 llDebug = CFG_LOGLEVEL_DEBUG - CFG_MIN_LOGLEVEL
62 ,llBackup = CFG_LOGLEVEL_BACKUP - CFG_MIN_LOGLEVEL
63 };
64
65 /**
66 * No of categories
67 */
68 #define _LOGLEVEL_CATEGORIES (CFG_MAX_LOGLEVEL - CFG_MIN_LOGLEVEL + 1)
69 STATIC_CONST( LOGLEVEL_CATEGORIES = _LOGLEVEL_CATEGORIES );
70
71 void clear();
72
73 /**
74 * Note level is valid as 0-15
75 */
76 int setLogLevel(EventCategory ec, Uint32 level = 7);
77
78 /**
79 * Get the loglevel (0-15) for a category
80 */
81 Uint32 getLogLevel(EventCategory ec) const;
82
83 /**
84 * Set this= max(this, ll) per category
85 */
86 LogLevel& set_max(const LogLevel& ll);
87
operator ==(const LogLevel & l) const88 bool operator==(const LogLevel& l) const {
89 return memcmp(this, &l, sizeof(* this)) == 0;
90 }
91
92 LogLevel& operator=(const struct EventSubscribeReq & req);
93
94 private:
95 /**
96 * The actual data
97 */
98 Uint8 logLevelData[LOGLEVEL_CATEGORIES];
99 };
100
101 inline
LogLevel()102 LogLevel::LogLevel(){
103 clear();
104 }
105
106 inline
107 LogLevel &
operator =(const LogLevel & org)108 LogLevel::operator= (const LogLevel & org){
109 memcpy(logLevelData, org.logLevelData, sizeof(logLevelData));
110 return * this;
111 }
112
113 inline
114 void
clear()115 LogLevel::clear(){
116 for(Uint32 i = 0; i<LOGLEVEL_CATEGORIES; i++){
117 logLevelData[i] = 0;
118 }
119 }
120
121 inline
122 int
setLogLevel(EventCategory ec,Uint32 level)123 LogLevel::setLogLevel(EventCategory ec, Uint32 level){
124 if (ec >= 0 && (Uint32) ec < LOGLEVEL_CATEGORIES)
125 {
126 logLevelData[ec] = (Uint8)level;
127 return 0;
128 }
129 return 1;
130 }
131
132 inline
133 Uint32
getLogLevel(EventCategory ec) const134 LogLevel::getLogLevel(EventCategory ec) const{
135 assert(ec >= 0 && (Uint32) ec < LOGLEVEL_CATEGORIES);
136
137 return (Uint32)logLevelData[ec];
138 }
139
140 inline
141 LogLevel &
set_max(const LogLevel & org)142 LogLevel::set_max(const LogLevel & org){
143 for(Uint32 i = 0; i<LOGLEVEL_CATEGORIES; i++){
144 if(logLevelData[i] < org.logLevelData[i])
145 logLevelData[i] = org.logLevelData[i];
146 }
147 return * this;
148 }
149
150 #include "signaldata/EventSubscribeReq.hpp"
151
152 inline
153 LogLevel&
operator =(const EventSubscribeReq & req)154 LogLevel::operator=(const EventSubscribeReq& req)
155 {
156 clear();
157 for(size_t i = 0; i<req.noOfEntries; i++){
158 logLevelData[(req.theData[i] >> 16)] = req.theData[i] & 0xFFFF;
159 }
160 return * this;
161 }
162
163 #endif
164