~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/logging.cc

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:48:12 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 918.
  • Revision ID: mordred@inaugust.com-20090304024812-5wb6wpye5c1iitbq
Applied atomic patch to current tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Mark Atwood
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include "config.h"
21
 
#include "drizzled/plugin/logging.h"
22
 
#include "drizzled/gettext.h"
23
 
#include "drizzled/errmsg_print.h"
24
 
 
25
 
#include <vector>
26
 
#include <algorithm>
27
 
 
28
 
class Session;
29
 
 
30
 
namespace drizzled
31
 
{
32
 
 
33
 
std::vector<plugin::Logging *> all_loggers;
34
 
 
35
 
 
36
 
bool plugin::Logging::addPlugin(plugin::Logging *handler)
37
 
{
38
 
  if (handler != NULL)
39
 
    all_loggers.push_back(handler);
40
 
  return false;
41
 
}
42
 
 
43
 
void plugin::Logging::removePlugin(plugin::Logging *handler)
44
 
{
45
 
  if (handler != NULL)
46
 
    all_loggers.erase(std::find(all_loggers.begin(), all_loggers.end(), handler));
47
 
}
48
 
 
49
 
 
50
 
class PreIterate : public std::unary_function<plugin::Logging *, bool>
51
 
{
52
 
  Session *session;
53
 
public:
54
 
  PreIterate(Session *session_arg) :
55
 
    std::unary_function<plugin::Logging *, bool>(),
56
 
    session(session_arg) {}
57
 
 
58
 
  inline result_type operator()(argument_type handler)
59
 
  {
60
 
    if (handler->pre(session))
61
 
    {
62
 
      /* TRANSLATORS: The leading word "logging" is the name
63
 
         of the plugin api, and so should not be translated. */
64
 
      errmsg_printf(ERRMSG_LVL_ERROR,
65
 
                    _("logging '%s' pre() failed"),
66
 
                    handler->getName().c_str());
67
 
      return true;
68
 
    }
69
 
    return false;
70
 
  }
71
 
};
72
 
 
73
 
 
74
 
class PostIterate : public std::unary_function<plugin::Logging *, bool>
75
 
{
76
 
  Session *session;
77
 
public:
78
 
  PostIterate(Session *session_arg) :
79
 
    std::unary_function<plugin::Logging *, bool>(),
80
 
    session(session_arg) {}
81
 
 
82
 
  /* This gets called once for each loaded logging plugin */
83
 
  inline result_type operator()(argument_type handler)
84
 
  {
85
 
    if (handler->post(session))
86
 
    {
87
 
      /* TRANSLATORS: The leading word "logging" is the name
88
 
         of the plugin api, and so should not be translated. */
89
 
      errmsg_printf(ERRMSG_LVL_ERROR,
90
 
                    _("logging '%s' post() failed"),
91
 
                    handler->getName().c_str());
92
 
      return true;
93
 
    }
94
 
    return false;
95
 
  }
96
 
};
97
 
 
98
 
class PostEndIterate : public std::unary_function<plugin::Logging *, bool>
99
 
{
100
 
  Session *session;
101
 
public:
102
 
  PostEndIterate(Session *session_arg) :
103
 
    std::unary_function<plugin::Logging *, bool>(),
104
 
    session(session_arg) {}
105
 
 
106
 
  /* This gets called once for each loaded logging plugin */
107
 
  inline result_type operator()(argument_type handler)
108
 
  {
109
 
    if (handler->postEnd(session))
110
 
    {
111
 
      /* TRANSLATORS: The leading word "logging" is the name
112
 
         of the plugin api, and so should not be translated. */
113
 
      errmsg_printf(ERRMSG_LVL_ERROR,
114
 
                    _("logging '%s' postEnd() failed"),
115
 
                    handler->getName().c_str());
116
 
      return true;
117
 
    }
118
 
    return false;
119
 
  }
120
 
};
121
 
 
122
 
class ResetIterate : public std::unary_function<plugin::Logging *, bool>
123
 
{
124
 
  Session *session;
125
 
public:
126
 
  ResetIterate(Session *session_arg) :
127
 
    std::unary_function<plugin::Logging *, bool>(),
128
 
    session(session_arg) {}
129
 
 
130
 
  inline result_type operator()(argument_type handler)
131
 
  {
132
 
    if (handler->resetGlobalScoreboard())
133
 
    {
134
 
      /* TRANSLATORS: The leading word "logging" is the name
135
 
         of the plugin api, and so should not be translated. */
136
 
      errmsg_printf(ERRMSG_LVL_ERROR,
137
 
                    _("logging '%s' resetCurrentScoreboard() failed"),
138
 
                    handler->getName().c_str());
139
 
      return true;
140
 
    }
141
 
    return false;
142
 
  }
143
 
};
144
 
 
145
 
 
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)
149
 
{
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 != 
157
 
   */
158
 
  return iter != all_loggers.end();
159
 
}
160
 
 
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)
164
 
{
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 != 
172
 
   */
173
 
  return iter != all_loggers.end();
174
 
}
175
 
 
176
 
/* This gets called in the session destructor */
177
 
bool plugin::Logging::postEndDo(Session *session)
178
 
