1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Mark Atwood
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.
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.
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
23
#include <drizzled/plugin.h>
24
#include <drizzled/plugin/logging.h>
25
#include <drizzled/plugin/error_message.h>
26
#include <drizzled/plugin/function.h>
32
#include <boost/program_options.hpp>
33
#include <drizzled/module/option_map.h>
35
namespace po= boost::program_options;
37
using namespace drizzled;
39
namespace syslog_module
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;
53
static int init(drizzled::module::Context &context)
55
const module::option_map &vm= context.getOptions();
57
if (vm.count("logging_threshold-slow"))
59
if (sysvar_logging_threshold_slow > ULONG_MAX)
61
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-slow\n"));
66
if (vm.count("logging-threshold-big-resultset"))
68
if (sysvar_logging_threshold_big_resultset > 2)
70
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-resultset\n"));
75
if (vm.count("logging-threshold-big-examined"))
77
if (sysvar_logging_threshold_big_examined > 2)
79
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-examined\n"));
84
if (vm.count("ident"))
86
sysvar_ident= const_cast<char *>(vm["ident"].as<string>().c_str());
90
sysvar_ident= const_cast<char *>("drizzled");
93
if (vm.count("facility"))
95
sysvar_facility= const_cast<char *>(vm["facility"].as<string>().c_str());
99
sysvar_facility= const_cast<char *>("local0");
102
if (vm.count("logging-priority"))
104
sysvar_logging_priority= const_cast<char *>(vm["logging-priority"].as<string>().c_str());
108
sysvar_logging_priority= const_cast<char *>("info");
111
if (vm.count("errmsg-priority"))
113
sysvar_errmsg_priority= const_cast<char *>(vm["errmsg-priority"].as<string>().c_str());
118
sysvar_errmsg_priority= const_cast<char *>("warning");
121
context.add(new Logging_syslog());
122
context.add(new ErrorMessage_syslog());
123
context.add(new plugin::Create_function<Function_syslog>("syslog"));
127
static DRIZZLE_SYSVAR_STR(
132
NULL, /* check func */
133
NULL, /* update func*/
134
"drizzled" /* default */);
136
static DRIZZLE_SYSVAR_STR(
140
N_("Syslog Facility"),
141
NULL, /* check func */
142
NULL, /* update func*/
143
"local0" /* default */); // local0 is what PostGreSQL uses by default
145
static DRIZZLE_SYSVAR_BOOL(
147
sysvar_logging_enable,
149
N_("Enable logging to syslog of the query log"),
150
NULL, /* check func */
151
NULL, /* update func */
152
false /* default */);
154
static DRIZZLE_SYSVAR_STR(
156
sysvar_logging_priority,
158
N_("Syslog Priority of query logging"),
159
NULL, /* check func */
160
NULL, /* update func*/
161
"info" /* default */);
163
static DRIZZLE_SYSVAR_ULONG(
164
logging_threshold_slow,
165
sysvar_logging_threshold_slow,
167
N_("Threshold for logging slow queries, in microseconds"),
168
NULL, /* check func */
169
NULL, /* update func */
175
static DRIZZLE_SYSVAR_ULONG(
176
logging_threshold_big_resultset,
177
sysvar_logging_threshold_big_resultset,
179
N_("Threshold for logging big queries, for rows returned"),
180
NULL, /* check func */
181
NULL, /* update func */
187
static DRIZZLE_SYSVAR_ULONG(
188
logging_threshold_big_examined,
189
sysvar_logging_threshold_big_examined,
191
N_("Threshold for logging big queries, for rows examined"),
192
NULL, /* check func */
193
NULL, /* update func */
199
static DRIZZLE_SYSVAR_BOOL(
201
sysvar_errmsg_enable,
203
N_("Enable logging to syslog of the error messages"),
204
NULL, /* check func */
205
NULL, /* update func */
206
false /* default */);
208
static DRIZZLE_SYSVAR_STR(
210
sysvar_errmsg_priority,
212
N_("Syslog Priority of error messages"),
213
NULL, /* check func */
214
NULL, /* update func*/
215
"warning" /* default */);
217
static void init_options(drizzled::module::option_context &context)
224
N_("Syslog Facility"));
225
context("logging-enable",
226
po::value<bool>(&sysvar_logging_enable)->default_value(false)->zero_tokens(),
227
N_("Enable logging to syslog of the query log"));
228
context("logging-priority",
230
N_("Syslog Priority of query logging"));
231
context("logging-threshold-slow",
232
po::value<unsigned long>(&sysvar_logging_threshold_slow)->default_value(0),
233
N_("Threshold for logging slow queries, in microseconds"));
234
context("logging-threshold-big-resultset",
235
po::value<unsigned long>(&sysvar_logging_threshold_big_resultset)->default_value(0),
236
N_("Threshold for logging big queries, for rows returned"));
237
context("logging-threshold-big-examined",
238
po::value<unsigned long>(&sysvar_logging_threshold_big_examined)->default_value(0),
239
N_("Threshold for logging big queries, for rows examined"));
240
context("errmsg-enable",
241
po::value<bool>(&sysvar_errmsg_enable)->default_value(false)->zero_tokens(),
242
N_("Enable logging to syslog of the error messages"));
243
context("errmsg-priority",
245
N_("Syslog Priority of error messages"));
248
static drizzle_sys_var* system_variables[]= {
249
DRIZZLE_SYSVAR(ident),
250
DRIZZLE_SYSVAR(facility),
251
DRIZZLE_SYSVAR(logging_enable),
252
DRIZZLE_SYSVAR(logging_priority),
253
DRIZZLE_SYSVAR(logging_threshold_slow),
254
DRIZZLE_SYSVAR(logging_threshold_big_resultset),
255
DRIZZLE_SYSVAR(logging_threshold_big_examined),
256
DRIZZLE_SYSVAR(errmsg_enable),
257
DRIZZLE_SYSVAR(errmsg_priority),
261
} // namespace syslog_module
263
DRIZZLE_PLUGIN(syslog_module::init, syslog_module::system_variables, syslog_module::init_options);