~drizzle-trunk/drizzle/development

499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
3
 *
499.2.10 by Mark Atwood
add editor format hints, and other useful metadata comments
4
 *  Copyright (C) 2008 Mark Atwood
5
 *
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.
9
 *
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.
14
 *
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
18
 */
19
383.6.1 by Mark Atwood
add pluggable logging
20
#include <drizzled/server_includes.h>
21
#include <drizzled/logging.h>
549 by Monty Taylor
Took gettext.h out of header files.
22
#include <drizzled/gettext.h>
383.6.1 by Mark Atwood
add pluggable logging
23
24
int logging_initializer(st_plugin_int *plugin)
25
{
26
  logging_t *p;
27
683.1.1 by Mark Atwood
use new/delete instead of malloc/free for plugin structs
28
  p= new logging_t;
383.6.1 by Mark Atwood
add pluggable logging
29
  if (p == NULL) return 1;
383.6.2 by Mark Atwood
changes of Brian's recommendation
30
  memset(p, 0, sizeof(logging_t));
383.6.1 by Mark Atwood
add pluggable logging
31
32
  plugin->data= (void *)p;
33
34
  if (plugin->plugin->init)
35
  {
36
    if (plugin->plugin->init((void *)p))
37
    {
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
38
      /* TRANSLATORS: The leading word "logging" is the name
39
         of the plugin api, and so should not be translated. */
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
40
      errmsg_printf(ERRMSG_LVL_ERROR, "logging plugin '%s' init() failed",
383.6.1 by Mark Atwood
add pluggable logging
41
                      plugin->name.str);
42
      goto err;
43
    }
44
  }
810 by Brian Aker
Fix for making sure I_S has good information about which plugins are
45
46
  plugin->state= PLUGIN_IS_READY;
47
383.6.1 by Mark Atwood
add pluggable logging
48
  return 0;
49
50
err:
683.1.1 by Mark Atwood
use new/delete instead of malloc/free for plugin structs
51
  delete p;
383.6.1 by Mark Atwood
add pluggable logging
52
  return 1;
53
}
54
55
int logging_finalizer(st_plugin_int *plugin)
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
56
{
383.6.2 by Mark Atwood
changes of Brian's recommendation
57
  logging_t *p = (logging_t *) plugin->data;
383.6.1 by Mark Atwood
add pluggable logging
58
59
  if (plugin->plugin->deinit)
60
  {
61
    if (plugin->plugin->deinit((void *)p))
62
    {
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
63
      /* TRANSLATORS: The leading word "logging" is the name
64
         of the plugin api, and so should not be translated. */
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
65
      errmsg_printf(ERRMSG_LVL_ERROR, _("logging plugin '%s' deinit() failed"),
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
66
		      plugin->name.str);
383.6.1 by Mark Atwood
add pluggable logging
67
    }
68
  }
69
683.1.1 by Mark Atwood
use new/delete instead of malloc/free for plugin structs
70
  if (p) delete p;
383.6.1 by Mark Atwood
add pluggable logging
71
72
  return 0;
73
}
74
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
75
/* This gets called by plugin_foreach once for each loaded logging plugin */
779.3.1 by Monty Taylor
More cleanup.
76
static bool logging_pre_iterate (Session *session, plugin_ref plugin, void *)
383.6.1 by Mark Atwood
add pluggable logging
77
{
78
  logging_t *l= plugin_data(plugin, logging_t *);
79
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
80
  /* call this loaded logging plugin's logging_pre function pointer */
383.6.1 by Mark Atwood
add pluggable logging
81
  if (l && l->logging_pre)
82
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
83
    if (l->logging_pre(session))
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
84
    {
85
      /* TRANSLATORS: The leading word "logging" is the name
86
         of the plugin api, and so should not be translated. */
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
87
      errmsg_printf(ERRMSG_LVL_ERROR, _("logging plugin '%s' logging_pre() failed"),
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
88
		      (char *)plugin_name(plugin));
383.6.1 by Mark Atwood
add pluggable logging
89
      return true;
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
90
    }
383.6.1 by Mark Atwood
add pluggable logging
91
  }
92
  return false;
93
}
94
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
95
/* This is the logging_pre_do entry point.
96
   This gets called by the rest of the Drizzle server code */
520.1.22 by Brian Aker
Second pass of thd cleanup
97
bool logging_pre_do (Session *session)
383.6.1 by Mark Atwood
add pluggable logging
98
{
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
99
  bool foreach_rv;
100
520.1.22 by Brian Aker
Second pass of thd cleanup
101
  foreach_rv= plugin_foreach(session,
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
102
			     logging_pre_iterate,
103
			     DRIZZLE_LOGGER_PLUGIN,
104
			     NULL);
105
  return foreach_rv;
383.6.1 by Mark Atwood
add pluggable logging
106
}
107
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
108
/* This gets called by plugin_foreach once for each loaded logging plugin */
779.3.1 by Monty Taylor
More cleanup.
109
static bool logging_post_iterate (Session *session, plugin_ref plugin, void *)
383.6.1 by Mark Atwood
add pluggable logging
110
{
111
  logging_t *l= plugin_data(plugin, logging_t *);
112
113
  if (l && l->logging_post)
114
  {
520.1.22 by Brian Aker
Second pass of thd cleanup
115
    if (l->logging_post(session))
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
116
    {
117
      /* TRANSLATORS: The leading word "logging" is the name
118
         of the plugin api, and so should not be translated. */
755.2.1 by Mark Atwood
replace sql_print_error etc with errmsg_print
119
      errmsg_printf(ERRMSG_LVL_ERROR, _("logging plugin '%s' logging_post() failed"),
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
120
		      (char *)plugin_name(plugin));
383.6.1 by Mark Atwood
add pluggable logging
121
      return true;
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
122
    }
383.6.1 by Mark Atwood
add pluggable logging
123
  }
124
  return false;
125
}
126
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
127
/* This is the logging_pre_do entry point.
128
   This gets called by the rest of the Drizzle server code */
520.1.22 by Brian Aker
Second pass of thd cleanup
129
bool logging_post_do (Session *session)
383.6.1 by Mark Atwood
add pluggable logging
130
{
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
131
  bool foreach_rv;
132
520.1.22 by Brian Aker
Second pass of thd cleanup
133
  foreach_rv= plugin_foreach(session,
499.2.14 by Mark Atwood
fixes as per MontyT's comments, prep for internationalization
134
			     logging_post_iterate,
135
			     DRIZZLE_LOGGER_PLUGIN,
136
			     NULL);
137
  return foreach_rv;
383.6.1 by Mark Atwood
add pluggable logging
138
}