~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_syslog/logging_syslog.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-07-08 04:26:02 UTC
  • mto: (1089.3.4 merge)
  • mto: This revision was merged to the branch mainline in revision 1092.
  • Revision ID: osullivan.padraig@gmail.com-20090708042602-x4hmf9ny8dcpvb22
Replaced an instance where a uint8_t type was being used to hold a
collection of flags. Converted it to a std::bitset<2> instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include <drizzled/plugin/logging.h>
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/plugin/logging_handler.h>
22
22
#include <drizzled/gettext.h>
23
23
#include <drizzled/session.h>
24
24
 
31
31
#endif
32
32
 
33
33
#include <stdarg.h>
34
 
#include <limits.h>
35
 
#include <sys/time.h>
36
 
#include <sys/types.h>
37
 
#include <sys/stat.h>
38
 
#include <fcntl.h>
39
 
 
40
 
 
41
 
using namespace drizzled;
42
34
 
43
35
static bool sysvar_logging_syslog_enable= false;
44
36
static char* sysvar_logging_syslog_ident= NULL;
52
44
   until the Session has a good utime "now" we can use
53
45
   will have to use this instead */
54
46
 
 
47
#include <sys/time.h>
55
48
static uint64_t get_microtime()
56
49
{
57
50
#if defined(HAVE_GETHRTIME)
66
59
#endif
67
60
}
68
61
 
69
 
class Logging_syslog: public drizzled::plugin::Logging
 
62
class Logging_syslog: public Logging_handler
70
63
{
71
64
 
72
65
  int syslog_facility;
74
67
 
75
68
public:
76
69
 
77
 
  Logging_syslog()
78
 
    : drizzled::plugin::Logging("Logging_syslog"),
79
 
      syslog_facility(-1), syslog_priority(-1)
 
70
  Logging_syslog() : Logging_handler("Logging_syslog"), syslog_facility(-1), syslog_priority(-1)
80
71
  {
81
72
 
82
73
    for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
132
123
    if (session->examined_row_count < sysvar_logging_syslog_threshold_big_examined)
133
124
      return false;
134
125
  
 
126
    /* TODO, looks like connect_utime isnt being set in the session
 
127
       object.  We could store the time this plugin was loaded, but that
 
128
       would just be a dumb workaround. */
135
129
    /* TODO, the session object should have a "utime command completed"
136
130
       inside itself, so be more accurate, and so this doesnt have to
137
131
       keep calling current_utime, which can be slow */
143
137
  
144
138
    /* to avoid trying to printf %s something that is potentially NULL */
145
139
  
146
 
    const char *dbs= session->db.empty() ? "" : session->db.c_str();
 
140
    const char *dbs= (session->db) ? session->db : "";
 
141
    int dbl= 0;
 
142
    if (dbs)
 
143
      dbl= session->db_length;
147
144
  
148
 
    const char *qys= (! session->getQueryString().empty()) ? session->getQueryString().c_str() : "";
 
145
    const char *qys= (session->query) ? session->query : "";
149
146
    int qyl= 0;
150
147
    if (qys)
151
 
      qyl= session->getQueryLength();
 
148
      qyl= session->query_length;
152
149
    
153
150
    syslog(syslog_priority,
154
151
           "thread_id=%ld query_id=%ld"
159
156
           " rows_sent=%ld rows_examined=%ld"
160
157
           " tmp_table=%ld total_warn_count=%ld\n",
161
158
           (unsigned long) session->thread_id,
162
 
           (unsigned long) session->getQueryId(),
163
 
           (int)session->db.length(), dbs,
 
159
           (unsigned long) session->query_id,
 
160
           dbl, dbs,
164
161
           qyl, qys,
165
162
           (int) command_name[session->command].length,
166
163
           command_name[session->command].str,
167
 
           (unsigned long long) (t_mark - session->getConnectMicroseconds()),
 
164
           (unsigned long long) (t_mark - session->connect_utime),
168
165
           (unsigned long long) (t_mark - session->start_utime),
169
166
           (unsigned long long) (t_mark - session->utime_after_lock),
170
167
           (unsigned long) session->sent_row_count,
178
175
 
179
176
static Logging_syslog *handler= NULL;
180
177
 
181
 
static int logging_syslog_plugin_init(drizzled::plugin::Context &context)
 
178
static int logging_syslog_plugin_init(PluginRegistry &registry)
182
179
{
183
180
  handler= new Logging_syslog();
184
 
  context.add(handler);
 
181
  registry.add(handler);
 
182
 
 
183
  return 0;
 
184
}
 
185
 
 
186
static int logging_syslog_plugin_deinit(PluginRegistry &registry)
 
187
{
 
188
  registry.remove(handler);
 
189
  delete handler;
185
190
 
186
191
  return 0;
187
192
}
258
263
  ULONG_MAX, /* max */
259
264
  0 /* blksiz */);
260
265
 
261
 
static drizzle_sys_var* logging_syslog_system_variables[]= {
 
266
static struct st_mysql_sys_var* logging_syslog_system_variables[]= {
262
267
  DRIZZLE_SYSVAR(enable),
263
268
  DRIZZLE_SYSVAR(ident),
264
269
  DRIZZLE_SYSVAR(facility),
269
274
  NULL
270
275
};
271
276
 
272
 
DRIZZLE_DECLARE_PLUGIN
 
277
drizzle_declare_plugin(logging_syslog)
273
278
{
274
 
  DRIZZLE_VERSION_ID,
275
279
  "logging_syslog",
276
280
  "0.2",
277
281
  "Mark Atwood <mark@fallenpegasus.com>",
278
282
  N_("Log to syslog"),
279
283
  PLUGIN_LICENSE_GPL,
280
284
  logging_syslog_plugin_init,
 
285
  logging_syslog_plugin_deinit,
 
286
  NULL,   /* status variables */
281
287
  logging_syslog_system_variables,
282
288
  NULL
283
289
}
284
 
DRIZZLE_DECLARE_PLUGIN_END;
 
290
drizzle_declare_plugin_end;