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 <cstdarg>
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/session/times.h>
00034 #include <drizzled/sql_parse.h>
00035 #include <drizzled/plugin.h>
00036 #include <drizzled/error.h>
00037
00038 #include "logging.h"
00039 #include "wrap.h"
00040
00041 namespace drizzle_plugin {
00042
00043 logging::Syslog::Syslog(const std::string &facility,
00044 uint64_t threshold_slow,
00045 uint64_t threshold_big_resultset,
00046 uint64_t threshold_big_examined) :
00047 drizzled::plugin::Logging("Syslog Logging"),
00048 _facility(WrapSyslog::getFacilityByName(facility.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
00062
00063 bool logging::Syslog::post(drizzled::Session *session)
00064 {
00065 assert(session != NULL);
00066
00067
00068 if (session->sent_row_count < _threshold_big_resultset)
00069 {
00070 return false;
00071 }
00072
00073 if (session->examined_row_count < _threshold_big_examined)
00074 {
00075 return false;
00076 }
00077
00078
00079
00080
00081
00082
00083 uint64_t t_mark= session->times.getCurrentTimestamp(false);
00084
00085
00086 if (session->times.getElapsedTime() < _threshold_slow)
00087 {
00088 return false;
00089 }
00090
00091 drizzled::Session::QueryString query_string(session->getQueryString());
00092 drizzled::util::string::ptr schema(session->schema());
00093
00094 WrapSyslog::singleton()
00095 .log(_facility, drizzled::error::INFO,
00096 "thread_id=%ld query_id=%ld"
00097 " db=\"%.*s\""
00098 " query=\"%.*s\""
00099 " command=\"%.*s\""
00100 " t_connect=%lld t_start=%lld t_lock=%lld"
00101 " rows_sent=%ld rows_examined=%ld"
00102 " tmp_table=%ld total_warn_count=%ld\n",
00103 (unsigned long) session->thread_id,
00104 (unsigned long) session->getQueryId(),
00105 (int) schema->size(),
00106 schema->empty() ? "" : schema->c_str(),
00107 (int) query_string->length(),
00108 query_string->empty() ? "" : query_string->c_str(),
00109 (int) drizzled::getCommandName(session->command).size(),
00110 drizzled::getCommandName(session->command).c_str(),
00111 (unsigned long long) (t_mark - session->times.getConnectMicroseconds()),
00112 (unsigned long long) (session->times.getElapsedTime()),
00113 (unsigned long long) (t_mark - session->times.utime_after_lock),
00114 (unsigned long) session->sent_row_count,
00115 (unsigned long) session->examined_row_count,
00116 (unsigned long) session->tmp_table,
00117 (unsigned long) session->total_warn_count);
00118
00119 return false;
00120 }
00121
00122 }