{
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 !=
186
 
   */
187
 
  return iter != all_loggers.end();
188
 
}
189
 
 
190
 
/* Resets global stats for logging plugin */
191
 
bool plugin::Logging::resetStats(Session *session)
192
 
{
193
 
  std::vector<plugin::Logging *>::iterator iter=
194
 
    std::find_if(all_loggers.begin(), all_loggers.end(),
195
 
                 ResetIterate(session));
196
 
 
197
 
  return iter != all_loggers.end();
198
 
}
199
 
 
200
 
} /* namespace drizzled */
 
20
#include <drizzled/server_includes.h>
 
21
#include <drizzled/logging.h>
 
22
#include <drizzled/gettext.h>
 
23
 
 
24
int logging_initializer(st_plugin_int *plugin)
 
25
{
 
26
  logging_t *p;
 
27
 
 
28
  p= new logging_t;
 
29
  if (p == NULL) return 1;
 
30
  memset(p, 0, sizeof(logging_t));
 
31
 
 
32
  plugin->data= (void *)p;
 
33
 
 
34
  if (plugin->plugin->init)
 
35
  {
 
36
    if (plugin->plugin->init((void *)p))
 
37
    {
 
38
      /* TRANSLATORS: The leading word "logging" is the name
 
39
         of the plugin api, and so should not be translated. */
 
40
      errmsg_printf(ERRMSG_LVL_ERROR, "logging plugin '%s' init() failed",
 
41
                      plugin->name.str);
 
42
      goto err;
 
43
    }
 
44
  }
 
45
 
 
46
  plugin->state= PLUGIN_IS_READY;
 
47
 
 
48
  return 0;
 
49
 
 
50
err:
 
51
  delete p;
 
52
  return 1;
 
53
}
 
54
 
 
55
int logging_finalizer(st_plugin_int *plugin)
 
56
{
 
57
  logging_t *p = (logging_t *) plugin->data;
 
58
 
 
59
  if (plugin->plugin->deinit)
 
60
  {
 
61
    if (plugin->plugin->deinit((void *)p))
 
62
    {
 
63
      /* TRANSLATORS: The leading word "logging" is the name
 
64
         of the plugin api, and so should not be translated. */
 
65
      errmsg_printf(ERRMSG_LVL_ERROR, _("logging plugin '%s' deinit() failed"),
 
66
                      plugin->name.str);
 
67
    }
 
68
  }
 
69
 
 
70
  if (p) delete p;
 
71
 
 
72
  return 0;
 
73
}
 
74
 
 
75
/* This gets called by plugin_foreach once for each loaded logging plugin */
 
76
static bool logging_pre_iterate (Session *session, plugin_ref plugin, void *)
 
77
{
 
78
  logging_t *l= plugin_data(plugin, logging_t *);
 
79
 
 
80
  /* call this loaded logging plugin's logging_pre function pointer */
 
81
  if (l && l->logging_pre)
 
82
  {
 
83
    if (l->logging_pre(session))
 
84
    {
 
85
      /* TRANSLATORS: The leading word "logging" is the name
 
86
         of the plugin api, and so should not be translated. */
 
87
      errmsg_printf(ERRMSG_LVL_ERROR, _("logging plugin '%s' logging_pre() failed"),
 
88
                      (char *)plugin_name(plugin));
 
89
      return true;
 
90
    }
 
91
  }
 
92
  return false;
 
93
}
 
94
 
 
95
/* This is the logging_pre_do entry point.
 
96
   This gets called by the rest of the Drizzle server code */
 
97
bool logging_pre_do (Session *session)
 
98
{
 
99
  bool foreach_rv;
 
100
 
 
101
  foreach_rv= plugin_foreach(session,
 
102
                             logging_pre_iterate,
 
103
                             DRIZZLE_LOGGER_PLUGIN,
 
104
                             NULL);
 
105
  return foreach_rv;
 
106
}
 
107
 
 
108
/* This gets called by plugin_foreach once for each loaded logging plugin */
 
109
static bool logging_post_iterate (Session *session, plugin_ref plugin, void *)
 
110
{
 
111
  logging_t *l= plugin_data(plugin, logging_t *);
 
112
 
 
113
  if (l && l->logging_post)
 
114
  {
 
115
    if (l->logging_post(session))
 
116
    {
 
117
      /* TRANSLATORS: The leading word "logging" is the name
 
118
         of the plugin api, and so should not be translated. */
 
119
      errmsg_printf(ERRMSG_LVL_ERROR, _("logging plugin '%s' logging_post() failed"),
 
120
                      (char *)plugin_name(plugin));
 
121
      return true;
 
122
    }
 
123
  }
 
124
  return false;
 
125
}
 
126
 
 
127
/* This is the logging_pre_do entry point.
 
128
   This gets called by the rest of the Drizzle server code */
 
129
bool logging_post_do (Session *session)
 
130
{
 
131
  bool foreach_rv;
 
132
 
 
133
  foreach_rv= plugin_foreach(session,
 
134
                             logging_post_iterate,
 
135
                             DRIZZLE_LOGGER_PLUGIN,
 
136
                             NULL);
 
137
  return foreach_rv;
 
138
}