~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/logging.cc

  • Committer: Brian Aker
  • Date: 2009-08-18 07:20:29 UTC
  • mfrom: (1117.1.9 merge)
  • Revision ID: brian@gaz-20090818072029-s9ch5lcmltxwidn7
Merge of Brian

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, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
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>
 
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"
24
24
 
25
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)
 
26
 
 
27
using namespace std;
 
28
 
 
29
static vector<Logging_handler *> all_loggers;
 
30
 
 
31
void add_logger(Logging_handler *handler)
37
32
{
38
33
  if (handler != NULL)
39
34
    all_loggers.push_back(handler);
40
 
  return false;
41
35
}
42
36
 
43
 
void plugin::Logging::removePlugin(plugin::Logging *handler)
 
37
void remove_logger(Logging_handler *handler)
44
38
{
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));
47
41
}
48
42
 
49
43
 
50
 
class PreIterate : public std::unary_function<plugin::Logging *, bool>
 
44
class LoggingPreIterate : public unary_function<Logging_handler *, bool>
51
45
{
52
46
  Session *session;
53
47
public:
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) {}
57
51
 
58
52
  inline result_type operator()(argument_type handler)
61
55
    {
62
56
      /* TRANSLATORS: The leading word "logging" is the name
63
57
         of the plugin api, and so should not be translated. */
64
 
      errmsg_printf(error::ERROR,
 
58
      errmsg_printf(ERRMSG_LVL_ERROR,
65
59
                    _("logging '%s' pre() failed"),
66
60
                    handler->getName().c_str());
67
61
      return true;
71
65
};
72
66
 
73
67
 
74
 
class PostIterate : public std::unary_function<plugin::Logging *, bool>
 
68
class LoggingPostIterate : public unary_function<Logging_handler *, bool>
75
69
{
76
70
  Session *session;
77
71
public:
78
 
  PostIterate(Session *session_arg) :
79
 
    std::unary_function<plugin::Logging *, bool>(),
 
72
  LoggingPostIterate(Session *session_arg) :
 
73
    unary_function<Logging_handler *, bool>(),
80
74
    session(session_arg) {}
81
75
 
82
76
  /* This gets called once for each loaded logging plugin */
86
80
    {
87
81
      /* TRANSLATORS: The leading word "logging" is the name
88
82
         of the plugin api, and so should not be translated. */
89
 
      errmsg_printf(error::ERROR,
 
83
      errmsg_printf(ERRMSG_LVL_ERROR,
90
84
                    _("logging '%s' post() failed"),
91
85
                    handler->getName().c_str());
92
86
      return true;
95
89
  }
96
90
};
97
91
 
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(error::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(error::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 */
 
92
 
 
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)
 
96
{
 
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 != 
 
104
   */
 
105
  return iter != all_loggers.end();
 
106
}
 
107
 
 
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)
 
111
{
 
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 != 
 
119
   */
 
120
  return iter != all_loggers.end();
 
121
}