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 |
||
22 |
#include <drizzled/plugin.h> |
|
23 |
#include <drizzled/plugin/logging.h> |
|
24 |
#include <drizzled/plugin/error_message.h> |
|
25 |
#include <drizzled/plugin/function.h> |
|
26 |
||
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
27 |
#include "wrap.h" |
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
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 |
||
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
39 |
namespace drizzle_plugin |
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
40 |
{
|
41 |
||
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
42 |
bool sysvar_logging_enable= false; |
43 |
bool sysvar_errmsg_enable= false; |
|
44 |
||
45 |
uint64_constraint sysvar_logging_threshold_slow; |
|
46 |
uint64_constraint sysvar_logging_threshold_big_resultset; |
|
47 |
uint64_constraint sysvar_logging_threshold_big_examined; |
|
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
48 |
|
1666.4.19
by Monty Taylor
Free strdup'd option strings. |
49 |
|
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
50 |
static int init(drizzled::module::Context &context) |
51 |
{
|
|
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
52 |
const module::option_map &vm= context.getOptions(); |
53 |
||
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
54 |
WrapSyslog::singleton().openlog(vm["ident"].as<string>()); |
55 |
if (sysvar_errmsg_enable) |
|
56 |
{
|
|
57 |
context.add(new error_message::Syslog(vm["facility"].as<string>(), |
|
58 |
vm["errmsg-priority"].as<string>())); |
|
59 |
}
|
|
60 |
if (sysvar_logging_enable) |
|
61 |
{
|
|
62 |
context.add(new logging::Syslog(vm["facility"].as<string>(), |
|
63 |
vm["logging-priority"].as<string>(), |
|
64 |
sysvar_logging_threshold_slow.get(), |
|
65 |
sysvar_logging_threshold_big_resultset.get(), |
|
66 |
sysvar_logging_threshold_big_examined.get())); |
|
67 |
}
|
|
68 |
context.add(new plugin::Create_function<udf::Syslog>("syslog")); |
|
69 |
||
70 |
context.registerVariable(new sys_var_const_string_val("facility", |
|
71 |
vm["facility"].as<string>())); |
|
72 |
context.registerVariable(new sys_var_const_string_val("errmsg_priority", |
|
73 |
vm["errmsg-priority"].as<string>())); |
|
74 |
context.registerVariable(new sys_var_const_string_val("logging_priority", |
|
75 |
vm["logging-priority"].as<string>())); |
|
76 |
context.registerVariable(new sys_var_bool_ptr_readonly("logging_enable", |
|
77 |
&sysvar_logging_enable)); |
|
78 |
context.registerVariable(new sys_var_bool_ptr_readonly("errmsg_enable", |
|
79 |
&sysvar_errmsg_enable)); |
|
80 |
context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("logging_threshold_slow", |
|
81 |
sysvar_logging_threshold_slow)); |
|
82 |
context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("logging_threshold_big_resultset", |
|
83 |
sysvar_logging_threshold_big_resultset)); |
|
84 |
context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("logging_threshold_big_examined", |
|
85 |
sysvar_logging_threshold_big_examined)); |
|
86 |
||
1637.3.1
by Mark Atwood
new syslog module, with plugins for query log, error message, and SYSLOG() function |
87 |
return 0; |
88 |
}
|
|
89 |
||
90 |
||
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
91 |
static void init_options(drizzled::module::option_context &context) |
92 |
{
|
|
93 |
context("ident", |
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
94 |
po::value<string>()->default_value("drizzled"), |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
95 |
N_("Syslog Ident")); |
96 |
context("facility", |
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
97 |
po::value<string>()->default_value("local0"), |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
98 |
N_("Syslog Facility")); |
99 |
context("logging-enable", |
|
100 |
po::value<bool>(&sysvar_logging_enable)->default_value(false)->zero_tokens(), |
|
101 |
N_("Enable logging to syslog of the query log")); |
|
102 |
context("logging-priority", |
|
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
103 |
po::value<string>()->default_value("warning"), |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
104 |
N_("Syslog Priority of query logging")); |
105 |
context("logging-threshold-slow", |
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
106 |
po::value<uint64_constraint>(&sysvar_logging_threshold_slow)->default_value(0), |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
107 |
N_("Threshold for logging slow queries, in microseconds")); |
108 |
context("logging-threshold-big-resultset", |
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
109 |
po::value<uint64_constraint>(&sysvar_logging_threshold_big_resultset)->default_value(0), |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
110 |
N_("Threshold for logging big queries, for rows returned")); |
111 |
context("logging-threshold-big-examined", |
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
112 |
po::value<uint64_constraint>(&sysvar_logging_threshold_big_examined)->default_value(0), |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
113 |
N_("Threshold for logging big queries, for rows examined")); |
114 |
context("errmsg-enable", |
|
115 |
po::value<bool>(&sysvar_errmsg_enable)->default_value(false)->zero_tokens(), |
|
116 |
N_("Enable logging to syslog of the error messages")); |
|
117 |
context("errmsg-priority", |
|
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
118 |
po::value<string>()->default_value("warning"), |
1684.3.1
by Vijay Samuel
Merge re factored commandline for syslog |
119 |
N_("Syslog Priority of error messages")); |
120 |
}
|
|
121 |
||
1964.2.7
by Monty Taylor
Refactored syslog module and changed it to use sys_var directly. |
122 |
} /* namespace drizzle_plugin */ |
123 |
||
124 |
DRIZZLE_PLUGIN(drizzle_plugin::init, NULL, drizzle_plugin::init_options); |