1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
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.
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.
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
21
#include <drizzled/plugin/logging.h>
22
#include <drizzled/gettext.h>
23
#include <drizzled/errmsg_print.h>
33
std::vector<plugin::Logging *> all_loggers;
36
bool plugin::Logging::addPlugin(plugin::Logging *handler)
39
all_loggers.push_back(handler);
43
void plugin::Logging::removePlugin(plugin::Logging *handler)
46
all_loggers.erase(std::find(all_loggers.begin(), all_loggers.end(), handler));
50
class PreIterate : public std::unary_function<plugin::Logging *, bool>
54
PreIterate(Session *session_arg) :
55
std::unary_function<plugin::Logging *, bool>(),
56
session(session_arg) {}
58
inline result_type operator()(argument_type handler)
60
if (handler->pre(session))
62
/* TRANSLATORS: The leading word "logging" is the name
63
of the plugin api, and so should not be translated. */
64
errmsg_printf(error::ERROR,
65
_("logging '%s' pre() failed"),
66
handler->getName().c_str());
74
class PostIterate : public std::unary_function<plugin::Logging *, bool>
78
PostIterate(Session *session_arg) :
79
std::unary_function<plugin::Logging *, bool>(),
80
session(session_arg) {}
82
/* This gets called once for each loaded logging plugin */
83
inline result_type operator()(argument_type handler)
85
if (handler->post(session))
87
/* TRANSLATORS: The leading word "logging" is the name
88
of the plugin api, and so should not be translated. */
89
errmsg_printf(error::ERROR,
90
_("logging '%s' post() failed"),
91
handler->getName().c_str());
98
class PostEndIterate : public std::unary_function<plugin::Logging *, bool>
102
PostEndIterate(Session *session_arg) :
103
std::unary_function<plugin::Logging *, bool>(),
104
session(session_arg) {}
106
/* This gets called once for each loaded logging plugin */
107
inline result_type operator()(argument_type handler)
109
if (handler->postEnd(session))
111
/* TRANSLATORS: The leading word "logging" is the name
112
of the plugin api, and so should not be translated. */
113
errmsg_printf(error::ERROR,
114
_("logging '%s' postEnd() failed"),
115
handler->getName().c_str());
122
class ResetIterate : public std::unary_function<plugin::Logging *, bool>
126
ResetIterate(Session *session_arg) :
127
std::unary_function<plugin::Logging *, bool>(),
128
session(session_arg) {}
130
inline result_type operator()(argument_type handler)
132
if (handler->resetGlobalScoreboard())
134
/* TRANSLATORS: The leading word "logging" is the name
135
of the plugin api, and so should not be translated. */
136
errmsg_printf(error::ERROR,
137
_("logging '%s' resetCurrentScoreboard() failed"),
138
handler->getName().c_str());
146
/* This is the Logging::preDo entry point.
147
This gets called by the rest of the Drizzle server code */
148
bool plugin::Logging::preDo(Session *session)
150
/* Use find_if instead of foreach so that we can collect return codes */
151
std::vector<plugin::Logging *>::iterator iter=
152
std::find_if(all_loggers.begin(), all_loggers.end(),
153
PreIterate(session));
154
/* If iter is == end() here, that means that all of the plugins returned
155
* false, which in this case means they all succeeded. Since we want to
156
* return false on success, we return the value of the two being !=
158
return iter != all_loggers.end();
161
/* This is the Logging::postDo entry point.
162
This gets called by the rest of the Drizzle server code */
163
bool plugin::Logging::postDo(Session *session)
165
/* Use find_if instead of foreach so that we can collect return codes */
166
std::vector<plugin::Logging *>::iterator iter=
167
std::find_if(all_loggers.begin(), all_loggers.end(),
168
PostIterate(session));
169
/* If iter is == end() here, that means that all of the plugins returned
170
* false, which in this case means they all succeeded. Since we want to
171
* return false on success, we return the value of the two being !=
173
return iter != all_loggers.end();
176
/* This gets called in the session destructor */
177
bool plugin::Logging::postEndDo(Session *session)
179
/* Use find_if instead of foreach so that we can collect return codes */
180
std::vector<plugin::Logging *>::iterator iter=
181
std::find_if(all_loggers.begin(), all_loggers.end(),
182
PostEndIterate(session));
183
/* If iter is == end() here, that means that all of the plugins returned
184
* false, which in this case means they all succeeded. Since we want to
185
* return false on success, we return the value of the two being !=
187
return iter != all_loggers.end();
190
/* Resets global stats for logging plugin */
191
bool plugin::Logging::resetStats(Session *session)
193
std::vector<plugin::Logging *>::iterator iter=
194
std::find_if(all_loggers.begin(), all_loggers.end(),
195
ResetIterate(session));
197
return iter != all_loggers.end();
200
} /* namespace drizzled */
1
#include <drizzled/server_includes.h>
2
#include <drizzled/logging.h>
4
int logging_initializer(st_plugin_int *plugin)
8
fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
9
__func__, plugin->name.str, plugin->plugin_dl->dl.str);
11
p= (logging_t *) malloc(sizeof(logging_t));
12
if (p == NULL) return 1;
13
memset(p, 0, sizeof(logging_t));
15
plugin->data= (void *)p;
17
if (plugin->plugin->init)
19
if (plugin->plugin->init((void *)p))
21
sql_print_error("Logging plugin '%s' init function returned error.",
33
int logging_finalizer(st_plugin_int *plugin)
35
logging_t *p = (logging_t *) plugin->data;
37
fprintf(stderr, "MRA %s plugin:%s dl:%s\n",
38
__func__, plugin->name.str, plugin->plugin_dl->dl.str);
40
if (plugin->plugin->deinit)
42
if (plugin->plugin->deinit((void *)p))
44
sql_print_error("Logging plugin '%s' deinit function returned error.",
54
static bool logging_pre_iterate (THD *thd, plugin_ref plugin,
55
void *stuff __attribute__ ((__unused__)))
57
logging_t *l= plugin_data(plugin, logging_t *);
59
if (l && l->logging_pre)
61
if (l->logging_pre(thd))
67
void logging_pre_do (THD *thd)
69
if (plugin_foreach(thd, logging_pre_iterate, DRIZZLE_LOGGER_PLUGIN, NULL))
71
sql_print_error("Logging plugin pre had an error.");
76
static bool logging_post_iterate (THD *thd, plugin_ref plugin,
77
void *stuff __attribute__ ((__unused__)))
79
logging_t *l= plugin_data(plugin, logging_t *);
81
if (l && l->logging_post)
83
if (l->logging_post(thd))
89
void logging_post_do (THD *thd)
91
if (plugin_foreach(thd, logging_post_iterate, DRIZZLE_LOGGER_PLUGIN, NULL))
93
sql_print_error("Logging plugin post had an error.");