Drizzled Public API Documentation

module.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Mark Atwood
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include <config.h>
00021 
00022 #include <drizzled/plugin.h>
00023 #include <drizzled/plugin/logging.h>
00024 #include <drizzled/plugin/error_message.h>
00025 #include <drizzled/plugin/function.h>
00026 
00027 #include "wrap.h"
00028 #include "logging.h"
00029 #include "errmsg.h"
00030 #include "function.h"
00031 #include <iostream>
00032 #include <boost/program_options.hpp>
00033 #include <drizzled/module/option_map.h>
00034 
00035 namespace po= boost::program_options;
00036 using namespace std;
00037 using namespace drizzled;
00038 
00039 namespace drizzle_plugin
00040 {
00041 
00042 bool sysvar_logging_enable= false;
00043 bool sysvar_errmsg_enable= false;
00044 
00045 uint64_constraint sysvar_logging_threshold_slow;
00046 uint64_constraint sysvar_logging_threshold_big_resultset;
00047 uint64_constraint sysvar_logging_threshold_big_examined;
00048 
00049 
00050 static int init(drizzled::module::Context &context)
00051 {
00052   const module::option_map &vm= context.getOptions();
00053 
00054   WrapSyslog::singleton().openlog(vm["ident"].as<string>());
00055   if (sysvar_errmsg_enable)
00056   {
00057     context.add(new error_message::Syslog(vm["facility"].as<string>(),
00058                                           vm["errmsg-priority"].as<string>()));
00059   }
00060   if (sysvar_logging_enable)
00061   {
00062     context.add(new logging::Syslog(vm["facility"].as<string>(),
00063                                     vm["logging-priority"].as<string>(),
00064                                     sysvar_logging_threshold_slow.get(),
00065                                     sysvar_logging_threshold_big_resultset.get(),
00066                                     sysvar_logging_threshold_big_examined.get()));
00067   }
00068   context.add(new plugin::Create_function<udf::Syslog>("syslog"));
00069 
00070   context.registerVariable(new sys_var_const_string_val("facility",
00071                                                         vm["facility"].as<string>()));
00072   context.registerVariable(new sys_var_const_string_val("errmsg_priority",
00073                                                         vm["errmsg-priority"].as<string>()));
00074   context.registerVariable(new sys_var_const_string_val("logging_priority",
00075                                                         vm["logging-priority"].as<string>()));
00076   context.registerVariable(new sys_var_bool_ptr_readonly("logging_enable",
00077                                                          &sysvar_logging_enable));
00078   context.registerVariable(new sys_var_bool_ptr_readonly("errmsg_enable",
00079                                                          &sysvar_errmsg_enable));
00080   context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("logging_threshold_slow",
00081                                                                             sysvar_logging_threshold_slow));
00082   context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("logging_threshold_big_resultset",
00083                                                                             sysvar_logging_threshold_big_resultset));
00084   context.registerVariable(new sys_var_constrained_value_readonly<uint64_t>("logging_threshold_big_examined",
00085                                                                             sysvar_logging_threshold_big_examined));
00086 
00087   return 0;
00088 }
00089 
00090 
00091 static void init_options(drizzled::module::option_context &context)
00092 {
00093   context("ident",
00094           po::value<string>()->default_value("drizzled"),
00095           _("Syslog Ident"));
00096   context("facility",
00097           po::value<string>()->default_value("local0"),
00098           _("Syslog Facility"));
00099   context("logging-enable",
00100           po::value<bool>(&sysvar_logging_enable)->default_value(false)->zero_tokens(),
00101           _("Enable logging to syslog of the query log"));
00102   context("logging-priority",
00103           po::value<string>()->default_value("warning"),
00104           _("Syslog Priority of query logging"));
00105   context("logging-threshold-slow",
00106           po::value<uint64_constraint>(&sysvar_logging_threshold_slow)->default_value(0),
00107           _("Threshold for logging slow queries, in microseconds"));
00108   context("logging-threshold-big-resultset",
00109           po::value<uint64_constraint>(&sysvar_logging_threshold_big_resultset)->default_value(0),
00110           _("Threshold for logging big queries, for rows returned"));
00111   context("logging-threshold-big-examined",
00112           po::value<uint64_constraint>(&sysvar_logging_threshold_big_examined)->default_value(0),
00113           _("Threshold for logging big queries, for rows examined"));
00114   context("errmsg-enable",
00115           po::value<bool>(&sysvar_errmsg_enable)->default_value(false)->zero_tokens(),
00116           _("Enable logging to syslog of the error messages"));
00117   context("errmsg-priority",
00118           po::value<string>()->default_value("warning"),
00119           _("Syslog Priority of error messages"));
00120 }
00121 
00122 } /* namespace drizzle_plugin */
00123 
00124 DRIZZLE_PLUGIN(drizzle_plugin::init, NULL, drizzle_plugin::init_options);