~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/syslog/module.cc

  • Committer: Monty Taylor
  • Date: 2010-12-02 22:51:54 UTC
  • mto: (1975.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1976.
  • Revision ID: mordred@inaugust.com-20101202225154-h54ifmga9x6cckgs
Refactored syslog module and changed it to use sys_var directly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
#include "config.h"
21
 
#include "module.h"
22
21
 
23
22
#include <drizzled/plugin.h>
24
23
#include <drizzled/plugin/logging.h>
25
24
#include <drizzled/plugin/error_message.h>
26
25
#include <drizzled/plugin/function.h>
27
26
 
 
27
#include "wrap.h"
28
28
#include "logging.h"
29
29
#include "errmsg.h"
30
30
#include "function.h"
36
36
using namespace std;
37
37
using namespace drizzled;
38
38
 
39
 
namespace syslog_module
 
39
namespace drizzle_plugin
40
40
{
41
41
 
42
 
char* sysvar_ident;
43
 
char* sysvar_facility;
44
 
bool sysvar_logging_enable;
45
 
char* sysvar_logging_priority;
46
 
unsigned long sysvar_logging_threshold_slow;
47
 
unsigned long sysvar_logging_threshold_big_resultset;
48
 
unsigned long sysvar_logging_threshold_big_examined;
49
 
bool sysvar_errmsg_enable;
50
 
char* sysvar_errmsg_priority;
 
42
bool sysvar_logging_enable= false;
 
43
bool sysvar_errmsg_enable= false;
 
44
 
 
45
uint64_constraint sysvar_logging_threshold_slow;
 
46
uint64_constraint sysvar_logging_threshold_big_resultset;
 
47
uint64_constraint sysvar_logging_threshold_big_examined;
51
48
 
52
49
 
53
50
static int init(drizzled::module::Context &context)
54
51
{
55
52
  const module::option_map &vm= context.getOptions();
56
53
 
57
 
  if (vm.count("logging_threshold-slow"))
58
 
  {
59
 
    if (sysvar_logging_threshold_slow > ULONG_MAX)
60
 
    {
61
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-slow\n"));
62
 
      return 1;
63
 
    }
64
 
  }
65
 
 
66
 
  if (vm.count("logging-threshold-big-resultset"))
67
 
  {
68
 
    if (sysvar_logging_threshold_big_resultset > 2)
69
 
    {
70
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-resultset\n"));
71
 
      return 1;
72
 
    }
73
 
  }
74
 
 
75
 
  if (vm.count("logging-threshold-big-examined"))
76
 
  {
77
 
    if (sysvar_logging_threshold_big_examined > 2)
78
 
    {
79
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-examined\n"));
80
 
      return 1;
81
 
    }
82
 
  }
83
 
 
84
 
  if (vm.count("ident"))
85
 
  {
86
 
    sysvar_ident= const_cast<char *>(vm["ident"].as<string>().c_str());
87
 
  }
88
 
  else
89
 
  {
90
 
    sysvar_ident= const_cast<char *>("drizzled");
91
 
  }
92
 
 
93
 
  if (vm.count("facility"))
94
 
  {
95
 
    sysvar_facility= const_cast<char *>(vm["facility"].as<string>().c_str());
96
 
  }
97
 
  else
98
 
  {
99
 
    sysvar_facility= const_cast<char *>("local0");
100
 
  }
101
 
 
102
 
  if (vm.count("logging-priority"))
103
 
  {
104
 
    sysvar_logging_priority= const_cast<char *>(vm["logging-priority"].as<string>().c_str());
105
 
  }
106
 
  else
107
 
  {
108
 
    sysvar_logging_priority= const_cast<char *>("info");
109
 
  }
110
 
 
111
 
  if (vm.count("errmsg-priority"))
112
 
  {
113
 
    sysvar_errmsg_priority= const_cast<char *>(vm["errmsg-priority"].as<string>().c_str());
114
 
  }
115
 
 
116
 
  else
117
 
  {
118
 
    sysvar_errmsg_priority= const_cast<char *>("warning");
119
 
  }
120
 
 
121
 
  context.add(new Logging_syslog());
122
 
  context.add(new ErrorMessage_syslog());
123
 
  context.add(new plugin::Create_function<Function_syslog>("syslog"));
 
54
  WrapSyslog::singleton().openlog(vm["ident"].as<string>());
 
55
  if (sysvar_errmsg_enable)
 
56
  {
 
57
    context.add(new error_message::Syslog(vm["facility"].as<string>(),
 
58
                                          vm["errmsg-priority"].as<string>()));
 
59
  }
 
60
  if (sysvar_logging_enable)
 
61
  {
 
62
    context.add(new logging::Syslog(vm["facility"].as<string>(),
 
63
                                    vm["logging-priority"].as<string>(),
 
64
                                    sysvar_logging_threshold_slow.get(),
 
65
                                    sysvar_logging_threshold_big_resultset.get(),
 
66
                                    sysvar_logging_threshold_big_examined.get()));
 
67
  }
 
68
  context.add(new plugin::Create_function<udf::Syslog>("syslog"));
 
69
 
 
70
  context.registerVariable(new sys_var_const_string_val("facility",
 
71
                                                        vm["facility"].as<string>()));
 
72
  context.registerVariable(new sys_var_const_string_val("errmsg_priority",
 
73
                                                        vm["errmsg-priority"].as<string>()));
 
74
  context.registerVariable(new sys_var_const_string_val("logging_priority",
 
75
                                                        vm["logging-priority"].as<string>()));
 
76
  context.registerVariable(new sys_var_bool_ptr_readonly("logging_enable",
 
77
                                                         &sysvar_logging_enable));
 
78
  context.registerVariable(new sys_var_bool_ptr_readonly("errmsg_enable",
 
79
                                                         &sysvar_errmsg_enable));
 
80
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("logging_threshold_slow",
 
81
                                                                            sysvar_logging_threshold_slow));
 
82
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("logging_threshold_big_resultset",
 
83
                                                                            sysvar_logging_threshold_big_resultset));
 
84
  context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("logging_threshold_big_examined",
 
85
                                                                            sysvar_logging_threshold_big_examined));
 
