26
29
#include <sys/stat.h>
29
#include <boost/date_time.hpp>
31
#include <drizzled/gettext.h>
32
#include <drizzled/session.h>
34
32
#include "logging.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(ERRMSG_LVL_WARN,
55
_("syslog facility \"%s\" not known, using \"local0\""),
57
_facility= WrapSyslog::getFacilityByName("local0");
62
drizzled::errmsg_printf(ERRMSG_LVL_WARN,
63
_("syslog priority \"%s\" not known, using \"info\""),
65
_priority= WrapSyslog::getPriorityByName("info");
35
using namespace drizzled;
37
Logging_syslog::Logging_syslog()
38
: drizzled::plugin::Logging("Logging_syslog")
40
syslog_facility= WrapSyslog::getFacilityByName(syslog_module::sysvar_facility);
41
if (syslog_facility < 0)
43
errmsg_printf(ERRMSG_LVL_WARN,
44
_("syslog facility \"%s\" not known, using \"local0\""),
45
syslog_module::sysvar_facility);
46
syslog_facility= WrapSyslog::getFacilityByName("local0");
49
syslog_priority= WrapSyslog::getPriorityByName(syslog_module::sysvar_logging_priority);
50
if (syslog_priority < 0)
52
errmsg_printf(ERRMSG_LVL_WARN,
53
_("syslog priority \"%s\" not known, using \"info\""),
54
syslog_module::sysvar_logging_priority);
55
syslog_priority= WrapSyslog::getPriorityByName("info");
58
WrapSyslog::singleton().openlog(syslog_module::sysvar_ident);
70
bool logging::Syslog::post(drizzled::Session *session)
62
bool Logging_syslog::post (Session *session)
72
64
assert(session != NULL);
66
if (syslog_module::sysvar_logging_enable == false)
74
69
// return if query was not too small
75
if (session->sent_row_count < _threshold_big_resultset)
70
if (session->sent_row_count < syslog_module::sysvar_logging_threshold_big_resultset)
77
if (session->examined_row_count < _threshold_big_examined)
72
if (session->examined_row_count < syslog_module::sysvar_logging_threshold_big_examined)
80
75
/* TODO, the session object should have a "utime command completed"
86
81
uint64_t t_mark= (mytime-epoch).total_microseconds();
88
83
// return if query was not too slow
89
if ((t_mark - session->start_utime) < _threshold_slow)
84
if ((t_mark - session->start_utime) < syslog_module::sysvar_logging_threshold_slow)
92
drizzled::Session::QueryString query_string(session->getQueryString());
93
drizzled::util::string::const_shared_ptr schema(session->schema());
87
Session::QueryString query_string(session->getQueryString());
95
89
WrapSyslog::singleton()
96
.log(_facility, _priority,
90
.log(syslog_facility, syslog_priority,
97
91
"thread_id=%ld query_id=%ld"
103
97
" tmp_table=%ld total_warn_count=%ld\n",
104
98
(unsigned long) session->thread_id,
105
99
(unsigned long) session->getQueryId(),
106
(int) schema->size(),
107
schema->empty() ? "" : schema->c_str(),
100
(int) session->getSchema().length(),
101
session->getSchema().empty() ? "" : session->getSchema().c_str(),
108
102
(int) query_string->length(),
109
103
query_string->empty() ? "" : query_string->c_str(),
110
(int) drizzled::command_name[session->command].length,
111
drizzled::command_name[session->command].str,
104
(int) command_name[session->command].length,
105
command_name[session->command].str,
112
106
(unsigned long long) (t_mark - session->getConnectMicroseconds()),
113
107
(unsigned long long) (t_mark - session->start_utime),
114
108
(unsigned long long) (t_mark - session->utime_after_lock),