1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Mark Atwood
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
21
#include <drizzled/plugin_logging.h>
22
#include <drizzled/gettext.h>
23
#include <drizzled/session.h>
28
// copied from drizzled/sql_parse.cc
29
const LEX_STRING command_name[]={
30
{ C_STRING_WITH_LEN("Sleep") },
31
{ C_STRING_WITH_LEN("Quit") },
32
{ C_STRING_WITH_LEN("InitDB") },
33
{ C_STRING_WITH_LEN("Query") },
34
{ C_STRING_WITH_LEN("FieldList") },
35
{ C_STRING_WITH_LEN("CreateDB") },
36
{ C_STRING_WITH_LEN("DropDB") },
37
{ C_STRING_WITH_LEN("Refresh") },
38
{ C_STRING_WITH_LEN("Shutdown") },
39
{ C_STRING_WITH_LEN("Processlist") },
40
{ C_STRING_WITH_LEN("Connect") },
41
{ C_STRING_WITH_LEN("Kill") },
42
{ C_STRING_WITH_LEN("Ping") },
43
{ C_STRING_WITH_LEN("Time") },
44
{ C_STRING_WITH_LEN("ChangeUser") },
45
{ C_STRING_WITH_LEN("BinlogDump") },
46
{ C_STRING_WITH_LEN("ConnectOut") },
47
{ C_STRING_WITH_LEN("RegisterSlave") },
48
{ C_STRING_WITH_LEN("SetOption") },
49
{ C_STRING_WITH_LEN("Daemon") },
50
{ C_STRING_WITH_LEN("Error") }
53
/* stolen from mysys/my_getsystime
54
until the Session has a good utime "now" we can use
55
will have to use this instead */
58
static uint64_t get_microtime()
60
#if defined(HAVE_GETHRTIME)
61
return gethrtime()/1000;
65
/* loop is because gettimeofday may fail on some systems */
66
while (gettimeofday(&t, NULL) != 0) {}
67
newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
72
bool logging_syslog_func_post (Session *session)
74
assert(session != NULL);
76
/* skip returning field list, too verbose */
77
if (session->command == COM_FIELD_LIST) return false;
79
uint64_t t_mark= get_microtime();
81
syslog(LOG_INFO, "thread_id=%ld query_id=%ld"
82
" t_connect=%lld t_start=%lld t_lock=%lld"
84
" rows_sent=%ld rows_examined=%u\n"
85
" db=\"%.*s\" query=\"%.*s\"\n",
86
(unsigned long) session->thread_id,
87
(unsigned long) session->query_id,
88
(unsigned long long)(t_mark - session->connect_utime),
89
(unsigned long long)(t_mark - session->start_utime),
90
(unsigned long long)(t_mark - session->utime_after_lock),
91
(uint32_t)command_name[session->command].length,
92
command_name[session->command].str,
93
(unsigned long) session->sent_row_count,
94
(uint32_t) session->examined_row_count,
95
session->db_length, session->db,
96
session->query_length, session->query);
101
static int logging_syslog_plugin_init(void *p)
103
logging_t *l= (logging_t *) p;
105
openlog("drizzled", LOG_PID, LOG_LOCAL3);
107
l->logging_pre= NULL;
108
l->logging_post= logging_syslog_func_post;
113
static int logging_syslog_plugin_deinit(void *p)
115
logging_st *l= (logging_st *) p;
117
l->logging_pre= NULL;
118
l->logging_post= NULL;
123
static struct st_mysql_sys_var* logging_syslog_system_variables[]= {
127
mysql_declare_plugin(logging_syslog)
129
DRIZZLE_LOGGER_PLUGIN,
132
"Mark Atwood <mark@fallenpegasus.com>",
135
logging_syslog_plugin_init,
136
logging_syslog_plugin_deinit,
137
NULL, /* status variables */
138
logging_syslog_system_variables,
141
mysql_declare_plugin_end;