1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
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" |
|
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
31 |
#include <iostream> |
32 |
#include <boost/program_options.hpp> |
|
33 |
#include <drizzled/module/option_map.h> |
|
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
34 |
|
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
35 |
namespace po= boost::program_options; |
36 |
using namespace std; |
|
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
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 |
||
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
52 |
|
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
53 |
static int init(drizzled::module::Context &context) |
54 |
{
|
|
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
55 |
const module::option_map &vm= context.getOptions(); |
56 |
||
57 |
if (vm.count("logging_threshold-slow")) |
|
58 |
{
|
|
59 |
if (sysvar_logging_threshold_slow > ULONG_MAX) |
|
60 |
{
|
|
61 |
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-slow\n")); |
|
62 |
exit(-1); |
|
63 |
}
|
|
64 |
}
|
|
65 |
||
66 |
if (vm.count("logging-threshold-big-resultset")) |
|
67 |
{
|
|
68 |
if (sysvar_logging_threshold_big_resultset > 2) |
|
69 |
{
|
|
70 |
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-resultset\n")); |
|
71 |
exit(-1); |
|
72 |
}
|
|
73 |
}
|
|
74 |
||
75 |
if (vm.count("logging-threshold-big-examined")) |
|
76 |
{
|
|
77 |
if (sysvar_logging_threshold_big_examined > 2) |
|
78 |
{
|
|
79 |
errmsg_printf(ERRMSG_LVL_ERROR, _("Invalid value for logging-threshold-big-examined\n")); |
|
80 |
exit(-1); |
|
81 |
}
|
|
82 |
}
|
|
83 |
||
84 |
if (vm.count("ident")) |
|
85 |
{
|
|
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
86 |
sysvar_ident= const_cast<char *>(vm["ident"].as<string>().c_str()); |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
87 |
}
|
88 |
else
|
|
89 |
{
|
|
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
90 |
sysvar_ident= const_cast<char *>("drizzled"); |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
91 |
}
|
92 |
||
93 |
if (vm.count("facility")) |
|
94 |
{
|
|
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
95 |
sysvar_facility= const_cast<char *>(vm["facility"].as<string>().c_str()); |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
96 |
}
|
97 |
else
|
|
98 |
{
|
|
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
99 |
sysvar_facility= const_cast<char *>("local0"); |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
100 |
}
|
101 |
||
102 |
if (vm.count("logging-priority")) |
|
103 |
{
|
|
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
104 |
sysvar_logging_priority= const_cast<char *>(vm["logging-priority"].as<string>().c_str()); |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
105 |
}
|
106 |
else
|
|
107 |
{
|
|
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
108 |
sysvar_logging_priority= const_cast<char *>("info"); |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
109 |
}
|
110 |
||
111 |
if (vm.count("errmsg-priority")) |
|
112 |
{
|
|
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
113 |
sysvar_errmsg_priority= const_cast<char *>(vm["errmsg-priority"].as<string>().c_str()); |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
114 |
}
|
115 |
||
116 |
else
|
|
117 |
{
|
|
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
118 |
sysvar_errmsg_priority= const_cast<char *>("warning"); |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
119 |
}
|
120 |
||
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
121 |
context.add(new Logging_syslog()); |
122 |
context.add(new ErrorMessage_syslog()); |
|
123 |
context.add(new plugin::Create_function<Function_syslog>("syslog")); |
|
124 |
return 0; |
|
125 |
}
|
|
126 |
||
127 |
static DRIZZLE_SYSVAR_STR( |
|
128 |
ident, |
|
129 |
sysvar_ident, |
|
130 |
PLUGIN_VAR_READONLY, |
|
131 |
N_("Syslog Ident"), |
|
132 |
NULL, /* check func */ |
|
133 |
NULL, /* update func*/ |
|
134 |
"drizzled" /* default */); |
|
135 |
||
136 |
static DRIZZLE_SYSVAR_STR( |
|
137 |
facility, |
|
138 |
sysvar_facility, |
|
139 |
PLUGIN_VAR_READONLY, |
|
140 |
N_("Syslog Facility"), |
|
141 |
NULL, /* check func */ |
|
142 |
NULL, /* update func*/ |
|
143 |
"local0" /* default */); // local0 is what PostGreSQL uses by default |
|
144 |
||
145 |
static DRIZZLE_SYSVAR_BOOL( |
|
146 |
logging_enable, |
|
147 |
sysvar_logging_enable, |
|
148 |
PLUGIN_VAR_NOCMDARG, |
|
149 |
N_("Enable logging to syslog of the query log"), |
|
150 |
NULL, /* check func */ |
|
151 |
NULL, /* update func */ |
|
152 |
false /* default */); |
|
153 |
||
154 |
static DRIZZLE_SYSVAR_STR( |
|
155 |
logging_priority, |
|
156 |
sysvar_logging_priority, |
|
157 |
PLUGIN_VAR_READONLY, |
|
158 |
N_("Syslog Priority of query logging"), |
|
159 |
NULL, /* check func */ |
|
160 |
NULL, /* update func*/ |
|
161 |
"info" /* default */); |
|
162 |
||
163 |
static DRIZZLE_SYSVAR_ULONG( |
|
164 |
logging_threshold_slow, |
|
165 |
sysvar_logging_threshold_slow, |
|
166 |
PLUGIN_VAR_OPCMDARG, |
|
167 |
N_("Threshold for logging slow queries, in microseconds"), |
|
168 |
NULL, /* check func */ |
|
169 |
NULL, /* update func */ |
|
170 |
0, /* default */ |
|
171 |
0, /* min */ |
|
172 |
ULONG_MAX, /* max */ |
|
173 |
0 /* blksiz */); |
|
174 |
||
175 |
static DRIZZLE_SYSVAR_ULONG( |
|
176 |
logging_threshold_big_resultset, |
|
177 |
sysvar_logging_threshold_big_resultset, |
|
178 |
PLUGIN_VAR_OPCMDARG, |
|
179 |
N_("Threshold for logging big queries, for rows returned"), |
|
180 |
NULL, /* check func */ |
|
181 |
NULL, /* update func */ |
|
182 |
0, /* default */ |
|
183 |
0, /* min */ |
|
184 |
ULONG_MAX, /* max */ |
|
185 |
0 /* blksiz */); |
|
186 |
||
187 |
static DRIZZLE_SYSVAR_ULONG( |
|
188 |
logging_threshold_big_examined, |
|
189 |
sysvar_logging_threshold_big_examined, |
|
190 |
PLUGIN_VAR_OPCMDARG, |
|
191 |
N_("Threshold for logging big queries, for rows examined"), |
|
192 |
NULL, /* check func */ |
|
193 |
NULL, /* update func */ |
|
194 |
0, /* default */ |
|
195 |
0, /* min */ |
|
196 |
ULONG_MAX, /* max */ |
|
197 |
0 /* blksiz */); |
|
198 |
||
199 |
static DRIZZLE_SYSVAR_BOOL( |
|
200 |
errmsg_enable, |
|
201 |
sysvar_errmsg_enable, |
|
202 |
PLUGIN_VAR_NOCMDARG, |
|
203 |
N_("Enable logging to syslog of the error messages"), |
|
204 |
NULL, /* check func */ |
|
205 |
NULL, /* update func */ |
|
206 |
false /* default */); |
|
207 |
||
208 |
static DRIZZLE_SYSVAR_STR( |
|
209 |
errmsg_priority, |
|
210 |
sysvar_errmsg_priority, |
|
211 |
PLUGIN_VAR_READONLY, |
|
212 |
N_("Syslog Priority of error messages"), |
|
213 |
NULL, /* check func */ |
|
214 |
NULL, /* update func*/ |
|
215 |
"warning" /* default */); |
|
216 |
||
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
217 |
static void init_options(drizzled::module::option_context &context) |
218 |
{
|
|
219 |
context("ident", |
|
220 |
po::value<string>(), |
|
221 |
N_("Syslog Ident")); |
|
222 |
context("facility", |
|
223 |
po::value<string>(), |
|
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", |
|
229 |
po::value<string>(), |
|
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", |
|
244 |
po::value<string>(), |
|
245 |
N_("Syslog Priority of error messages")); |
|
246 |
}
|
|
247 |
||
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
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), |
|
258 |
NULL
|
|
259 |
};
|
|
260 |
||
261 |
} // namespace syslog_module |
|
262 |
||
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
263 |
DRIZZLE_PLUGIN(syslog_module::init, syslog_module::system_variables, syslog_module::init_options); |