Drizzled Public API Documentation

module.cc
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/item.h>
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 <plugin/syslog/wrap.h>
29 #include <plugin/syslog/logging.h>
30 #include <plugin/syslog/errmsg.h>
31 #include <plugin/syslog/function.h>
32 #include <iostream>
33 #include <boost/program_options.hpp>
35 
36 namespace po= boost::program_options;
37 using namespace std;
38 using namespace drizzled;
39 
40 namespace drizzle_plugin {
41 namespace syslog {
42 
43 
44 bool sysvar_logging_enable= false;
45 static bool sysvar_errmsg_enable= true;
46 bool updateFacility(Session *, set_var *);
47 
48 uint64_constraint sysvar_logging_threshold_slow;
49 uint64_constraint sysvar_logging_threshold_big_resultset;
50 uint64_constraint sysvar_logging_threshold_big_examined;
51 
52 logging::Syslog *logging_syslog_handler = NULL;
53 
54 bool updateFacility(Session *, set_var* var)
55 {
56  if (not var->value->str_value.empty())
57  {
58  std::string new_facility(var->value->str_value.data());
59  if (logging_syslog_handler->setFacility(new_facility))
60  return false; //success
61  else
62  return true; // error
63  }
64  errmsg_printf(error::ERROR, _("syslog_facility cannot be NULL"));
65  return true; // error
66 }
67 
68 static int init(drizzled::module::Context &context)
69 {
70  const module::option_map &vm= context.getOptions();
71 
72  WrapSyslog::singleton().openlog(vm["ident"].as<string>());
73  if (sysvar_errmsg_enable)
74  {
75  context.add(new error_message::Syslog(vm["facility"].as<string>()));
76  }
77 
78  logging_syslog_handler = new logging::Syslog(vm["facility"].as<string>(),
79  sysvar_logging_threshold_slow.get(),
80  sysvar_logging_threshold_big_resultset.get(),
81  sysvar_logging_threshold_big_examined.get());
82  context.add(logging_syslog_handler);
83 
84  context.add(new plugin::Create_function<udf::Syslog>("syslog"));
85 
86  context.registerVariable(new sys_var_std_string("facility", logging_syslog_handler->getFacility(), NULL, &updateFacility));
87  context.registerVariable(new sys_var_const_string_val("errmsg_priority",
88  vm["errmsg-priority"].as<string>()));
89  context.registerVariable(new sys_var_const_string_val("logging_priority",
90  vm["logging-priority"].as<string>()));
91  context.registerVariable(new sys_var_bool_ptr("logging_enable", &sysvar_logging_enable, NULL));
92  context.registerVariable(new sys_var_bool_ptr_readonly("errmsg_enable",
93  &sysvar_errmsg_enable));
94  context.registerVariable(new sys_var_constrained_value<uint64_t>("logging_threshold_slow", logging_syslog_handler->_threshold_slow));
95  context.registerVariable(new sys_var_constrained_value<uint64_t>("logging_threshold_big_resultset", logging_syslog_handler->_threshold_big_resultset));
96  context.registerVariable(new sys_var_constrained_value<uint64_t>("logging_threshold_big_examined", logging_syslog_handler->_threshold_big_examined));
97 
98  return 0;
99 }
100 
101 
102 static void init_options(drizzled::module::option_context &context)
103 {
104  context("ident",
105  po::value<string>()->default_value("drizzled"),
106  _("Syslog Ident"));
107  context("facility",
108  po::value<string>()->default_value("local0"),
109  _("Syslog Facility"));
110  context("logging-enable",
111  po::value<bool>(&sysvar_logging_enable)->default_value(false)->zero_tokens(),
112  _("Enable logging to syslog of the query log"));
113  context("logging-priority",
114  po::value<string>()->default_value("warning"),
115  _("Syslog Priority of query logging"));
116  context("logging-threshold-slow",
117  po::value<uint64_constraint>(&sysvar_logging_threshold_slow)->default_value(0),
118  _("Threshold for logging slow queries, in microseconds"));
119  context("logging-threshold-big-resultset",
120  po::value<uint64_constraint>(&sysvar_logging_threshold_big_resultset)->default_value(0),
121  _("Threshold for logging big queries, for rows returned"));
122  context("logging-threshold-big-examined",
123  po::value<uint64_constraint>(&sysvar_logging_threshold_big_examined)->default_value(0),
124  _("Threshold for logging big queries, for rows examined"));
125  context("errmsg-enable",
126  po::value<bool>(&sysvar_errmsg_enable)->default_value(true)->zero_tokens(),
127  _("Enable logging to syslog of the error messages"));
128  context("errmsg-priority",
129  po::value<string>()->default_value("warning"),
130  _("Syslog Priority of error messages"));
131 }
132 
133 } /* namespace syslog */
134 } /* namespace drizzle_plugin */
135 
136 DRIZZLE_DECLARE_PLUGIN
137 {
138  DRIZZLE_VERSION_ID,
139  "syslog",
140  "0.3",
141  "Mark Atwood",
142  N_("Logs error messages and queries to syslog"),
143  PLUGIN_LICENSE_GPL,
144  drizzle_plugin::syslog::init,
145  NULL,
146  drizzle_plugin::syslog::init_options
147 }
148 DRIZZLE_DECLARE_PLUGIN_END;
An Proxy Wrapper around boost::program_options::variables_map.
String str_value
Definition: item.h:107