~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/error_message.cc

Merge in additional test case fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
 
20
#include "config.h"
 
21
#include "drizzled/plugin/error_message.h"
21
22
 
22
 
#include <drizzled/error.h>
23
 
#include <drizzled/gettext.h>
24
 
#include <drizzled/plugin/error_message.h>
 
23
#include "drizzled/gettext.h"
25
24
 
26
25
#include <cstdio>
27
26
#include <algorithm>
31
30
{
32
31
 
33
32
std::vector<plugin::ErrorMessage *> all_errmsg_handler;
 
33
bool errmsg_has= false;
 
34
 
34
35
 
35
36
bool plugin::ErrorMessage::addPlugin(plugin::ErrorMessage *handler)
36
37
{
37
38
  all_errmsg_handler.push_back(handler);
 
39
  errmsg_has= true;
38
40
  return false;
39
41
}
40
42
 
41
 
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *)
 
43
void plugin::ErrorMessage::removePlugin(plugin::ErrorMessage *handler)
42
44
{
43
 
  all_errmsg_handler.clear();
 
45
  all_errmsg_handler.erase(std::find(all_errmsg_handler.begin(),
 
46
                                     all_errmsg_handler.end(), handler));
44
47
}
45
48
 
46
49
 
86
89
 
87
90
bool plugin::ErrorMessage::vprintf(error::level_t priority, char const *format, va_list ap)
88
91
{
89
 
  if (not (priority >= error::verbosity()))
90
 
    return false;
91
92
 
92
 
  /* 
93
 
    Check to see if any errmsg plugin has been loaded
94
 
    if not, just fall back to emitting the message to stderr.
95
 
  */
96
 
  if (not all_errmsg_handler.size())
 
93
  /* check to see if any errmsg plugin has been loaded
 
94
     if not, just fall back to emitting the message to stderr */
 
95
  if (not errmsg_has)
97
96
  {
98
97
    /* if it turns out that the vfprintf doesnt do one single write
99
98
       (single writes are atomic), then this needs to be rewritten to
100
99
       vsprintf into a char buffer, and then write() that char buffer
101
100
       to stderr */
102
 
      vfprintf(stderr, format, ap);
103
 
      fputc('\n', stderr);
 
101
    vfprintf(stderr, format, ap);
104
102
    return false;
105
103
  }
106
104