17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <drizzled/plugin/logging.h>
20
#include <drizzled/server_includes.h>
21
#include <drizzled/plugin/logging_handler.h>
22
22
#include <drizzled/gettext.h>
23
23
#include <drizzled/session.h>
25
25
#include <libgearman/gearman.h>
28
#include <sys/types.h>
33
using namespace drizzled;
36
28
/* TODO make this dynamic as needed */
244
235
unsigned char qs[255];
246
237
// to avoid trying to printf %s something that is potentially NULL
247
const char *dbs= session->db.empty() ? "" : session->db.c_str();
238
const char *dbs= (session->db) ? session->db : "";
241
dbl= session->db_length;
243
// todo, add hostname, listener port, and server id to this
250
246
snprintf(msgbuf, MAX_MSG_LEN,
251
247
"%"PRIu64",%"PRIu64",%"PRIu64",\"%.*s\",\"%s\",\"%.*s\","
252
"%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64","
253
"%"PRIu32",%"PRIu32",%"PRIu32",\"%s\"",
248
"%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64
249
"%"PRIu32",%"PRIu32"",
255
251
session->thread_id,
256
session->getQueryId(),
257
253
// dont need to quote the db name, always CSV safe
258
(int)session->db.length(), dbs,
259
255
// do need to quote the query
260
quotify((const unsigned char *)session->getQueryString().c_str(),
261
session->getQueryLength(), qs, sizeof(qs)),
256
quotify((unsigned char *)session->query,
257
session->query_length, qs, sizeof(qs)),
262
258
// command_name is defined in drizzled/sql_parse.cc
263
259
// dont need to quote the command name, always CSV safe
264
260
(int)command_name[session->command].length,
270
266
session->sent_row_count,
271
267
session->examined_row_count,
272
268
session->tmp_table,
273
session->total_warn_count,
274
session->getServerId(),
269
session->total_warn_count);
278
271
char job_handle[GEARMAN_JOB_HANDLE_SIZE];
291
static LoggingGearman *handler= NULL;
284
static Logging_handler *handler= NULL;
293
static int logging_gearman_plugin_init(plugin::Context &context)
286
static int logging_gearman_plugin_init(drizzled::plugin::Registry ®istry)
295
288
handler= new LoggingGearman();
296
context.add(handler);
289
registry.add(handler);
294
static int logging_gearman_plugin_deinit(drizzled::plugin::Registry ®istry)
296
registry.remove(handler);
325
326
NULL, /* update func*/
326
327
"drizzlelog" /* default */);
328
static drizzle_sys_var* logging_gearman_system_variables[]= {
329
static struct st_mysql_sys_var* logging_gearman_system_variables[]= {
329
330
DRIZZLE_SYSVAR(enable),
330
331
DRIZZLE_SYSVAR(host),
331
332
DRIZZLE_SYSVAR(function),
335
DRIZZLE_DECLARE_PLUGIN
336
drizzle_declare_plugin(logging_gearman)
338
338
"logging_gearman",
340
340
"Mark Atwood <mark@fallenpegasus.com>",
341
341
N_("Log queries to a Gearman server"),
342
342
PLUGIN_LICENSE_GPL,
343
343
logging_gearman_plugin_init,
344
logging_gearman_plugin_deinit,
345
NULL, /* status variables */
344
346
logging_gearman_system_variables,
347
DRIZZLE_DECLARE_PLUGIN_END;
349
drizzle_declare_plugin_end;