~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/syslog/logging.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <config.h>
22
22
 
23
 
#include <stdarg.h>
 
23
#include <cstdarg>
24
24
#include <limits.h>
25
25
#include <sys/types.h>
26
26
#include <sys/stat.h>
30
30
 
31
31
#include <drizzled/gettext.h>
32
32
#include <drizzled/session.h>
 
33
#include <drizzled/session/times.h>
33
34
#include <drizzled/sql_parse.h>
 
35
#include <drizzled/plugin.h>
 
36
#include <drizzled/error.h>
34
37
 
35
38
#include "logging.h"
36
39
#include "wrap.h"
37
40
 
38
 
namespace drizzle_plugin
39
 
{
 
41
namespace drizzle_plugin {
40
42
 
41
43
logging::Syslog::Syslog(const std::string &facility,
42
 
                        const std::string &priority,
43
44
                        uint64_t threshold_slow,
44
45
                        uint64_t threshold_big_resultset,
45
46
                        uint64_t threshold_big_examined) :
46
 
  drizzled::plugin::Logging("Syslog Logging"),
 
47
  drizzled::plugin::Logging("syslog_query_log"),
47
48
  _facility(WrapSyslog::getFacilityByName(facility.c_str())),
48
 
  _priority(WrapSyslog::getPriorityByName(priority.c_str())),
49
49
  _threshold_slow(threshold_slow),
50
50
  _threshold_big_resultset(threshold_big_resultset),
51
51
  _threshold_big_examined(threshold_big_examined)
57
57
                            facility.c_str());
58
58
    _facility= WrapSyslog::getFacilityByName("local0");
59
59
  }
60
 
 
61
 
  if (_priority < 0)
62
 
  {
63
 
    drizzled::errmsg_printf(drizzled::error::WARN,
64
 
                            _("syslog priority \"%s\" not known, using \"info\""),
65
 
                            priority.c_str());
66
 
    _priority= WrapSyslog::getPriorityByName("info");
67
 
  }
68
60
}
69
61
 
70
62
 
74
66
 
75
67
  // return if query was not too small
76
68
  if (session->sent_row_count < _threshold_big_resultset)
 
69
  {
77
70
    return false;
 
71
  }
 
72
 
78
73
  if (session->examined_row_count < _threshold_big_examined)
 
74
  {
79
75
    return false;
 
76
  }
80
77
 
81
78
  /*
82
79
    TODO, the session object should have a "utime command completed"
83
80
    inside itself, so be more accurate, and so this doesnt have to
84
81
    keep calling current_utime, which can be slow.
85
82
  */
86
 
  uint64_t t_mark= session->getCurrentTimestamp(false);
 
83
  uint64_t t_mark= session->times.getCurrentTimestamp(false);
87
84
 
88
85
  // return if query was not too slow
89
 
  if (session->getElapsedTime() < _threshold_slow)
 
86
  if (session->times.getElapsedTime() < _threshold_slow)
 
87
  {
90
88
    return false;
 
89
  }
91
90
 
92
91
  drizzled::Session::QueryString query_string(session->getQueryString());
93
 
  drizzled::util::string::const_shared_ptr schema(session->schema());
 
92
  drizzled::util::string::ptr schema(session->schema());
94
93
 
95
94
  WrapSyslog::singleton()
96
 
    .log(_facility, _priority,
 
95
    .log(_facility, drizzled::error::INFO,
97
96
         "thread_id=%ld query_id=%ld"
98
97
         " db=\"%.*s\""
99
98
         " query=\"%.*s\""
109
108
         query_string->empty() ? "" : query_string->c_str(),
110
109
         (int) drizzled::getCommandName(session->command).size(),
111
110
         drizzled::getCommandName(session->command).c_str(),
112
 
         (unsigned long long) (t_mark - session->getConnectMicroseconds()),
113
 
         (unsigned long long) (session->getElapsedTime()),
114
 
         (unsigned long long) (t_mark - session->utime_after_lock),
 
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),
115
114
         (unsigned long) session->sent_row_count,
116
115
         (unsigned long) session->examined_row_count,
117
116
         (unsigned long) session->tmp_table,