36
36
using namespace std;
37
37
using namespace drizzled;
39
namespace syslog_module
39
namespace drizzle_plugin
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;
45
uint64_constraint sysvar_logging_threshold_slow;
46
uint64_constraint sysvar_logging_threshold_big_resultset;
47
uint64_constraint sysvar_logging_threshold_big_examined;
53
50
static int init(drizzled::module::Context &context)
55
52
const module::option_map &vm= context.getOptions();
57
if (vm.count("logging_threshold-slow"))
59
if (sysvar_logging_threshold_slow > ULONG_MAX)
61
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-slow\n"));
66
if (vm.count("logging-threshold-big-resultset"))
68
if (sysvar_logging_threshold_big_resultset > 2)
70
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-resultset\n"));
75
if (vm.count("logging-threshold-big-examined"))
77
if (sysvar_logging_threshold_big_examined > 2)
79
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-examined\n"));
84
if (vm.count("ident"))
86
sysvar_ident= const_cast<char *>(vm["ident"].as<string>().c_str());
90
sysvar_ident= const_cast<char *>("drizzled");
93
if (vm.count("facility"))
95
sysvar_facility= const_cast<char *>(vm["facility"].as<string>().c_str());
99
sysvar_facility= const_cast<char *>("local0");
102
if (vm.count("logging-priority"))
104
sysvar_logging_priority= const_cast<char *>(vm["logging-priority"].as<string>().c_str());
108
sysvar_logging_priority= const_cast<char *>("info");
111
if (vm.count("errmsg-priority"))
113
sysvar_errmsg_priority= const_cast<char *>(vm["errmsg-priority"].as<string>().c_str());
118
sysvar_errmsg_priority= const_cast<char *>("warning");
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)
57
context.add(new error_message::Syslog(vm["facility"].as<string>(),
58
vm["errmsg-priority"].as<string>()));
60
if (sysvar_logging_enable)
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()));
68
context.add(new plugin::Create_function<udf::Syslog>("syslog"));
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));
127
static DRIZZLE_SYSVAR_STR(
132
NULL, /* check func */
133
NULL, /* update func*/
134
"drizzled" /* default */);
136
static DRIZZLE_SYSVAR_STR(
140
N_("Syslog Facility"),
141
NULL, /* check func */
142
NULL, /* update func*/
143
"local0" /* default */); // local0 is what PostGreSQL uses by default
145
static DRIZZLE_SYSVAR_BOOL(
147
sysvar_logging_enable,
149
N_("Enable logging to syslog of the query log"),
150
NULL, /* check func */
151
NULL, /* update func */
152
false /* default */);
154
static DRIZZLE_SYSVAR_STR(
156
sysvar_logging_priority,
158
N_("Syslog Priority of query logging"),
159
NULL, /* check func */
160
NULL, /* update func*/
161
"info" /* default */);
163
static DRIZZLE_SYSVAR_ULONG(
164
logging_threshold_slow,
165
sysvar_logging_threshold_slow,
167
N_("Threshold for logging slow queries, in microseconds"),
168
NULL, /* check func */
169
NULL, /* update func */
175
static DRIZZLE_SYSVAR_ULONG(
176
logging_threshold_big_resultset,
177
sysvar_logging_threshold_big_resultset,
179
N_("Threshold for logging big queries, for rows returned"),
180
NULL, /* check func */
181
NULL, /* update func */
187
static DRIZZLE_SYSVAR_ULONG(
188
logging_threshold_big_examined,
189
sysvar_logging_threshold_big_examined,
191
N_("Threshold for logging big queries, for rows examined"),
192
NULL, /* check func */
193
NULL, /* update func */
199
static DRIZZLE_SYSVAR_BOOL(
201
sysvar_errmsg_enable,
203
N_("Enable logging to syslog of the error messages"),
204
NULL, /* check func */
205
NULL, /* update func */
206
false /* default */);
208
static DRIZZLE_SYSVAR_STR(
210
sysvar_errmsg_priority,
212
N_("Syslog Priority of error messages"),
213
NULL, /* check func */
214
NULL, /* update func*/
215
"warning" /* default */);
217
91
static void init_options(drizzled::module::option_context &context)
94
po::value<string>()->default_value("drizzled"),
221
95
N_("Syslog Ident"));
222
96
context("facility",
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",
118
po::value<string>()->default_value("warning"),
245
119
N_("Syslog Priority of error messages"));
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),
261
} // namespace syslog_module
263
DRIZZLE_PLUGIN(syslog_module::init, syslog_module::system_variables, syslog_module::init_options);
122
} /* namespace drizzle_plugin */
124
DRIZZLE_PLUGIN(drizzle_plugin::init, NULL, drizzle_plugin::init_options);