17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include <drizzled/plugin/logging.h>
20
#include <drizzled/server_includes.h>
21
#include <drizzled/logging.h>
22
22
#include <drizzled/gettext.h>
23
#include <drizzled/errmsg_print.h>
23
#include "drizzled/plugin/registry.h"
33
std::vector<plugin::Logging *> all_loggers;
36
bool plugin::Logging::addPlugin(plugin::Logging *handler)
29
static vector<Logging_handler *> all_loggers;
31
void add_logger(Logging_handler *handler)
38
33
if (handler != NULL)
39
34
all_loggers.push_back(handler);
43
void plugin::Logging::removePlugin(plugin::Logging *handler)
37
void remove_logger(Logging_handler *handler)
45
39
if (handler != NULL)
46
all_loggers.erase(std::find(all_loggers.begin(), all_loggers.end(), handler));
40
all_loggers.erase(find(all_loggers.begin(), all_loggers.end(), handler));
50
class PreIterate : public std::unary_function<plugin::Logging *, bool>
44
class LoggingPreIterate : public unary_function<Logging_handler *, bool>
54
PreIterate(Session *session_arg) :
55
std::unary_function<plugin::Logging *, bool>(),
48
LoggingPreIterate(Session *session_arg) :
49
unary_function<Logging_handler *, bool>(),
56
50
session(session_arg) {}
58
52
inline result_type operator()(argument_type handler)
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 */
93
/* This is the logging_pre_do entry point.
94
This gets called by the rest of the Drizzle server code */
95
bool logging_pre_do (Session *session)
97
/* Use find_if instead of foreach so that we can collect return codes */
98
vector<Logging_handler *>::iterator iter=
99
find_if(all_loggers.begin(), all_loggers.end(),
100
LoggingPreIterate(session));
101
/* If iter is == end() here, that means that all of the plugins returned
102
* false, which in this case means they all succeeded. Since we want to
103
* return false on success, we return the value of the two being !=
105
return iter != all_loggers.end();
108
/* This is the logging_post_do entry point.
109
This gets called by the rest of the Drizzle server code */
110
bool logging_post_do (Session *session)
112
/* Use find_if instead of foreach so that we can collect return codes */
113
vector<Logging_handler *>::iterator iter=
114
find_if(all_loggers.begin(), all_loggers.end(),
115
LoggingPostIterate(session));
116
/* If iter is == end() here, that means that all of the plugins returned
117
* false, which in this case means they all succeeded. Since we want to
118
* return false on success, we return the value of the two being !=
120
return iter != all_loggers.end();