86
 
124
87
  return 0;
125
88
}
126
89
 
127
 
static DRIZZLE_SYSVAR_STR(
128
 
  ident,
129
 
  sysvar_ident,
130
 
  PLUGIN_VAR_READONLY,
131
 
  N_("Syslog Ident"),
132
 
  NULL, /* check func */
133
 
  NULL, /* update func*/
134
 
  "drizzled" /* default */);
135
 
 
136
 
static DRIZZLE_SYSVAR_STR(
137
 
  facility,
138
 
  sysvar_facility,
139
 
  PLUGIN_VAR_READONLY,
140
 
  N_("Syslog Facility"),
141
 
  NULL, /* check func */
142
 
  NULL, /* update func*/
143
 
  "local0" /* default */);  // local0 is what PostGreSQL uses by default
144
 
 
145
 
static DRIZZLE_SYSVAR_BOOL(
146
 
  logging_enable,
147
 
  sysvar_logging_enable,
148
 
  PLUGIN_VAR_NOCMDARG,
149
 
  N_("Enable logging to syslog of the query log"),
150
 
  NULL, /* check func */
151
 
  NULL, /* update func */
152
 
  false /* default */);
153
 
 
154
 
static DRIZZLE_SYSVAR_STR(
155
 
  logging_priority,
156
 
  sysvar_logging_priority,
157
 
  PLUGIN_VAR_READONLY,
158
 
  N_("Syslog Priority of query logging"),
159
 
  NULL, /* check func */
160
 
  NULL, /* update func*/
161
 
  "info" /* default */);
162
 
 
163
 
static DRIZZLE_SYSVAR_ULONG(
164
 
  logging_threshold_slow,
165
 
  sysvar_logging_threshold_slow,
166
 
  PLUGIN_VAR_OPCMDARG,
167
 
  N_("Threshold for logging slow queries, in microseconds"),
168
 
  NULL, /* check func */
169
 
  NULL, /* update func */
170
 
  0, /* default */
171
 
  0, /* min */
172
 
  ULONG_MAX, /* max */
173
 
  0 /* blksiz */);
174
 
 
175
 
static DRIZZLE_SYSVAR_ULONG(
176
 
  logging_threshold_big_resultset,
177
 
  sysvar_logging_threshold_big_resultset,
178
 
  PLUGIN_VAR_OPCMDARG,
179
 
  N_("Threshold for logging big queries, for rows returned"),
180
 
  NULL, /* check func */
181
 
  NULL, /* update func */
182
 
  0, /* default */
183
 
  0, /* min */
184
 
  ULONG_MAX, /* max */
185
 
  0 /* blksiz */);
186
 
 
187
 
