22 #include <boost/program_options.hpp>
23 #include <drizzled/item.h>
24 #include <drizzled/data_home.h>
26 #include <drizzled/session.h>
27 #include <drizzled/plugin.h>
28 #include "query_log.h"
30 namespace po= boost::program_options;
32 using namespace drizzled;
34 namespace drizzle_plugin {
79 const char *new_file= var->value->
str_value.ptr();
83 errmsg_printf(error::ERROR, _(
"The query log file name must be defined."));
89 errmsg_printf(error::ERROR, _(
"The query log file name must have a value."));
110 errmsg_printf(error::ERROR,
"Cannot open the query log file %s", new_file);
138 errmsg_printf(error::ERROR,
"Cannot enable the query log file because the query log file %s cannot be opened.",
query_log->sysvar_file.c_str());
164 po::value<bool>(&
query_log->sysvar_file_enabled)->default_value(
false)->zero_tokens(),
165 N_(
"Enable query logging to file"));
170 N_(
"Query log file"));
173 "threshold-execution-time",
174 po::value<uint32_constraint>(&
query_log->sysvar_threshold_execution_time)->default_value(0),
175 _(
"Threshold for logging slow queries, in microseconds"));
178 "threshold-lock-time",
179 po::value<uint32_constraint>(&
query_log->sysvar_threshold_lock_time)->default_value(0),
180 _(
"Threshold for logging long locking queries, in microseconds"));
183 "threshold-rows-examined",
184 po::value<uint32_constraint>(&
query_log->sysvar_threshold_rows_examined)->default_value(0),
185 _(
"Threshold for logging queries that examine too many rows, integer"));
188 "threshold-rows-sent",
189 po::value<uint32_constraint>(&
query_log->sysvar_threshold_rows_sent)->default_value(0),
190 _(
"Threshold for logging queries that return too many rows, integer"));
193 "threshold-tmp-tables",
194 po::value<uint32_constraint>(&
query_log->sysvar_threshold_tmp_tables)->default_value(0),
195 _(
"Threshold for logging queries that use too many temporary tables, integer"));
198 "threshold-warnings",
199 po::value<uint32_constraint>(&
query_log->sysvar_threshold_warnings)->default_value(0),
200 _(
"Threshold for logging queries that cause too many warnings, integer"));
203 "threshold-session-time",
204 po::value<uint32_constraint>(&
query_log->sysvar_threshold_session_time)->default_value(0),
205 _(
"Threshold for logging queries that are active too long, in seconds"));
234 if (vm[
"file-enabled"].as<bool>())
235 logger_file->
openLogFile(vm[
"file"].as<string>().c_str());
242 context.registerVariable(
246 context.registerVariable(
250 context.registerVariable(
254 context.registerVariable(
256 "threshold_execution_time",
query_log->sysvar_threshold_execution_time));
258 context.registerVariable(
260 "threshold_lock_time",
query_log->sysvar_threshold_lock_time));
262 context.registerVariable(
264 "threshold_rows_examined",
query_log->sysvar_threshold_rows_examined));
266 context.registerVariable(
268 "threshold_rows_sent",
query_log->sysvar_threshold_rows_sent));
270 context.registerVariable(
272 "threshold_tmp_tables",
query_log->sysvar_threshold_tmp_tables));
274 context.registerVariable(
276 "threshold_warnings",
query_log->sysvar_threshold_warnings));
278 context.registerVariable(
280 "threshold_session_time",
query_log->sysvar_threshold_session_time));
287 DRIZZLE_DECLARE_PLUGIN
293 N_(
"Logs queries to a file"),
295 drizzle_plugin::init,
297 drizzle_plugin::init_options
299 DRIZZLE_DECLARE_PLUGIN_END;