~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/syslog/logging.cc

  • Committer: Monty Taylor
  • Date: 2010-12-02 22:51:54 UTC
  • mto: (1975.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1976.
  • Revision ID: mordred@inaugust.com-20101202225154-h54ifmga9x6cckgs
Refactored syslog module and changed it to use sys_var directly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 */
20
20
 
21
21
#include "config.h"
22
 
#include <boost/date_time.hpp>
23
 
#include <drizzled/gettext.h>
24
 
#include <drizzled/session.h>
25
22
 
26
23
#include <stdarg.h>
27
24
#include <limits.h>
29
26
#include <sys/stat.h>
30
27
#include <fcntl.h>
31
28
 
 
29
#include <boost/date_time.hpp>
 
30
 
 
31
#include <drizzled/gettext.h>
 
32
#include <drizzled/session.h>
 
33
 
32
34
#include "logging.h"
33
35
#include "wrap.h"
34
36
 
35
 
using namespace drizzled;
36
 
 
37
 
Logging_syslog::Logging_syslog()
38
 
  : drizzled::plugin::Logging("Logging_syslog")
39
 
{
40
 
  syslog_facility= WrapSyslog::getFacilityByName(syslog_module::sysvar_facility);
41
 
  if (syslog_facility < 0)
42
 
  {
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");
47
 
  }
48
 
 
49
 
  syslog_priority= WrapSyslog::getPriorityByName(syslog_module::sysvar_logging_priority);
50
 
  if (syslog_priority < 0)
51
 
  {
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");
56
 
  }
57
 
 
58
 
  WrapSyslog::singleton().openlog(syslog_module::sysvar_ident);
 
37
namespace drizzle_plugin
 
38
{
 
39
 
 
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)
 
51
{
 
52
  if (_facility < 0)
 
53
  {
 
54
    drizzled::errmsg_printf(ERRMSG_LVL_WARN,
 
55
                            _("syslog facility \"%s\" not known, using \"local0\""),
 
56
                            facility.c_str());
 
57
    _facility= WrapSyslog::getFacilityByName("local0");
 
58
  }
 
59
 
 
60
  if (_priority < 0)
 
61
  {
 
62
    drizzled::errmsg_printf(ERRMSG_LVL_WARN,
 
63
                            _("syslog priority \"%s\" not known, using \"info\""),
 
64
                            priority.c_str());
 
65
    _priority= WrapSyslog::getPriorityByName("info");
 
66
  }
59
67
}
60
68
 
61
69
 
62
 
bool Logging_syslog::post (Session *session)
 
70
bool logging::Syslog::post(drizzled::Session *session)
63
71
{
64
72
  assert(session != NULL);
65
73
 
66
 
  if (syslog_module::sysvar_logging_enable == false)
67
 
    return false;
68
 
  
69
74
  // return if query was not too small
70
 
  if (session->sent_row_count < syslog_module::sysvar_logging_threshold_big_resultset)
 
75
  if (session->sent_row_count < _threshold_big_resultset)
71
76
    return false;
72
 
  if (session->examined_row_count < syslog_module::sysvar_logging_threshold_big_examined)
 
77
  if (session->examined_row_count < _threshold_big_examined)
73
78
    return false;
74
79
  
75
80
  /* TODO, the session object should have a "utime command completed"
81
86
  uint64_t t_mark= (mytime-epoch).total_microseconds();
82
87
 
83
88
  // return if query was not too slow
84
 
  if ((t_mark - session->start_utime) < syslog_module::sysvar_logging_threshold_slow)
 
89
  if ((t_mark - session->start_utime) < _threshold_slow)
85
90
    return false;
86
91
  
87
 
  Session::QueryString query_string(session->getQueryString());
 
92
  drizzled::Session::QueryString query_string(session->getQueryString());
88
93
 
89
94
  WrapSyslog::singleton()
90
 
    .log(syslog_facility, syslog_priority,
 
95
    .log(_facility, _priority,
91
96
         "thread_id=%ld query_id=%ld"
92
97
         " db=\"%.*s\""
93
98
         " query=\"%.*s\""
101
106
         session->getSchema().empty() ? "" : session->getSchema().c_str(),
102
107
         (int) query_string->length(), 
103
108
         query_string->empty() ? "" : query_string->c_str(),
104
 
         (int) command_name[session->command].length,
105
 
         command_name[session->command].str,
 
109
         (int) drizzled::command_name[session->command].length,
 
110
         drizzled::command_name[session->command].str,
106
111
         (unsigned long long) (t_mark - session->getConnectMicroseconds()),
107
112
         (unsigned long long) (t_mark - session->start_utime),
108
113
         (unsigned long long) (t_mark - session->utime_after_lock),
113
118
  
114
119
    return false;
115
120
}
 
121
 
 
122
} /* namespsace drizzle_plugin */