36
36
using namespace std;
37
37
using namespace drizzled;
39
namespace drizzle_plugin
39
namespace syslog_module
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;
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;
50
52
static int init(drizzled::module::Context &context)
52
54
const module::option_map &vm= context.getOptions();
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));
56
if (vm.count("logging_threshold-slow"))
58
if (sysvar_logging_threshold_slow > ULONG_MAX)
60
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-slow\n"));
65
if (vm.count("logging-threshold-big-resultset"))
67
if (sysvar_logging_threshold_big_resultset > 2)
69
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-resultset\n"));
74
if (vm.count("logging-threshold-big-examined"))
76
if (sysvar_logging_threshold_big_examined > 2)
78
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-examined\n"));
83
if (vm.count("ident"))
85
sysvar_ident= strdup(vm["ident"].as<string>().c_str());
90
sysvar_ident= strdup("drizzled");
93
if (vm.count("facility"))
95
sysvar_facility= strdup(vm["facility"].as<string>().c_str());
100
sysvar_facility= strdup("local0");
103
if (vm.count("logging-priority"))
105
sysvar_logging_priority= strdup(vm["logging-priority"].as<string>().c_str());
110
sysvar_logging_priority= strdup("info");
113
if (vm.count("errmsg-priority"))
115
sysvar_errmsg_priority= strdup(vm["errmsg-priority"].as<string>().c_str());
120
sysvar_errmsg_priority= strdup("warning");
123
context.add(new Logging_syslog());
124
context.add(new ErrorMessage_syslog());
125
context.add(new plugin::Create_function<Function_syslog>("syslog"));
129
static DRIZZLE_SYSVAR_STR(
134
NULL, /* check func */
135
NULL, /* update func*/
136
"drizzled" /* default */);
138
static DRIZZLE_SYSVAR_STR(
142
N_("Syslog Facility"),
143
NULL, /* check func */
144
NULL, /* update func*/
145
"local0" /* default */); // local0 is what PostGreSQL uses by default
147
static DRIZZLE_SYSVAR_BOOL(
149
sysvar_logging_enable,
151
N_("Enable logging to syslog of the query log"),
152
NULL, /* check func */
153
NULL, /* update func */
154
false /* default */);
156
static DRIZZLE_SYSVAR_STR(
158
sysvar_logging_priority,
160
N_("Syslog Priority of query logging"),
161
NULL, /* check func */
162
NULL, /* update func*/
163
"info" /* default */);
165
static DRIZZLE_SYSVAR_ULONG(
166
logging_threshold_slow,
167
sysvar_logging_threshold_slow,
169
N_("Threshold for logging slow queries, in microseconds"),
170
NULL, /* check func */
171
NULL, /* update func */
177
static DRIZZLE_SYSVAR_ULONG(
178
logging_threshold_big_resultset,
179
sysvar_logging_threshold_big_resultset,
181
N_("Threshold for logging big queries, for rows returned"),
182
NULL, /* check func */
183
NULL, /* update func */
189
static DRIZZLE_SYSVAR_ULONG(
190
logging_threshold_big_examined,
191
sysvar_logging_threshold_big_examined,
193
N_("Threshold for logging big queries, for rows examined"),
194
NULL, /* check func */
195
NULL, /* update func */
201
static DRIZZLE_SYSVAR_BOOL(
203
sysvar_errmsg_enable,
205
N_("Enable logging to syslog of the error messages"),
206
NULL, /* check func */
207
NULL, /* update func */
208
false /* default */);
210
static DRIZZLE_SYSVAR_STR(
212
sysvar_errmsg_priority,
214
N_("Syslog Priority of error messages"),
215
NULL, /* check func */
216
NULL, /* update func*/
217
"warning" /* default */);
91
219
static void init_options(drizzled::module::option_context &context)
94
po::value<string>()->default_value("drizzled"),
96
224
context("facility",
97
po::value<string>()->default_value("local0"),
98
_("Syslog Facility"));
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"));
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"));
247
N_("Syslog Priority of error messages"));
122
} /* namespace drizzle_plugin */
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),
263
} // namespace syslog_module
265
DRIZZLE_PLUGIN(syslog_module::init, syslog_module::system_variables, syslog_module::init_options);