~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/syslog/module.cc

Merge in Stewart's FK work

Show diffs side-by-side

added added

removed removed

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