~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_gearman/logging_gearman.cc

  • Committer: Brian Aker
  • Date: 2011-02-17 10:09:00 UTC
  • mfrom: (2173.2.1 clean-include-usuage)
  • Revision ID: brian@tangent.org-20110217100900-4tpuxxzdl1sj00sh
Merge Monty for headers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008,2009 Sun Microsystems
 
4
 *  Copyright (C) 2008, 2009 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
 
20
#include <config.h>
21
21
 
22
22
#include <boost/scoped_array.hpp>
23
23
 
24
24
#include <drizzled/plugin/logging.h>
25
25
#include <drizzled/gettext.h>
26
26
#include <drizzled/session.h>
 
27
#include <drizzled/errmsg_print.h>
27
28
#include <boost/date_time.hpp>
28
29
#include <boost/program_options.hpp>
29
30
#include <drizzled/module/option_map.h>
181
182
 
182
183
    if (gearman_client_create(&_gearman_client) == NULL)
183
184
    {
184
 
      char errmsg[STRERROR_MAX];
185
 
      strerror_r(errno, errmsg, sizeof(errmsg));
186
 
      drizzled::errmsg_printf(ERRMSG_LVL_ERROR, _("fail gearman_client_create(): %s"),
187
 
                              errmsg);
 
185
      drizzled::sql_perror(_("fail gearman_client_create()"));
188
186
      return;
189
187
    }
190
188
 
194
192
                                   host.c_str(), 0);
195
193
    if (ret != GEARMAN_SUCCESS)
196
194
    {
197
 
      drizzled::errmsg_printf(ERRMSG_LVL_ERROR, _("fail gearman_client_add_server(): %s"),
 
195
      drizzled::errmsg_printf(drizzled::error::ERROR, _("fail gearman_client_add_server(): %s"),
198
196
                              gearman_client_error(&_gearman_client));
199
197
      return;
200
198
    }
225
223
    if (not _gearman_client_ok)
226
224
        return false;
227
225
  
228
 
    /* TODO, the session object should have a "utime command completed"
229
 
       inside itself, so be more accurate, and so this doesnt have to
230
 
       keep calling current_utime, which can be slow */
231
 
  
232
 
    boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
233
 
    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
234
 
    uint64_t t_mark= (mytime-epoch).total_microseconds();
 
226
    /* 
 
227
      TODO, the session object should have a "utime command completed"
 
228
      inside itself, so be more accurate, and so this doesnt have to
 
229
      keep calling current_utime, which can be slow.
 
230
    */
 
231
    uint64_t t_mark= session->getCurrentTimestamp(false);
235
232
  
236
233
 
237
234
    // buffer to quotify the query
252
249
               (int)dbs->size(), dbs->c_str(),
253
250
               // do need to quote the query
254
251
               quotify((const unsigned char *)session->getQueryString()->c_str(), session->getQueryString()->length(), qs, sizeof(qs)),
255
 
               // command_name is defined in drizzled/sql_parse.cc
256
 
               // dont need to quote the command name, always CSV safe
257
 
               (int)drizzled::command_name[session->command].length,
258
 
               drizzled::command_name[session->command].str,
 
252
               // getCommandName is defined in drizzled/sql_parse.h dont
 
253
               // need to quote the command name, always CSV safe
 
254
               (int)drizzled::getCommandName(session->command).size(),
 
255
               drizzled::getCommandName(session->command).c_str(),
259
256
               // counters are at end, to make it easier to add more
260
257
               (t_mark - session->getConnectMicroseconds()),
261
 
               (t_mark - session->start_utime),
 
258
               (session->getElapsedTime()),
262
259
               (t_mark - session->utime_after_lock),
263
260
               session->sent_row_count,
264
261
               session->examined_row_count,
300
297
{
301
298
  context("host",
302
299
          po::value<std::string>()->default_value("localhost"),
303
 
          N_("Hostname for logging to a Gearman server"));
 
300
          _("Hostname for logging to a Gearman server"));
304
301
  context("function",
305
302
          po::value<std::string>()->default_value("drizzlelog"),
306
 
          N_("Gearman Function to send logging to"));
 
303
          _("Gearman Function to send logging to"));
307
304
}
308
305
 
309
306
} /* namespace drizzle_plugin */