~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/syslog/module.cc

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

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"
21
22
 
22
23
#include <drizzled/plugin.h>
23
24
#include <drizzled/plugin/logging.h>
24
25
#include <drizzled/plugin/error_message.h>
25
26
#include <drizzled/plugin/function.h>
26
27
 
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 drizzle_plugin
 
39
namespace syslog_module
40
40
{
41
41
 
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;
 
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;
48
51
 
49
52
 
50
53
static int init(drizzled::module::Context &context)
51
54
{
52
55
  const module::option_map &vm= context.getOptions();
53
56
 
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
 
 
 
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
      exit(-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
      exit(-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
      exit(-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"));
87
124
  return 0;
88
125
}
89
126
 
 
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 */);
90
216
 
91
217
static void init_options(drizzled::module::option_context &context)
92
218
{
93
219
  context("ident",
94
 
          po::value<string>()->default_value("drizzled"),
95
 
          _("Syslog Ident"));
 
220
          po::value<string>(),
 
221
          N_("Syslog Ident"));
96
222
  context("facility",
97
 
          po::value<string>()->default_value("local0"),
98
 
          _("Syslog Facility"));
 
223
          po::value<string>(),
 
224
          N_("Syslog Facility"));
99
225
  context("logging-enable",
100
226
          po::value<bool>(&sysvar_logging_enable)->default_value(false)->zero_tokens(),
101
 
          _("Enable logging to syslog of the query log"));
 
227
          N_("Enable logging to syslog of the query log"));
102
228
  context("logging-priority",
103
 
          po::value<string>()->default_value("warning"),
104
 
          _("Syslog Priority of query logging"));
 
229
          po::value<string>(),
 
230
          N_("Syslog Priority of query logging"));
105
231
  context("logging-threshold-slow",
106
 
          po::value<uint64_constraint>(&sysvar_logging_threshold_slow)->default_value(0),
107
 
          _("Threshold for logging slow queries, in microseconds"));
 
232
          po::value<unsigned long>(&sysvar_logging_threshold_slow)->default_value(0),
 
233
          N_("Threshold for logging slow queries, in microseconds"));
108
234
  context("logging-threshold-big-resultset",
109
 
          po::value<uint64_constraint>(&sysvar_logging_threshold_big_resultset)->default_value(0),
110
 
          _("Threshold for logging big queries, for rows returned"));
 
235
          po::value<unsigned long>(&sysvar_logging_threshold_big_resultset)->default_value(0),
 
236
          N_("Threshold for logging big queries, for rows returned"));
111
237
  context("logging-threshold-big-examined",
112
 
          po::value<uint64_constraint>(&sysvar_logging_threshold_big_examined)->default_value(0),
113
 
          _("Threshold for logging big queries, for rows examined"));
 
238
          po::value<unsigned long>(&sysvar_logging_threshold_big_examined)->default_value(0),
 
239
          N_("Threshold for logging big queries, for rows examined"));
114
240
  context("errmsg-enable",
115
241
          po::value<bool>(&sysvar_errmsg_enable)->default_value(false)->zero_tokens(),
116
 
          _("Enable logging to syslog of the error messages"));
 
242
          N_("Enable logging to syslog of the error messages"));
117
243
  context("errmsg-priority",
118
 
          po::value<string>()->default_value("warning"),
119
 
          _("Syslog Priority of error messages"));
 
244
          po::value<string>(),
 
245
          N_("Syslog Priority of error messages"));
120
246
}
121
247
 
122
 
} /* namespace drizzle_plugin */
123
 
 
124
 
DRIZZLE_PLUGIN(drizzle_plugin::init, NULL, drizzle_plugin::init_options);
 
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);