1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems, Inc.
5
* Copyright (C) 2010 Mark Atwood
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.
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.
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
25
#include <sys/types.h>
29
#include <boost/date_time.hpp>
31
#include <drizzled/gettext.h>
32
#include <drizzled/session.h>
37
namespace drizzle_plugin
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)
54
drizzled::errmsg_printf(drizzled::error::WARN,
55
_("syslog facility \"%s\" not known, using \"local0\""),
57
_facility= WrapSyslog::getFacilityByName("local0");
62
drizzled::errmsg_printf(drizzled::error::WARN,
63
_("syslog priority \"%s\" not known, using \"info\""),
65
_priority= WrapSyslog::getPriorityByName("info");
70
bool logging::Syslog::post(drizzled::Session *session)
72
assert(session != NULL);
74
// return if query was not too small
75
if (session->sent_row_count < _threshold_big_resultset)
77
if (session->examined_row_count < _threshold_big_examined)
81
TODO, the session object should have a "utime command completed"
82
inside itself, so be more accurate, and so this doesnt have to
83
keep calling current_utime, which can be slow.
85
uint64_t t_mark= session->getCurrentTimestamp(false);
87
// return if query was not too slow
88
if (session->getElapsedTime() < _threshold_slow)
91
drizzled::Session::QueryString query_string(session->getQueryString());
92
drizzled::util::string::const_shared_ptr schema(session->schema());
94
WrapSyslog::singleton()
95
.log(_facility, _priority,
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,
104
(unsigned long) session->getQueryId(),
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->getConnectMicroseconds()),
112
(unsigned long long) (session->getElapsedTime()),
113
(unsigned long long) (t_mark - session->utime_after_lock),
114
(unsigned long) session->sent_row_count,
115
(unsigned long) session->examined_row_count,
116
(unsigned long) session->tmp_table,
117
(unsigned long) session->total_warn_count);
122
} /* namespsace drizzle_plugin */