~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/logging_syslog/logging_syslog.cc

  • Committer: Nathan Williams
  • Date: 2009-06-13 21:21:13 UTC
  • mfrom: (1062 staging)
  • mto: This revision was merged to the branch mainline in revision 1063.
  • Revision ID: nathanlws@gmail.com-20090613212113-liz01ojh1wxutgqx
Merged trunk and resolved conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
static ulong sysvar_logging_syslog_threshold_big_resultset= 0;
41
41
static ulong sysvar_logging_syslog_threshold_big_examined= 0;
42
42
 
43
 
static int syslog_facility= -1;
44
 
static int syslog_priority= -1;
45
 
 
46
43
/* stolen from mysys/my_getsystime
47
44
   until the Session has a good utime "now" we can use
48
45
   will have to use this instead */
64
61
 
65
62
class Logging_syslog: public Logging_handler
66
63
{
 
64
 
 
65
  int syslog_facility;
 
66
  int syslog_priority;
 
67
 
67
68
public:
68
69
 
69
 
  Logging_syslog() : Logging_handler("Logging_syslog") {}
 
70
  Logging_syslog() : Logging_handler("Logging_syslog"), syslog_facility(-1), syslog_priority(-1)
 
71
  {
 
72
 
 
73
    for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
 
74
    {
 
75
      if (strcasecmp(facilitynames[ndx].c_name, sysvar_logging_syslog_facility) == 0)
 
76
      {
 
77
        syslog_facility= facilitynames[ndx].c_val;
 
78
        break;
 
79
      }
 
80
    }
 
81
    if (syslog_facility == -1)
 
82
    {
 
83
      errmsg_printf(ERRMSG_LVL_WARN,
 
84
                    _("syslog facility \"%s\" not known, using \"local0\""),
 
85
                    sysvar_logging_syslog_facility);
 
86
      syslog_facility= LOG_LOCAL0;
 
87
    }
 
88
 
 
89
    for (int ndx= 0; prioritynames[ndx].c_name; ndx++)
 
90
    {
 
91
      if (strcasecmp(prioritynames[ndx].c_name, sysvar_logging_syslog_priority) == 0)
 
92
      {
 
93
        syslog_priority= prioritynames[ndx].c_val;
 
94
        break;
 
95
      }
 
96
    }
 
97
    if (syslog_priority == -1)
 
98
    {
 
99
      errmsg_printf(ERRMSG_LVL_WARN,
 
100
                    _("syslog priority \"%s\" not known, using \"info\""),
 
101
                    sysvar_logging_syslog_priority);
 
102
      syslog_priority= LOG_INFO;
 
103
    }
 
104
 
 
105
    openlog(sysvar_logging_syslog_ident,
 
106
            LOG_PID, syslog_facility);
 
107
  }
 
108
 
 
109
  ~Logging_syslog()
 
110
  {
 
111
    closelog();
 
112
  }
70
113
 
71
114
  virtual bool post (Session *session)
72
115
  {
110
153
           " query=\"%.*s\""
111
154
           " command=\"%.*s\""
112
155
           " t_connect=%lld t_start=%lld t_lock=%lld"
113
 
           " rows_sent=%ld rows_examined=%ld\n",
 
156
           " rows_sent=%ld rows_examined=%ld"
 
157
           " tmp_table=%ld total_warn_count=%ld\n",
114
158
           (unsigned long) session->thread_id,
115
159
           (unsigned long) session->query_id,
116
160
           dbl, dbs,
121
165
           (unsigned long long) (t_mark - session->start_utime),
122
166
           (unsigned long long) (t_mark - session->utime_after_lock),
123
167
           (unsigned long) session->sent_row_count,
124
 
           (unsigned long) session->examined_row_count);
125
 
  
126
 
#if 0
127
 
    syslog(syslog_priority,
128
 
           "thread_id=%ld query_id=%ld"
129
 
           " db=\"%.*s\""
130
 
           " query=\".*%s\""
131
 
           " command=%.*s"
132
 
           " t_connect=%lld t_start=%lld t_lock=%lld"
133
 
           " rows_sent=%ld rows_examined=%ld\n",
134
 
           (unsigned long) session->thread_id,
135
 
           (unsigned long) session->query_id,
136
 
           session->db_length, session->db,
137
 
           // dont need to quote the query, because syslog does it itself
138
 
           session->query_length, session->query,
139
 
           (int) command_name[session->command].length,
140
 
           command_name[session->command].str,
141
 
           (unsigned long long) (t_mark - session->connect_utime),
142
 
           (unsigned long long) (t_mark - session->start_utime),
143
 
           (unsigned long long) (t_mark - session->utime_after_lock),
144
 
           (unsigned long) session->sent_row_count,
145
 
           (unsigned long) session->examined_row_count);
146
 
  
147
 
#endif
 
168
           (unsigned long) session->examined_row_count,
 
169
           (unsigned long) session->tmp_table,
 
170
           (unsigned long) session->total_warn_count);
148
171
  
149
172
    return false;
150
173
  }
154
177
 
155
178
static int logging_syslog_plugin_init(PluginRegistry &registry)
156
179
{
157
 
  syslog_facility= -1;
158
 
  for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
159
 
  {
160
 
    if (strcasecmp(facilitynames[ndx].c_name, sysvar_logging_syslog_facility) == 0)
161
 
    {
162
 
      syslog_facility= facilitynames[ndx].c_val;
163
 
      break;
164
 
    }
165
 
  }
166
 
  if (syslog_facility == -1)
167
 
  {
168
 
    errmsg_printf(ERRMSG_LVL_WARN,
169
 
                  _("syslog facility \"%s\" not known, using \"local0\""),
170
 
                  sysvar_logging_syslog_facility);
171
 
    syslog_facility= LOG_LOCAL0;
172
 
  }
173
 
 
174
 
  syslog_priority= -1;
175
 
  for (int ndx= 0; prioritynames[ndx].c_name; ndx++)
176
 
  {
177
 
    if (strcasecmp(prioritynames[ndx].c_name, sysvar_logging_syslog_priority) == 0)
178
 
    {
179
 
      syslog_priority= prioritynames[ndx].c_val;
180
 
      break;
181
 
    }
182
 
  }
183
 
  if (syslog_priority == -1)
184
 
  {
185
 
    errmsg_printf(ERRMSG_LVL_WARN,
186
 
                  _("syslog priority \"%s\" not known, using \"info\""),
187
 
                  sysvar_logging_syslog_priority);
188
 
    syslog_priority= LOG_INFO;
189
 
  }
190
 
 
191
 
  openlog(sysvar_logging_syslog_ident,
192
 
          LOG_PID, syslog_facility);
193
 
 
194
180
  handler= new Logging_syslog();
195
181
  registry.add(handler);
196
182
 
209
195
  enable,
210
196
  sysvar_logging_syslog_enable,
211
197
  PLUGIN_VAR_NOCMDARG,
212
 
  N_("Enable logging"),
 
198
  N_("Enable logging to syslog"),
213
199
  NULL, /* check func */
214
200
  NULL, /* update func */
215
201
  false /* default */);