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;
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."));
106 if (query_log->sysvar_file_enabled)
110 errmsg_printf(error::ERROR,
"Cannot open the query log file %s", new_file);
116 query_log->sysvar_file= new_file;
134 if (query_log->sysvar_file_enabled)
136 if (logger_file->
openLogFile(query_log->sysvar_file.c_str()))
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());
139 query_log->sysvar_file_enabled=
false;
164 po::value<bool>(&query_log->sysvar_file_enabled)->default_value(
false)->zero_tokens(),
165 N_(
"Enable query logging to file"));
169 po::value<string>(&query_log->sysvar_file)->default_value(default_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());
238 context.add(query_log);
242 context.registerVariable(
246 context.registerVariable(
250 context.registerVariable(
252 "file", query_log->sysvar_file, NULL, &
update_file));
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"),
299 DRIZZLE_DECLARE_PLUGIN_END;
bool closeLogFile()
Close the log file.
const char * default_file
Default query log file.
bool openLogFile(const char *file)
Open new log file, close old log file if successful.
TODO: Rename this file - func.h is stupid.
static void init_options(drizzled::module::option_context &context)
Initialize query-log command line options.
An Proxy Wrapper around boost::program_options::variables_map.
static drizzled::plugin::QueryLog * query_log
static int init(drizzled::module::Context &context)
Add query_log plugin to Drizzle and initalize query_log system variables.
QueryLog implements the query_log plugin.
QueryLoggerFile implements logging to a file for the QueryLog class.
bool update_file(Session *, set_var *var)
Update query_log_file (query_log->sysvar_file).
void update_file_enabled(Session *, sql_var_t)
Update query_log_file_enabled (query_log->sysvar_file_enabled).