~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/syslog/logging.cc

  • Committer: Olaf van der Spek
  • Date: 2011-06-23 11:44:30 UTC
  • mto: This revision was merged to the branch mainline in revision 2348.
  • Revision ID: olafvdspek@gmail.com-20110623114430-no355yypk4y3icqb
Refactor

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) 2009 Sun Microsystems
 
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
5
5
 *  Copyright (C) 2010 Mark Atwood
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
22
22
 
23
23
#include <stdarg.h>
24
24
#include <limits.h>
30
30
 
31
31
#include <drizzled/gettext.h>
32
32
#include <drizzled/session.h>
 
33
#include <drizzled/session/times.h>
 
34
#include <drizzled/sql_parse.h>
 
35
#include <drizzled/plugin.h>
33
36
 
34
37
#include "logging.h"
35
38
#include "wrap.h"
36
39
 
37
 
namespace drizzle_plugin
38
 
{
 
40
namespace drizzle_plugin {
39
41
 
40
42
logging::Syslog::Syslog(const std::string &facility,
41
43
                        const std::string &priority,
51
53
{
52
54
  if (_facility < 0)
53
55
  {
54
 
    drizzled::errmsg_printf(ERRMSG_LVL_WARN,
 
56
    drizzled::errmsg_printf(drizzled::error::WARN,
55
57
                            _("syslog facility \"%s\" not known, using \"local0\""),
56
58
                            facility.c_str());
57
59
    _facility= WrapSyslog::getFacilityByName("local0");
59
61
 
60
62
  if (_priority < 0)
61
63
  {
62
 
    drizzled::errmsg_printf(ERRMSG_LVL_WARN,
 
64
    drizzled::errmsg_printf(drizzled::error::WARN,
63
65
                            _("syslog priority \"%s\" not known, using \"info\""),
64
66
                            priority.c_str());
65
67
    _priority= WrapSyslog::getPriorityByName("info");
76
78
    return false;
77
79
  if (session->examined_row_count < _threshold_big_examined)
78
80
    return false;
79
 
  
80
 
  /* TODO, the session object should have a "utime command completed"
81
 
     inside itself, so be more accurate, and so this doesnt have to
82
 
     keep calling current_utime, which can be slow */
83
 
  
84
 
  boost::posix_time::ptime mytime(boost::posix_time::microsec_clock::local_time());
85
 
  boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
86
 
  uint64_t t_mark= (mytime-epoch).total_microseconds();
 
81
 
 
82
  /*
 
83
    TODO, the session object should have a "utime command completed"
 
84
    inside itself, so be more accurate, and so this doesnt have to
 
85
    keep calling current_utime, which can be slow.
 
86
  */
 
87
  uint64_t t_mark= session->times.getCurrentTimestamp(false);
87
88
 
88
89
  // return if query was not too slow
89
 
  if ((t_mark - session->start_utime) < _threshold_slow)
 
90
  if (session->times.getElapsedTime() < _threshold_slow)
90
91
    return false;
91
 
  
 
92
 
92
93
  drizzled::Session::QueryString query_string(session->getQueryString());
93
 
  drizzled::util::string::const_shared_ptr schema(session->schema());
 
94
  drizzled::util::string::ptr schema(session->schema());
94
95
 
95
96
  WrapSyslog::singleton()
96
97
    .log(_facility, _priority,
105
106
         (unsigned long) session->getQueryId(),
106
107
         (int) schema->size(),
107
108
         schema->empty() ? "" : schema->c_str(),
108
 
         (int) query_string->length(), 
 
109
         (int) query_string->length(),
109
110
         query_string->empty() ? "" : query_string->c_str(),
110
 
         (int) drizzled::command_name[session->command].length,
111
 
         drizzled::command_name[session->command].str,
112
 
         (unsigned long long) (t_mark - session->getConnectMicroseconds()),
113
 
         (unsigned long long) (t_mark - session->start_utime),
114
 
         (unsigned long long) (t_mark - session->utime_after_lock),
 
111
         (int) drizzled::getCommandName(session->command).size(),
 
112
         drizzled::getCommandName(session->command).c_str(),
 
113
         (unsigned long long) (t_mark - session->times.getConnectMicroseconds()),
 
114
         (unsigned long long) (session->times.getElapsedTime()),
 
115
         (unsigned long long) (t_mark - session->times.utime_after_lock),
115
116
         (unsigned long) session->sent_row_count,
116
117
         (unsigned long) session->examined_row_count,
117
118
         (unsigned long) session->tmp_table,
118
119
         (unsigned long) session->total_warn_count);
119
 
  
 
120
 
120
121
    return false;
121
122
}
122
123