00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <stdarg.h>
00024 #include <limits.h>
00025 #include <sys/types.h>
00026 #include <sys/stat.h>
00027 #include <fcntl.h>
00028
00029 #include <boost/date_time.hpp>
00030
00031 #include <drizzled/gettext.h>
00032 #include <drizzled/session.h>
00033 #include <drizzled/sql_parse.h>
00034
00035 #include "logging.h"
00036 #include "wrap.h"
00037
00038 namespace drizzle_plugin
00039 {
00040
00041 logging::Syslog::Syslog(const std::string &facility,
00042 const std::string &priority,
00043 uint64_t threshold_slow,
00044 uint64_t threshold_big_resultset,
00045 uint64_t threshold_big_examined) :
00046 drizzled::plugin::Logging("Syslog Logging"),
00047 _facility(WrapSyslog::getFacilityByName(facility.c_str())),
00048 _priority(WrapSyslog::getPriorityByName(priority.c_str())),
00049 _threshold_slow(threshold_slow),
00050 _threshold_big_resultset(threshold_big_resultset),
00051 _threshold_big_examined(threshold_big_examined)
00052 {
00053 if (_facility < 0)
00054 {
00055 drizzled::errmsg_printf(drizzled::error::WARN,
00056 _("syslog facility \"%s\" not known, using \"local0\""),
00057 facility.c_str());
00058 _facility= WrapSyslog::getFacilityByName("local0");
00059 }
00060
00061 if (_priority < 0)
00062 {
00063 drizzled::errmsg_printf(drizzled::error::WARN,
00064 _("syslog priority \"%s\" not known, using \"info\""),
00065 priority.c_str());
00066 _priority= WrapSyslog::getPriorityByName("info");
00067 }
00068 }
00069
00070
00071 bool logging::Syslog::post(drizzled::Session *session)
00072 {
00073 assert(session != NULL);
00074
00075
00076 if (session->sent_row_count < _threshold_big_resultset)
00077 return false;
00078 if (session->examined_row_count < _threshold_big_examined)
00079 return false;
00080
00081
00082
00083
00084
00085
00086 uint64_t t_mark= session->getCurrentTimestamp(false);
00087
00088
00089 if (session->getElapsedTime() < _threshold_slow)
00090 return false;
00091
00092 drizzled::Session::QueryString query_string(session->getQueryString());
00093 drizzled::util::string::const_shared_ptr schema(session->schema());
00094
00095 WrapSyslog::singleton()
00096 .log(_facility, _priority,
00097 "thread_id=%ld query_id=%ld"
00098 " db=\"%.*s\""
00099 " query=\"%.*s\""
00100 " command=\"%.*s\""
00101 " t_connect=%lld t_start=%lld t_lock=%lld"
00102 " rows_sent=%ld rows_examined=%ld"
00103 " tmp_table=%ld total_warn_count=%ld\n",
00104 (unsigned long) session->thread_id,
00105 (unsigned long) session->getQueryId(),
00106 (int) schema->size(),
00107 schema->empty() ? "" : schema->c_str(),
00108 (int) query_string->length(),
00109 query_string->empty() ? "" : query_string->c_str(),
00110 (int) drizzled::getCommandName(session->command).size(),
00111 drizzled::getCommandName(session->command).c_str(),
00112 (unsigned long long) (t_mark - session->getConnectMicroseconds()),
00113 (unsigned long long) (session->getElapsedTime()),
00114 (unsigned long long) (t_mark - session->utime_after_lock),
00115 (unsigned long) session->sent_row_count,
00116 (unsigned long) session->examined_row_count,
00117 (unsigned long) session->tmp_table,
00118 (unsigned long) session->total_warn_count);
00119
00120 return false;
00121 }
00122
00123 }