static DRIZZLE_SYSVAR_ULONG(
188
 
  logging_threshold_big_examined,
189
 
  sysvar_logging_threshold_big_examined,
190
 
  PLUGIN_VAR_OPCMDARG,
191
 
  N_("Threshold for logging big queries, for rows examined"),
192
 
  NULL, /* check func */
193
 
  NULL, /* update func */
194
 
  0, /* default */
195
 
  0, /* min */
196
 
  ULONG_MAX, /* max */
197
 
  0 /* blksiz */);
198
 
 
199
 
static DRIZZLE_SYSVAR_BOOL(
200
 
  errmsg_enable,
201
 
  sysvar_errmsg_enable,
202
 
  PLUGIN_VAR_NOCMDARG,
203
 
  N_("Enable logging to syslog of the error messages"),
204
 
  NULL, /* check func */
205
 
  NULL, /* update func */
206
 
  false /* default */);
207
 
 
208
 
static DRIZZLE_SYSVAR_STR(
209
 
  errmsg_priority,
210
 
  sysvar_errmsg_priority,
211
 
  PLUGIN_VAR_READONLY,
212
 
  N_("Syslog Priority of error messages"),
213
 
  NULL, /* check func */
214
 
  NULL, /* update func*/
215
 
  "warning" /* default */);
216
90
 
217
91
static void init_options(drizzled::module::option_context &context)
218
92
{
219
93
  context("ident",
220
 
          po::value<string>(),
 
94
          po::value<string>()->default_value("drizzled"),
221
95
          N_("Syslog Ident"));
222
96
  context("facility",
223
 
          po::value<string>(),
 
97
          po::value<string>()->default_value("local0"),
224
98
          N_("Syslog Facility"));
225
99
  context("logging-enable",
226
100
          po::value<bool>(&sysvar_logging_enable)->default_value(false)->zero_tokens(),
229
103
          po::value<string>(),
230
104
          N_("Syslog Priority of query logging"));
231
105
  context("logging-threshold-slow",
232
 
          po::value<unsigned long>(&sysvar_logging_threshold_slow)->default_value(0),
 
106
          po::value<uint64_constraint>(&sysvar_logging_threshold_slow)->default_value(0),
233
107
          N_("Threshold for logging slow queries, in microseconds"));
234
108
  context("logging-threshold-big-resultset",
235
 
          po::value<unsigned long>(&sysvar_logging_threshold_big_resultset)->default_value(0),
 
109
          po::value<uint64_constraint>(&sysvar_logging_threshold_big_resultset)->default_value(0),
236
110
          N_("Threshold for logging big queries, for rows returned"));
237
111
  context("logging-threshold-big-examined",
238
 
          po::value<unsigned long>(&sysvar_logging_threshold_big_examined)->default_value(0),
 
112
          po::value<uint64_constraint>(&sysvar_logging_threshold_big_examined)->default_value(0),
239
113
          N_("Threshold for logging big queries, for rows examined"));
240
114
  context("errmsg-enable",
241
115
          po::value<bool>(&sysvar_errmsg_enable)->default_value(false)->zero_tokens(),
242
116
          N_("Enable logging to syslog of the error messages"));
243
117
  context("errmsg-priority",
244
 
          po::value<string>(),
 
118
          po::value<string>()->default_value("warning"),
245
119
          N_("Syslog Priority of error messages"));
246
120
}
247
121
 
248
 
static drizzle_sys_var* system_variables[]= {
249
 
  DRIZZLE_SYSVAR(ident),
250
 
  DRIZZLE_SYSVAR(facility),
251
 
  DRIZZLE_SYSVAR(logging_enable),
252
 
  DRIZZLE_SYSVAR(logging_priority),
253
 
  DRIZZLE_SYSVAR(logging_threshold_slow),
254
 
  DRIZZLE_SYSVAR(logging_threshold_big_resultset),
255
 
  DRIZZLE_SYSVAR(logging_threshold_big_examined),
256
 
  DRIZZLE_SYSVAR(errmsg_enable),
257
 
  DRIZZLE_SYSVAR(errmsg_priority),
258
 
  NULL
259
 
};
260
 
 
261
 
} // namespace syslog_module
262
 
 
263
 
DRIZZLE_PLUGIN(syslog_module::init, syslog_module::system_variables, syslog_module::init_options);
 
122
} /* namespace drizzle_plugin */
 
123
 
 
124
DRIZZLE_PLUGIN(drizzle_plugin::init, NULL, drizzle_plugin::init_options);