~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/syslog/module.cc

Merge Joe, plus I updated the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
#include "config.h"
 
21
#include "module.h"
21
22
 
22
23
#include <drizzled/plugin.h>
23
24
#include <drizzled/plugin/logging.h>
24
25
#include <drizzled/plugin/error_message.h>
25
26
#include <drizzled/plugin/function.h>
26
27
 
27
 
#include "wrap.h"
28
28
#include "logging.h"
29
29
#include "errmsg.h"
30
30
#include "function.h"
31
 
#include <iostream>
32
 
#include <boost/program_options.hpp>
33
 
#include <drizzled/module/option_map.h>
34
31
 
35
 
namespace po= boost::program_options;
36
 
using namespace std;
37
32
using namespace drizzled;
38
33
 
39
 
namespace drizzle_plugin
 
34
namespace syslog_module
40
35
{
41
36
 
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;
48
 
 
 
37
char* sysvar_ident;
 
38
char* sysvar_facility;
 
39
bool sysvar_logging_enable;
 
40
char* sysvar_logging_priority;
 
41
unsigned long sysvar_logging_threshold_slow;
 
42
unsigned long sysvar_logging_threshold_big_resultset;
 
43
unsigned long sysvar_logging_threshold_big_examined;
 
44
bool sysvar_errmsg_enable;
 
45
char* sysvar_errmsg_priority;
49
46
 
50
47
static int init(drizzled::module::Context &context)
51
48
{
52
 
  const module::option_map &vm= context.getOptions();
53
 
 
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
 
 
 
49
  context.add(new Logging_syslog());
 
50
  context.add(new ErrorMessage_syslog());
 
51
  context.add(new plugin::Create_function<Function_syslog>("syslog"));
87
52
  return 0;
88
53
}
89
54
 
90
 
 
91
 
static void init_options(drizzled::module::option_context &context)
92
 
{
93
 
  context("ident",
94
 
          po::value<string>()->default_value("drizzled"),
95
 
          _("Syslog Ident"));
96
 
  context("facility",
97
 
          po::value<string>()->default_value("local0"),
98
 
          _("Syslog Facility"));
99
 
  context("logging-enable",
100
 
          po::value<bool>(&sysvar_logging_enable)->default_value(false)->zero_tokens(),
101
 
          _("Enable logging to syslog of the query log"));
102
 
  context("logging-priority",
103
 
          po::value<string>()->default_value("warning"),
104
 
          _("Syslog Priority of query logging"));
105
 
  context("logging-threshold-slow",
106
 
          po::value<uint64_constraint>(&sysvar_logging_threshold_slow)->default_value(0),
107
 
          _("Threshold for logging slow queries, in microseconds"));
108
 
  context("logging-threshold-big-resultset",
109
 
          po::value<uint64_constraint>(&sysvar_logging_threshold_big_resultset)->default_value(0),
110
 
          _("Threshold for logging big queries, for rows returned"));
111
 
  context("logging-threshold-big-examined",
112
 
          po::value<uint64_constraint>(&sysvar_logging_threshold_big_examined)->default_value(0),
113
 
          _("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
 
          _("Enable logging to syslog of the error messages"));
117
 
  context("errmsg-priority",
118
 
          po::value<string>()->default_value("warning"),
119
 
          _("Syslog Priority of error messages"));
120
 
}
121
 
 
122
 
} /* namespace drizzle_plugin */
123
 
 
124
 
DRIZZLE_PLUGIN(drizzle_plugin::init, NULL, drizzle_plugin::init_options);
 
55
static DRIZZLE_SYSVAR_STR(
 
56
  ident,
 
57
  sysvar_ident,
 
58
  PLUGIN_VAR_READONLY,
 
59
  N_("Syslog Ident"),
 
60
  NULL, /* check func */
 
61
  NULL, /* update func*/
 
62
  "drizzled" /* default */);
 
63
 
 
64
static DRIZZLE_SYSVAR_STR(
 
65
  facility,
 
66
  sysvar_facility,
 
67
  PLUGIN_VAR_READONLY,
 
68
  N_("Syslog Facility"),
 
69
  NULL, /* check func */
 
70
  NULL, /* update func*/
 
71
  "local0" /* default */);  // local0 is what PostGreSQL uses by default
 
72
 
 
73
static DRIZZLE_SYSVAR_BOOL(
 
74
  logging_enable,
 
75
  sysvar_logging_enable,
 
76
  PLUGIN_VAR_NOCMDARG,
 
77
  N_("Enable logging to syslog of the query log"),
 
78
  NULL, /* check func */
 
79
  NULL, /* update func */
 
80
  false /* default */);
 
81
 
 
82
static DRIZZLE_SYSVAR_STR(
 
83
  logging_priority,
 
84
  sysvar_logging_priority,
 
85
  PLUGIN_VAR_READONLY,
 
86
  N_("Syslog Priority of query logging"),
 
87
  NULL, /* check func */
 
88
  NULL, /* update func*/
 
89
  "info" /* default */);
 
90
 
 
91
static DRIZZLE_SYSVAR_ULONG(
 
92
  logging_threshold_slow,
 
93
  sysvar_logging_threshold_slow,
 
94
  PLUGIN_VAR_OPCMDARG,
 
95
  N_("Threshold for logging slow queries, in microseconds"),
 
96
  NULL, /* check func */
 
97
  NULL, /* update func */
 
98
  0, /* default */
 
99
  0, /* min */
 
100
  ULONG_MAX, /* max */
 
101
  0 /* blksiz */);
 
102
 
 
103
static DRIZZLE_SYSVAR_ULONG(
 
104
  logging_threshold_big_resultset,
 
105
  sysvar_logging_threshold_big_resultset,
 
106
  PLUGIN_VAR_OPCMDARG,
 
107
  N_("Threshold for logging big queries, for rows returned"),
 
108
  NULL, /* check func */
 
109
  NULL, /* update func */
 
110
  0, /* default */
 
111
  0, /* min */
 
112
  ULONG_MAX, /* max */
 
113
  0 /* blksiz */);
 
114
 
 
115
static DRIZZLE_SYSVAR_ULONG(
 
116
  logging_threshold_big_examined,
 
117
  sysvar_logging_threshold_big_examined,
 
118
  PLUGIN_VAR_OPCMDARG,
 
119
  N_("Threshold for logging big queries, for rows examined"),
 
120
  NULL, /* check func */
 
121
  NULL, /* update func */
 
122
  0, /* default */
 
123
  0, /* min */
 
124
  ULONG_MAX, /* max */
 
125
  0 /* blksiz */);
 
126
 
 
127
static DRIZZLE_SYSVAR_BOOL(
 
128
  errmsg_enable,
 
129
  sysvar_errmsg_enable,
 
130
  PLUGIN_VAR_NOCMDARG,
 
131
  N_("Enable logging to syslog of the error messages"),
 
132
  NULL, /* check func */
 
133
  NULL, /* update func */
 
134
  false /* default */);
 
135
 
 
136
static DRIZZLE_SYSVAR_STR(
 
137
  errmsg_priority,
 
138
  sysvar_errmsg_priority,
 
139
  PLUGIN_VAR_READONLY,
 
140
  N_("Syslog Priority of error messages"),
 
141
  NULL, /* check func */
 
142
  NULL, /* update func*/
 
143
  "warning" /* default */);
 
144
 
 
145
static drizzle_sys_var* system_variables[]= {
 
146
  DRIZZLE_SYSVAR(ident),
 
147
  DRIZZLE_SYSVAR(facility),
 
148
  DRIZZLE_SYSVAR(logging_enable),
 
149
  DRIZZLE_SYSVAR(logging_priority),
 
150
  DRIZZLE_SYSVAR(logging_threshold_slow),
 
151
  DRIZZLE_SYSVAR(logging_threshold_big_resultset),
 
152
  DRIZZLE_SYSVAR(logging_threshold_big_examined),
 
153
  DRIZZLE_SYSVAR(errmsg_enable),
 
154
  DRIZZLE_SYSVAR(errmsg_priority),
 
155
  NULL
 
156
};
 
157
 
 
158
} // namespace syslog_module
 
159
 
 
160
DRIZZLE_PLUGIN(syslog_module::init, syslog_module::system_variables, NULL);