~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/include/kernel/LogLevel.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef _LOG_LEVEL_HPP
 
17
#define _LOG_LEVEL_HPP
 
18
 
 
19
#include <ndb_global.h>
 
20
#include <mgmapi_config_parameters.h>
 
21
 
 
22
/**
 
23
 * 
 
24
 */
 
25
class LogLevel {
 
26
  friend class Config;
 
27
public:
 
28
  /**
 
29
   * Constructor
 
30
   */
 
31
  LogLevel();
 
32
  
 
33
  /**
 
34
   * Howto add a new event category:
 
35
   * 1. Add the new event category to EventCategory below
 
36
   * 2. Update #define _LOGLEVEL_CATEGORIES (found below) with the number of 
 
37
   *    items in EventCategory 
 
38
   * 3. Update LogLevelCategoryName in LogLevel.cpp
 
39
   * 4. Add the event in EventLogger
 
40
   */
 
41
 
 
42
 
 
43
  /**
 
44
   * Copy operator
 
45
   */
 
46
  LogLevel & operator= (const LogLevel &);
 
47
 
 
48
  enum EventCategory {
 
49
    llInvalid = -1,
 
50
    llStartUp = CFG_LOGLEVEL_STARTUP - CFG_MIN_LOGLEVEL,
 
51
    llShutdown = CFG_LOGLEVEL_SHUTDOWN - CFG_MIN_LOGLEVEL,
 
52
    llStatistic = CFG_LOGLEVEL_STATISTICS - CFG_MIN_LOGLEVEL,
 
53
    llCheckpoint = CFG_LOGLEVEL_CHECKPOINT - CFG_MIN_LOGLEVEL,
 
54
    llNodeRestart = CFG_LOGLEVEL_NODERESTART - CFG_MIN_LOGLEVEL,
 
55
    llConnection = CFG_LOGLEVEL_CONNECTION - CFG_MIN_LOGLEVEL,
 
56
    llInfo = CFG_LOGLEVEL_INFO - CFG_MIN_LOGLEVEL,
 
57
    llWarning = CFG_LOGLEVEL_WARNING - CFG_MIN_LOGLEVEL,
 
58
    llError = CFG_LOGLEVEL_ERROR - CFG_MIN_LOGLEVEL,
 
59
    llCongestion = CFG_LOGLEVEL_CONGESTION - CFG_MIN_LOGLEVEL,
 
60
    llDebug = CFG_LOGLEVEL_DEBUG - CFG_MIN_LOGLEVEL
 
61
    ,llBackup = CFG_LOGLEVEL_BACKUP - CFG_MIN_LOGLEVEL
 
62
  };
 
63
 
 
64
  /**
 
65
   * No of categories
 
66
   */
 
67
#define _LOGLEVEL_CATEGORIES (CFG_MAX_LOGLEVEL - CFG_MIN_LOGLEVEL + 1)
 
68
  STATIC_CONST( LOGLEVEL_CATEGORIES = _LOGLEVEL_CATEGORIES );
 
69
  
 
70
  void clear();
 
71
  
 
72
  /**
 
73
   * Note level is valid as 0-15
 
74
   */
 
75
  int setLogLevel(EventCategory ec, Uint32 level = 7);
 
76
  
 
77
  /**
 
78
   * Get the loglevel (0-15) for a category
 
79
   */
 
80
  Uint32 getLogLevel(EventCategory ec) const;
 
81
  
 
82
  /**
 
83
   * Set this= max(this, ll) per category
 
84
   */
 
85
  LogLevel& set_max(const LogLevel& ll);
 
86
  
 
87
  bool operator==(const LogLevel& l) const { 
 
88
    return memcmp(this, &l, sizeof(* this)) == 0;
 
89
  }
 
90
 
 
91
  LogLevel& operator=(const struct EventSubscribeReq & req);
 
92
  
 
93
private:
 
94
  /**
 
95
   * The actual data
 
96
   */
 
97
  Uint8 logLevelData[LOGLEVEL_CATEGORIES];
 
98
};
 
99
 
 
100
inline
 
101
LogLevel::LogLevel(){
 
102
  clear();
 
103
}
 
104
 
 
105
inline
 
106
LogLevel & 
 
107
LogLevel::operator= (const LogLevel & org){
 
108
  memcpy(logLevelData, org.logLevelData, sizeof(logLevelData));
 
109
  return * this;
 
110
}
 
111
 
 
112
inline
 
113
void
 
114
LogLevel::clear(){
 
115
  for(Uint32 i = 0; i<LOGLEVEL_CATEGORIES; i++){
 
116
    logLevelData[i] = 0;
 
117
  }
 
118
}
 
119
 
 
120
inline
 
121
int
 
122
LogLevel::setLogLevel(EventCategory ec, Uint32 level){
 
123
  if (ec >= 0 && (Uint32) ec < LOGLEVEL_CATEGORIES)
 
124
  {
 
125
    logLevelData[ec] = (Uint8)level;
 
126
    return 0;
 
127
  }
 
128
  return 1;
 
129
}
 
130
 
 
131
inline
 
132
Uint32
 
133
LogLevel::getLogLevel(EventCategory ec) const{
 
134
  assert(ec >= 0 && (Uint32) ec < LOGLEVEL_CATEGORIES);
 
135
 
 
136
  return (Uint32)logLevelData[ec];
 
137
}
 
138
 
 
139
inline
 
140
LogLevel & 
 
141
LogLevel::set_max(const LogLevel & org){
 
142
  for(Uint32 i = 0; i<LOGLEVEL_CATEGORIES; i++){
 
143
    if(logLevelData[i] < org.logLevelData[i])
 
144
      logLevelData[i] = org.logLevelData[i];
 
145
  }
 
146
  return * this;
 
147
}
 
148
 
 
149
#include "signaldata/EventSubscribeReq.hpp"
 
150
 
 
151
inline
 
152
LogLevel&
 
153
LogLevel::operator=(const EventSubscribeReq& req)
 
154
{
 
155
  clear();
 
156
  for(size_t i = 0; i<req.noOfEntries; i++){
 
157
    logLevelData[(req.theData[i] >> 16)] = req.theData[i] & 0xFFFF;
 
158
  }
 
159
  return * this;
 
160
}
 
161
 
 
162
#endif