383.6.1
by Mark Atwood
add pluggable logging |
1 |
#include <drizzled/server_includes.h> |
2 |
#include <drizzled/logging.h> |
|
3 |
||
4 |
int logging_initializer(st_plugin_int *plugin) |
|
5 |
{
|
|
6 |
logging_t *p; |
|
7 |
||
8 |
fprintf(stderr, "MRA %s plugin:%s dl:%s\n", |
|
9 |
__func__, plugin->name.str, plugin->plugin_dl->dl.str); |
|
10 |
||
11 |
p= (logging_t *) malloc(sizeof(logging_t)); |
|
12 |
if (p == NULL) return 1; |
|
383.6.2
by Mark Atwood
changes of Brian's recommendation |
13 |
memset(p, 0, sizeof(logging_t)); |
383.6.1
by Mark Atwood
add pluggable logging |
14 |
|
15 |
plugin->data= (void *)p; |
|
16 |
||
17 |
if (plugin->plugin->init) |
|
18 |
{
|
|
19 |
if (plugin->plugin->init((void *)p)) |
|
20 |
{
|
|
21 |
sql_print_error("Logging plugin '%s' init function returned error.", |
|
22 |
plugin->name.str); |
|
23 |
goto err; |
|
24 |
}
|
|
25 |
}
|
|
26 |
return 0; |
|
27 |
||
28 |
err: |
|
29 |
free(p); |
|
30 |
return 1; |
|
31 |
}
|
|
32 |
||
33 |
int logging_finalizer(st_plugin_int *plugin) |
|
34 |
{
|
|
383.6.2
by Mark Atwood
changes of Brian's recommendation |
35 |
logging_t *p = (logging_t *) plugin->data; |
383.6.1
by Mark Atwood
add pluggable logging |
36 |
|
37 |
fprintf(stderr, "MRA %s plugin:%s dl:%s\n", |
|
38 |
__func__, plugin->name.str, plugin->plugin_dl->dl.str); |
|
39 |
||
40 |
if (plugin->plugin->deinit) |
|
41 |
{
|
|
42 |
if (plugin->plugin->deinit((void *)p)) |
|
43 |
{
|
|
44 |
sql_print_error("Logging plugin '%s' deinit function returned error.", |
|
45 |
plugin->name.str); |
|
46 |
}
|
|
47 |
}
|
|
48 |
||
49 |
if (p) free(p); |
|
50 |
||
51 |
return 0; |
|
52 |
}
|
|
53 |
||
383.6.3
by Mark Atwood
more work on plugable logging |
54 |
static bool logging_pre_iterate (THD *thd, plugin_ref plugin, |
55 |
void *stuff __attribute__ ((__unused__))) |
|
383.6.1
by Mark Atwood
add pluggable logging |
56 |
{
|
57 |
logging_t *l= plugin_data(plugin, logging_t *); |
|
58 |
||
59 |
if (l && l->logging_pre) |
|
60 |
{
|
|
383.6.2
by Mark Atwood
changes of Brian's recommendation |
61 |
if (l->logging_pre(thd)) |
383.6.1
by Mark Atwood
add pluggable logging |
62 |
return true; |
63 |
}
|
|
64 |
return false; |
|
65 |
}
|
|
66 |
||
383.6.2
by Mark Atwood
changes of Brian's recommendation |
67 |
void logging_pre_do (THD *thd) |
383.6.1
by Mark Atwood
add pluggable logging |
68 |
{
|
383.6.3
by Mark Atwood
more work on plugable logging |
69 |
if (plugin_foreach(thd, logging_pre_iterate, DRIZZLE_LOGGER_PLUGIN, NULL)) |
383.6.1
by Mark Atwood
add pluggable logging |
70 |
{
|
71 |
sql_print_error("Logging plugin pre had an error."); |
|
72 |
}
|
|
73 |
return; |
|
74 |
}
|
|
75 |
||
383.6.3
by Mark Atwood
more work on plugable logging |
76 |
static bool logging_post_iterate (THD *thd, plugin_ref plugin, |
77 |
void *stuff __attribute__ ((__unused__))) |
|
383.6.1
by Mark Atwood
add pluggable logging |
78 |
{
|
79 |
logging_t *l= plugin_data(plugin, logging_t *); |
|
80 |
||
81 |
if (l && l->logging_post) |
|
82 |
{
|
|
383.6.2
by Mark Atwood
changes of Brian's recommendation |
83 |
if (l->logging_post(thd)) |
383.6.1
by Mark Atwood
add pluggable logging |
84 |
return true; |
85 |
}
|
|
86 |
return false; |
|
87 |
}
|
|
88 |
||
383.6.2
by Mark Atwood
changes of Brian's recommendation |
89 |
void logging_post_do (THD *thd) |
383.6.1
by Mark Atwood
add pluggable logging |
90 |
{
|
383.6.3
by Mark Atwood
more work on plugable logging |
91 |
if (plugin_foreach(thd, logging_post_iterate, DRIZZLE_LOGGER_PLUGIN, NULL)) |
383.6.1
by Mark Atwood
add pluggable logging |
92 |
{
|
93 |
sql_print_error("Logging plugin post had an error."); |
|
94 |
}
|
|
95 |
return; |
|
96 |
}
|