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;
52
static int init(drizzled::module::Context &context)
54
const module::option_map &vm= context.getOptions();
56
if (vm.count("logging_threshold-slow"))
58
if (sysvar_logging_threshold_slow > ULONG_MAX)
60
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-slow\n"));
65
if (vm.count("logging-threshold-big-resultset"))
67
if (sysvar_logging_threshold_big_resultset > 2)
69
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-resultset\n"));
74
if (vm.count("logging-threshold-big-examined"))
76
if (sysvar_logging_threshold_big_examined > 2)
78
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-examined\n"));
83
if (vm.count("ident"))
85
sysvar_ident= strdup(vm["ident"].as<string>().c_str());
90
sysvar_ident= strdup("drizzled");
93
if (vm.count("facility"))
95
sysvar_facility= strdup(vm["facility"].as<string>().c_str());
100
sysvar_facility= strdup("local0");
103
if (vm.count("logging-priority"))
105
sysvar_logging_priority= strdup(vm["logging-priority"].as<string>().c_str());
110
sysvar_logging_priority= strdup("info");
113
if (vm.count("errmsg-priority"))
115
sysvar_errmsg_priority= strdup(vm["errmsg-priority"].as<string>().c_str());
120
sysvar_errmsg_priority= strdup("warning");
123
context.add(new Logging_syslog());
124
context.add(new ErrorMessage_syslog());
125
context.add(new plugin::Create_function<Function_syslog>("syslog"));
129
static DRIZZLE_SYSVAR_STR(
134
NULL, /* check func */
135
NULL, /* update func*/
136
"drizzled" /* default */);
138
static DRIZZLE_SYSVAR_STR(
142
N_("Syslog Facility"),
143
NULL, /* check func */
144
NULL, /* update func*/
145
"local0" /* default */); // local0 is what PostGreSQL uses by default
147
static DRIZZLE_SYSVAR_BOOL(
149
sysvar_logging_enable,
151
N_("Enable logging to syslog of the query log"),
152
NULL, /* check func */
153
NULL, /* update func */
154
false /* default */);
156
static DRIZZLE_SYSVAR_STR(
158
sysvar_logging_priority,
160
N_("Syslog Priority of query logging"),
161
NULL, /* check func */
162
NULL, /* update func*/
163
"info" /* default */);
165
static DRIZZLE_SYSVAR_ULONG(
166
logging_threshold_slow,
167
sysvar_logging_threshold_slow,
169
N_("Threshold for logging slow queries, in microseconds"),
170
NULL, /* check func */
171
NULL, /* update func */
177
static DRIZZLE_SYSVAR_ULONG(
178
logging_threshold_big_resultset,
179
sysvar_logging_threshold_big_resultset,
181
N_("Threshold for logging big queries, for rows returned"),
182
NULL, /* check func */
183
NULL, /* update func */
189
static DRIZZLE_SYSVAR_ULONG(
190
logging_threshold_big_examined,
191
sysvar_logging_threshold_big_examined,
193
N_("Threshold for logging big queries, for rows examined"),
194
NULL, /* check func */
195
NULL, /* update func */
201
static DRIZZLE_SYSVAR_BOOL(
203
sysvar_errmsg_enable,
205
N_("Enable logging to syslog of the error messages"),
206
NULL, /* check func */
207
NULL, /* update func */
208
false /* default */);
210
static DRIZZLE_SYSVAR_STR(
212
sysvar_errmsg_priority,
214
N_("Syslog Priority of error messages"),
215
NULL, /* check func */
216
NULL, /* update func*/
217
"warning" /* default */);
219
static void init_options(drizzled::module::option_context &context)
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",
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",
247
N_("Syslog Priority of error messages"));
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),
263
} // namespace syslog_module
265
DRIZZLE_PLUGIN(syslog_module::init, syslog_module::system_variables, syslog_module::init_options);