25 #include <sys/types.h>
29 #include <boost/date_time.hpp>
31 #include <drizzled/gettext.h>
32 #include <drizzled/session.h>
33 #include <drizzled/session/times.h>
34 #include <drizzled/sql_parse.h>
35 #include <drizzled/plugin.h>
36 #include <drizzled/error.h>
41 namespace drizzle_plugin {
43 logging::Syslog::Syslog(
const std::string &facility,
44 uint64_t threshold_slow,
45 uint64_t threshold_big_resultset,
46 uint64_t threshold_big_examined) :
47 drizzled::plugin::Logging(
"syslog_query_log"),
48 _facility(WrapSyslog::getFacilityByName(facility.c_str())),
49 _threshold_slow(threshold_slow),
50 _threshold_big_resultset(threshold_big_resultset),
51 _threshold_big_examined(threshold_big_examined)
55 drizzled::errmsg_printf(drizzled::error::WARN,
56 _(
"syslog facility \"%s\" not known, using \"local0\""),
58 _facility= WrapSyslog::getFacilityByName(
"local0");
65 assert(session != NULL);
83 uint64_t t_mark= session->times.getCurrentTimestamp(
false);
86 if (session->times.getElapsedTime() < _threshold_slow)
92 drizzled::util::string::ptr schema(session->schema());
94 WrapSyslog::singleton()
95 .log(_facility, drizzled::error::INFO,
96 "thread_id=%ld query_id=%ld"
100 " t_connect=%lld t_start=%lld t_lock=%lld"
101 " rows_sent=%ld rows_examined=%ld"
102 " tmp_table=%ld total_warn_count=%ld\n",
103 (
unsigned long) session->thread_id,
105 (int) schema->size(),
106 schema->empty() ?
"" : schema->c_str(),
107 (int) query_string->length(),
108 query_string->empty() ?
"" : query_string->c_str(),
109 (int) drizzled::getCommandName(session->
command).size(),
110 drizzled::getCommandName(session->
command).c_str(),
111 (
unsigned long long) (t_mark - session->times.getConnectMicroseconds()),
112 (
unsigned long long) (session->times.getElapsedTime()),
113 (
unsigned long long) (t_mark - session->times.utime_after_lock),
116 (
unsigned long) session->tmp_table,
117 (
unsigned long) session->total_warn_count);