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