1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2009 Sun Microsystems, Inc.
|
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
5 |
* Copyright (C) 2010 Mark Atwood
|
6 |
*
|
|
7 |
* This program is free software; you can redistribute it and/or modify
|
|
8 |
* it under the terms of the GNU General Public License as published by
|
|
9 |
* the Free Software Foundation; version 2 of the License.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
21 |
#include "config.h" |
|
22 |
||
23 |
#include <stdarg.h> |
|
24 |
#include <limits.h> |
|
25 |
#include <sys/types.h> |
|
26 |
#include <sys/stat.h> |
|
27 |
#include <fcntl.h> |
|
28 |
||
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
29 |
#include <boost/date_time.hpp> |
30 |
||
31 |
#include <drizzled/gettext.h> |
|
32 |
#include <drizzled/session.h> |
|
33 |
||
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
34 |
#include "logging.h" |
35 |
#include "wrap.h" |
|
36 |
||
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
37 |
namespace drizzle_plugin |
38 |
{
|
|
39 |
||
40 |
logging::Syslog::Syslog(const std::string &facility, |
|
41 |
const std::string &priority, |
|
42 |
uint64_t threshold_slow, |
|
43 |
uint64_t threshold_big_resultset, |
|
44 |
uint64_t threshold_big_examined) : |
|
45 |
drizzled::plugin::Logging("Syslog Logging"), |
|
46 |
_facility(WrapSyslog::getFacilityByName(facility.c_str())), |
|
47 |
_priority(WrapSyslog::getPriorityByName(priority.c_str())), |
|
48 |
_threshold_slow(threshold_slow), |
|
49 |
_threshold_big_resultset(threshold_big_resultset), |
|
50 |
_threshold_big_examined(threshold_big_examined) |
|
51 |
{
|
|
52 |
if (_facility < 0) |
|
53 |
{
|
|
54 |
drizzled::errmsg_printf(ERRMSG_LVL_WARN, |
|
55 |
_("syslog facility \"%s\" not known, using \"local0\""), |
|
56 |
facility.c_str()); |
|
57 |
_facility= WrapSyslog::getFacilityByName("local0"); |
|
58 |
}
|
|
59 |
||
60 |
if (_priority < 0) |
|
61 |
{
|
|
62 |
drizzled::errmsg_printf(ERRMSG_LVL_WARN, |
|
63 |
_("syslog priority \"%s\" not known, using \"info\""), |
|
64 |
priority.c_str()); |
|
65 |
_priority= WrapSyslog::getPriorityByName("info"); |
|
66 |
}
|
|
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
67 |
}
|
68 |
||
69 |
||
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
70 |
bool logging::Syslog::post(drizzled::Session *session) |
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
71 |
{
|
72 |
assert(session != NULL); |
|
73 |
||
74 |
// return if query was not too small
|
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
75 |
if (session->sent_row_count < _threshold_big_resultset) |
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
76 |
return false; |
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
77 |
if (session->examined_row_count < _threshold_big_examined) |
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
78 |
return false; |
79 |
||
80 |
/* TODO, the session object should have a "utime command completed"
|
|
81 |
inside itself, so be more accurate, and so this doesnt have to
|
|
82 |
keep calling current_utime, which can be slow */
|
|
83 |
||
1878.10.1
by Billy Earney
removed my_micro_time, my_micro_time_and_time, along with my_getsystime and replaced with boost:date_time for compatibility between OS. |
84 |
boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time()); |
85 |
boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1)); |
|
86 |
uint64_t t_mark= (mytime-epoch).total_microseconds(); |
|
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
87 |
|
88 |
// return if query was not too slow
|
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
89 |
if ((t_mark - session->start_utime) < _threshold_slow) |
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
90 |
return false; |
91 |
||
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
92 |
drizzled::Session::QueryString query_string(session->getQueryString()); |
1976.5.2
by Brian Aker
This resolves the issue where one thread may be looking at schema while |
93 |
drizzled::util::string::const_shared_ptr schema(session->schema()); |
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
94 |
|
95 |
WrapSyslog::singleton() |
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
96 |
.log(_facility, _priority, |
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
97 |
"thread_id=%ld query_id=%ld"
|
98 |
" db=\"%.*s\"" |
|
99 |
" query=\"%.*s\"" |
|
100 |
" command=\"%.*s\"" |
|
101 |
" t_connect=%lld t_start=%lld t_lock=%lld"
|
|
102 |
" rows_sent=%ld rows_examined=%ld"
|
|
103 |
" tmp_table=%ld total_warn_count=%ld\n", |
|
104 |
(unsigned long) session->thread_id, |
|
105 |
(unsigned long) session->getQueryId(), |
|
1976.5.2
by Brian Aker
This resolves the issue where one thread may be looking at schema while |
106 |
(int) schema->size(), |
107 |
schema->empty() ? "" : schema->c_str(), |
|
1921.4.13
by Brian Aker
Fix issue where session info might not be correct. |
108 |
(int) query_string->length(), |
109 |
query_string->empty() ? "" : query_string->c_str(), |
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
110 |
(int) drizzled::command_name[session->command].length, |
111 |
drizzled::command_name[session->command].str, |
|
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
112 |
(unsigned long long) (t_mark - session->getConnectMicroseconds()), |
113 |
(unsigned long long) (t_mark - session->start_utime), |
|
114 |
(unsigned long long) (t_mark - session->utime_after_lock), |
|
115 |
(unsigned long) session->sent_row_count, |
|
116 |
(unsigned long) session->examined_row_count, |
|
117 |
(unsigned long) session->tmp_table, |
|
118 |
(unsigned long) session->total_warn_count); |
|
119 |
||
120 |
return false; |
|
121 |
}
|
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
122 |
|
123 |
} /* namespsace drizzle_plugin */ |