~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/syslog/module.cc

  • Committer: Brian Aker
  • Date: 2010-08-18 16:12:58 UTC
  • mto: This revision was merged to the branch mainline in revision 1720.
  • Revision ID: brian@tangent.org-20100818161258-1vm71da888dfvwsx
Remove the code surrounding stack trace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2010 Mark Atwood
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
#include "module.h"
 
22
 
 
23
#include <drizzled/plugin.h>
 
24
#include <drizzled/plugin/logging.h>
 
25
#include <drizzled/plugin/error_message.h>
 
26
#include <drizzled/plugin/function.h>
 
27
 
 
28
#include "logging.h"
 
29
#include "errmsg.h"
 
30
#include "function.h"
 
31
#include <iostream>
 
32
#include <boost/program_options.hpp>
 
33
#include <drizzled/module/option_map.h>
 
34
 
 
35
namespace po= boost::program_options;
 
36
using namespace std;
 
37
using namespace drizzled;
 
38
 
 
39
namespace syslog_module
 
40
{
 
41
 
 
42
char* sysvar_ident;
 
43
char* sysvar_facility;
 
44
bool sysvar_logging_enable;
 
45
char* sysvar_logging_priority;
 
46
unsigned long sysvar_logging_threshold_slow;
 
47
unsigned long sysvar_logging_threshold_big_resultset;
 
48
unsigned long sysvar_logging_threshold_big_examined;
 
49
bool sysvar_errmsg_enable;
 
50
char* sysvar_errmsg_priority;
 
51
 
 
52
static int init(drizzled::module::Context &context)
 
53
{
 
54
  const module::option_map &vm= context.getOptions();
 
55
 
 
56
  if (vm.count("logging_threshold-slow"))
 
57
  {
 
58
    if (sysvar_logging_threshold_slow > ULONG_MAX)
 
59
    {
 
60
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-slow\n"));
 
61
      exit(-1);
 
62
    }
 
63
  }
 
64
 
 
65
  if (vm.count("logging-threshold-big-resultset"))
 
66
  {
 
67
    if (sysvar_logging_threshold_big_resultset > 2)
 
68
    {
 
69
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-resultset\n"));
 
70
      exit(-1);
 
71
    }
 
72
  }
 
73
 
 
74
  if (vm.count("logging-threshold-big-examined"))
 
75
  {
 
76
    if (sysvar_logging_threshold_big_examined > 2)
 
77
    {
 
78
      errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-examined\n"));
 
79
      exit(-1);
 
80
    }
 
81
  }
 
82
 
 
83
  if (vm.count("ident"))
 
84
  {
 
85
    sysvar_ident= strdup(vm["ident"].as<string>().c_str());
 
86
  }
 
87
 
 
88
  else
 
89
  {
 
90
    sysvar_ident= strdup("drizzled");
 
91
  }
 
92
 
 
93
  if (vm.count("facility"))
 
94
  {
 
95
    sysvar_facility= strdup(vm["facility"].as<string>().c_str());
 
96
  }
 
97
 
 
98
  else
 
99
  {
 
100
    sysvar_facility= strdup("local0");
 
101
  }
 
102
 
 
103
  if (vm.count("logging-priority"))
 
104
  {
 
105
    sysvar_logging_priority= strdup(vm["logging-priority"].as<string>().c_str());
 
106
  }
 
107
 
 
108
  else
 
109
  {
 
110
    sysvar_logging_priority= strdup("info");
 
111
  }
 
112
 
 
113
  if (vm.count("errmsg-priority"))
 
114
  {
 
115
    sysvar_errmsg_priority= strdup(vm["errmsg-priority"].as<string>().c_str());
 
116
  }
 
117
 
 
118
  else
 
119
  {
 
120
    sysvar_errmsg_priority= strdup("warning");
 
121
  }
 
122
 
 
123
  context.add(new Logging_syslog());
 
124
  context.add(new ErrorMessage_syslog());
 
125
  context.add(new plugin::Create_function<Function_syslog>("syslog"));
 
126
  return 0;
 
127
}
 
128
 
 
129
static DRIZZLE_SYSVAR_STR(
 
130
  ident,
 
131
  sysvar_ident,
 
132
  PLUGIN_VAR_READONLY,
 
133
  N_("Syslog Ident"),
 
134
  NULL, /* check func */
 
135
  NULL, /* update func*/
 
136
  "drizzled" /* default */);
 
137
 
 
138
static DRIZZLE_SYSVAR_STR(
 
139
  facility,
 
140
  sysvar_facility,
 
141
  PLUGIN_VAR_READONLY,
 
142
  N_("Syslog Facility"),
 
143
  NULL, /* check func */
 
144
  NULL, /* update func*/
 
145
  "local0" /* default */);  // local0 is what PostGreSQL uses by default
 
146
 
 
147
static DRIZZLE_SYSVAR_BOOL(
 
148
  logging_enable,
 
149
  sysvar_logging_enable,
 
150
  PLUGIN_VAR_NOCMDARG,
 
151
  N_("Enable logging to syslog of the query log"),
 
152
  NULL, /* check func */
 
153
  NULL, /* update func */
 
154
  false /* default */);
 
155
 
 
156
static DRIZZLE_SYSVAR_STR(
 
157
  logging_priority,
 
158
  sysvar_logging_priority,
 
159
  PLUGIN_VAR_READONLY,
 
160
  N_("Syslog Priority of query logging"),
 
161
  NULL, /* check func */
 
162
  NULL, /* update func*/
 
163
  "info" /* default */);
 
164
 
 
165
static DRIZZLE_SYSVAR_ULONG(
 
166
  logging_threshold_slow,
 
167
  sysvar_logging_threshold_slow,
 
168
  PLUGIN_VAR_OPCMDARG,
 
169
  N_("Threshold for logging slow queries, in microseconds"),
 
170
  NULL, /* check func */
 
171
  NULL, /* update func */
 
172
  0, /* default */
 
173
  0, /* min */
 
174
  ULONG_MAX, /* max */
 
175
  0 /* blksiz */);
 
176
 
 
177
static DRIZZLE_SYSVAR_ULONG(
 
178
  logging_threshold_big_resultset,
 
179
  sysvar_logging_threshold_big_resultset,
 
180
  PLUGIN_VAR_OPCMDARG,
 
181
  N_("Threshold for logging big queries, for rows returned"),
 
182
  NULL, /* check func */
 
183
  NULL, /* update func */
 
184
  0, /* default */
 
185
  0, /* min */
 
186
  ULONG_MAX, /* max */
 
187
  0 /* blksiz */);
 
188
 
 
189
static DRIZZLE_SYSVAR_ULONG(
 
190
  logging_threshold_big_examined,
 
191
  sysvar_logging_threshold_big_examined,
 
192
  PLUGIN_VAR_OPCMDARG,
 
193
  N_("Threshold for logging big queries, for rows examined"),
 
194
  NULL, /* check func */
 
195
  NULL, /* update func */
 
196
  0, /* default */
 
197
  0, /* min */
 
198
  ULONG_MAX, /* max */
 
199
  0 /* blksiz */);
 
200
 
 
201
static DRIZZLE_SYSVAR_BOOL(
 
202
  errmsg_enable,
 
203
  sysvar_errmsg_enable,
 
204
  PLUGIN_VAR_NOCMDARG,
 
205
  N_("Enable logging to syslog of the error messages"),
 
206
  NULL, /* check func */
 
207
  NULL, /* update func */
 
208
  false /* default */);
 
209
 
 
210
static DRIZZLE_SYSVAR_STR(
 
211
  errmsg_priority,
 
212
  sysvar_errmsg_priority,
 
213
  PLUGIN_VAR_READONLY,
 
214
  N_("Syslog Priority of error messages"),
 
215
  NULL, /* check func */
 
216
  NULL, /* update func*/
 
217
  "warning" /* default */);
 
218
 
 
219
static void init_options(drizzled::module::option_context &context)
 
220
{
 
221
  context("ident",
 
222
          po::value<string>(),
 
223
          N_("Syslog Ident"));
 
224
  context("facility",
 
225
          po::value<string>(),
 
226
          N_("Syslog Facility"));
 
227
  context("logging-enable",
 
228
          po::value<bool>(&sysvar_logging_enable)->default_value(false)->zero_tokens(),
 
229
          N_("Enable logging to syslog of the query log"));
 
230
  context("logging-priority",
 
231
          po::value<string>(),
 
232
          N_("Syslog Priority of query logging"));
 
233
  context("logging-threshold-slow",
 
234
          po::value<unsigned long>(&sysvar_logging_threshold_slow)->default_value(0),
 
235
          N_("Threshold for logging slow queries, in microseconds"));
 
236
  context("logging-threshold-big-resultset",
 
237
          po::value<unsigned long>(&sysvar_logging_threshold_big_resultset)->default_value(0),
 
238
          N_("Threshold for logging big queries, for rows returned"));
 
239
  context("logging-threshold-big-examined",
 
240
          po::value<unsigned long>(&sysvar_logging_threshold_big_examined)->default_value(0),
 
241
          N_("Threshold for logging big queries, for rows examined"));
 
242
  context("errmsg-enable",
 
243
          po::value<bool>(&sysvar_errmsg_enable)->default_value(false)->zero_tokens(),
 
244
          N_("Enable logging to syslog of the error messages"));
 
245
  context("errmsg-priority",
 
246
          po::value<string>(),
 
247
          N_("Syslog Priority of error messages"));
 
248
}
 
249
 
 
250
static drizzle_sys_var* system_variables[]= {
 
251
  DRIZZLE_SYSVAR(ident),
 
252
  DRIZZLE_SYSVAR(facility),
 
253
  DRIZZLE_SYSVAR(logging_enable),
 
254
  DRIZZLE_SYSVAR(logging_priority),
 
255
  DRIZZLE_SYSVAR(logging_threshold_slow),
 
256
  DRIZZLE_SYSVAR(logging_threshold_big_resultset),
 
257
  DRIZZLE_SYSVAR(logging_threshold_big_examined),
 
258
  DRIZZLE_SYSVAR(errmsg_enable),
 
259
  DRIZZLE_SYSVAR(errmsg_priority),
 
260
  NULL
 
261
};
 
262
 
 
263
} // namespace syslog_module
 
264
 
 
265
DRIZZLE_PLUGIN(syslog_module::init, syslog_module::system_variables, syslog_module::init_options);