Merge lp:~fallenpegasus/drizzle/syslog-module into lp:~drizzle-trunk/drizzle/development

Proposed by Mark Atwood
Status: Merged
Approved by: Brian Aker
Approved revision: 1638
Merged at revision: 1639
Proposed branch: lp:~fallenpegasus/drizzle/syslog-module
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 1365 lines (+881/-390)
16 files modified
plugin/logging_syslog/logging_syslog.cc (+0/-284)
plugin/logging_syslog/names.h (+0/-100)
plugin/logging_syslog/plugin.ini (+0/-4)
plugin/syslog/errmsg.cc (+66/-0)
plugin/syslog/errmsg.h (+42/-0)
plugin/syslog/function.cc (+76/-0)
plugin/syslog/function.h (+45/-0)
plugin/syslog/logging.cc (+137/-0)
plugin/syslog/logging.h (+42/-0)
plugin/syslog/module.cc (+160/-0)
plugin/syslog/module.h (+38/-0)
plugin/syslog/names.h (+100/-0)
plugin/syslog/plugin.ini (+20/-0)
plugin/syslog/wrap.cc (+105/-0)
plugin/syslog/wrap.h (+48/-0)
support-files/drizzle.spec.in (+2/-2)
To merge this branch: bzr merge lp:~fallenpegasus/drizzle/syslog-module
Reviewer Review Type Date Requested Status
Monty Taylor Pending
Drizzle Developers Pending
Review via email: mp+28367@code.launchpad.net

Description of the change

This removes plugin/logging_syslog and replaces it with plugin/syslog

This new module replaces the "send query log to syslog" plugin, adds a plugin for sending error messages to the syslog, and also adds a function, SYSLOG().

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed directory 'plugin/logging_syslog'
2=== removed file 'plugin/logging_syslog/logging_syslog.cc'
3--- plugin/logging_syslog/logging_syslog.cc 2010-05-18 18:20:56 +0000
4+++ plugin/logging_syslog/logging_syslog.cc 1970-01-01 00:00:00 +0000
5@@ -1,284 +0,0 @@
6-/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
7- * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
8- *
9- * Copyright (C) 2009 Sun Microsystems
10- *
11- * This program is free software; you can redistribute it and/or modify
12- * it under the terms of the GNU General Public License as published by
13- * the Free Software Foundation; version 2 of the License.
14- *
15- * This program is distributed in the hope that it will be useful,
16- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18- * GNU General Public License for more details.
19- *
20- * You should have received a copy of the GNU General Public License
21- * along with this program; if not, write to the Free Software
22- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23- */
24-
25-#include "config.h"
26-#include <drizzled/plugin/logging.h>
27-#include <drizzled/gettext.h>
28-#include <drizzled/session.h>
29-
30-#ifdef __sun
31-# include <syslog.h>
32-# include <plugin/logging_syslog/names.h>
33-#else
34-# define SYSLOG_NAMES 1
35-# include <syslog.h>
36-#endif
37-
38-#include <stdarg.h>
39-#include <limits.h>
40-#include <sys/time.h>
41-#include <sys/types.h>
42-#include <sys/stat.h>
43-#include <fcntl.h>
44-
45-
46-using namespace drizzled;
47-
48-static bool sysvar_logging_syslog_enable= false;
49-static char* sysvar_logging_syslog_ident= NULL;
50-static char* sysvar_logging_syslog_facility= NULL;
51-static char* sysvar_logging_syslog_priority= NULL;
52-static ulong sysvar_logging_syslog_threshold_slow= 0;
53-static ulong sysvar_logging_syslog_threshold_big_resultset= 0;
54-static ulong sysvar_logging_syslog_threshold_big_examined= 0;
55-
56-/* stolen from mysys/my_getsystime
57- until the Session has a good utime "now" we can use
58- will have to use this instead */
59-
60-static uint64_t get_microtime()
61-{
62-#if defined(HAVE_GETHRTIME)
63- return gethrtime()/1000;
64-#else
65- uint64_t newtime;
66- struct timeval t;
67- /* loop is because gettimeofday may fail on some systems */
68- while (gettimeofday(&t, NULL) != 0) {}
69- newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
70- return newtime;
71-#endif
72-}
73-
74-class Logging_syslog: public drizzled::plugin::Logging
75-{
76-
77- int syslog_facility;
78- int syslog_priority;
79-
80-public:
81-
82- Logging_syslog()
83- : drizzled::plugin::Logging("Logging_syslog"),
84- syslog_facility(-1), syslog_priority(-1)
85- {
86-
87- for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
88- {
89- if (strcasecmp(facilitynames[ndx].c_name, sysvar_logging_syslog_facility) == 0)
90- {
91- syslog_facility= facilitynames[ndx].c_val;
92- break;
93- }
94- }
95- if (syslog_facility == -1)
96- {
97- errmsg_printf(ERRMSG_LVL_WARN,
98- _("syslog facility \"%s\" not known, using \"local0\""),
99- sysvar_logging_syslog_facility);
100- syslog_facility= LOG_LOCAL0;
101- }
102-
103- for (int ndx= 0; prioritynames[ndx].c_name; ndx++)
104- {
105- if (strcasecmp(prioritynames[ndx].c_name, sysvar_logging_syslog_priority) == 0)
106- {
107- syslog_priority= prioritynames[ndx].c_val;
108- break;
109- }
110- }
111- if (syslog_priority == -1)
112- {
113- errmsg_printf(ERRMSG_LVL_WARN,
114- _("syslog priority \"%s\" not known, using \"info\""),
115- sysvar_logging_syslog_priority);
116- syslog_priority= LOG_INFO;
117- }
118-
119- openlog(sysvar_logging_syslog_ident,
120- LOG_PID, syslog_facility);
121- }
122-
123- ~Logging_syslog()
124- {
125- closelog();
126- }
127-
128- virtual bool post (Session *session)
129- {
130- assert(session != NULL);
131-
132- // return if not enabled or query was too fast or resultset was too small
133- if (sysvar_logging_syslog_enable == false)
134- return false;
135- if (session->sent_row_count < sysvar_logging_syslog_threshold_big_resultset)
136- return false;
137- if (session->examined_row_count < sysvar_logging_syslog_threshold_big_examined)
138- return false;
139-
140- /* TODO, the session object should have a "utime command completed"
141- inside itself, so be more accurate, and so this doesnt have to
142- keep calling current_utime, which can be slow */
143-
144- uint64_t t_mark= get_microtime();
145-
146- if ((t_mark - session->start_utime) < sysvar_logging_syslog_threshold_slow)
147- return false;
148-
149- /* to avoid trying to printf %s something that is potentially NULL */
150-
151- const char *dbs= session->db.empty() ? "" : session->db.c_str();
152-
153- const char *qys= (! session->getQueryString().empty()) ? session->getQueryString().c_str() : "";
154- int qyl= 0;
155- if (qys)
156- qyl= session->getQueryLength();
157-
158- syslog(syslog_priority,
159- "thread_id=%ld query_id=%ld"
160- " db=\"%.*s\""
161- " query=\"%.*s\""
162- " command=\"%.*s\""
163- " t_connect=%lld t_start=%lld t_lock=%lld"
164- " rows_sent=%ld rows_examined=%ld"
165- " tmp_table=%ld total_warn_count=%ld\n",
166- (unsigned long) session->thread_id,
167- (unsigned long) session->getQueryId(),
168- (int)session->db.length(), dbs,
169- qyl, qys,
170- (int) command_name[session->command].length,
171- command_name[session->command].str,
172- (unsigned long long) (t_mark - session->getConnectMicroseconds()),
173- (unsigned long long) (t_mark - session->start_utime),
174- (unsigned long long) (t_mark - session->utime_after_lock),
175- (unsigned long) session->sent_row_count,
176- (unsigned long) session->examined_row_count,
177- (unsigned long) session->tmp_table,
178- (unsigned long) session->total_warn_count);
179-
180- return false;
181- }
182-};
183-
184-static Logging_syslog *handler= NULL;
185-
186-static int logging_syslog_plugin_init(drizzled::module::Context &context)
187-{
188- handler= new Logging_syslog();
189- context.add(handler);
190-
191- return 0;
192-}
193-
194-static DRIZZLE_SYSVAR_BOOL(
195- enable,
196- sysvar_logging_syslog_enable,
197- PLUGIN_VAR_NOCMDARG,
198- N_("Enable logging to syslog"),
199- NULL, /* check func */
200- NULL, /* update func */
201- false /* default */);
202-
203-static DRIZZLE_SYSVAR_STR(
204- ident,
205- sysvar_logging_syslog_ident,
206- PLUGIN_VAR_READONLY,
207- N_("Syslog Ident"),
208- NULL, /* check func */
209- NULL, /* update func*/
210- "drizzled" /* default */);
211-
212-static DRIZZLE_SYSVAR_STR(
213- facility,
214- sysvar_logging_syslog_facility,
215- PLUGIN_VAR_READONLY,
216- N_("Syslog Facility"),
217- NULL, /* check func */
218- NULL, /* update func*/
219- "local0" /* default */); // local0 is what PostGreSQL uses by default
220-
221-static DRIZZLE_SYSVAR_STR(
222- priority,
223- sysvar_logging_syslog_priority,
224- PLUGIN_VAR_READONLY,
225- N_("Syslog Priority"),
226- NULL, /* check func */
227- NULL, /* update func*/
228- "info" /* default */);
229-
230-static DRIZZLE_SYSVAR_ULONG(
231- threshold_slow,
232- sysvar_logging_syslog_threshold_slow,
233- PLUGIN_VAR_OPCMDARG,
234- N_("Threshold for logging slow queries, in microseconds"),
235- NULL, /* check func */
236- NULL, /* update func */
237- 0, /* default */
238- 0, /* min */
239- ULONG_MAX, /* max */
240- 0 /* blksiz */);
241-
242-static DRIZZLE_SYSVAR_ULONG(
243- threshold_big_resultset,
244- sysvar_logging_syslog_threshold_big_resultset,
245- PLUGIN_VAR_OPCMDARG,
246- N_("Threshold for logging big queries, for rows returned"),
247- NULL, /* check func */
248- NULL, /* update func */
249- 0, /* default */
250- 0, /* min */
251- ULONG_MAX, /* max */
252- 0 /* blksiz */);
253-
254-static DRIZZLE_SYSVAR_ULONG(
255- threshold_big_examined,
256- sysvar_logging_syslog_threshold_big_examined,
257- PLUGIN_VAR_OPCMDARG,
258- N_("Threshold for logging big queries, for rows examined"),
259- NULL, /* check func */
260- NULL, /* update func */
261- 0, /* default */
262- 0, /* min */
263- ULONG_MAX, /* max */
264- 0 /* blksiz */);
265-
266-static drizzle_sys_var* logging_syslog_system_variables[]= {
267- DRIZZLE_SYSVAR(enable),
268- DRIZZLE_SYSVAR(ident),
269- DRIZZLE_SYSVAR(facility),
270- DRIZZLE_SYSVAR(priority),
271- DRIZZLE_SYSVAR(threshold_slow),
272- DRIZZLE_SYSVAR(threshold_big_resultset),
273- DRIZZLE_SYSVAR(threshold_big_examined),
274- NULL
275-};
276-
277-DRIZZLE_DECLARE_PLUGIN
278-{
279- DRIZZLE_VERSION_ID,
280- "logging_syslog",
281- "0.2",
282- "Mark Atwood <mark@fallenpegasus.com>",
283- N_("Log to syslog"),
284- PLUGIN_LICENSE_GPL,
285- logging_syslog_plugin_init,
286- logging_syslog_system_variables,
287- NULL
288-}
289-DRIZZLE_DECLARE_PLUGIN_END;
290
291=== removed file 'plugin/logging_syslog/names.h'
292--- plugin/logging_syslog/names.h 2009-08-30 00:26:17 +0000
293+++ plugin/logging_syslog/names.h 1970-01-01 00:00:00 +0000
294@@ -1,100 +0,0 @@
295-/*
296- * Copyright (c) 1982, 1986, 1988, 1993
297- * The Regents of the University of California. All rights reserved.
298- *
299- * Redistribution and use in source and binary forms, with or without
300- * modification, are permitted provided that the following conditions
301- * are met:
302- * 1. Redistributions of source code must retain the above copyright
303- * notice, this list of conditions and the following disclaimer.
304- * 2. Redistributions in binary form must reproduce the above copyright
305- * notice, this list of conditions and the following disclaimer in the
306- * documentation and/or other materials provided with the distribution.
307- * 4. Neither the name of the University nor the names of its contributors
308- * may be used to endorse or promote products derived from this software
309- * without specific prior written permission.
310- *
311- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
312- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
313- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
314- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
315- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
316- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
317- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
318- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
319- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
320- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321- * SUCH DAMAGE.
322- *
323- * @(#)syslog.h 8.1 (Berkeley) 6/2/93
324- */
325-#ifndef PLUGIN_LOGGING_SYSLOG_NAMES_H
326-#define PLUGIN_LOGGING_SYSLOG_NAMES_H
327-
328-/* Solaris doesn't define these, so we copy them in. So Sad. */
329-
330-#ifndef LOG_FTP
331-# define LOG_FTP (11<<3)
332-#endif
333-#ifndef LOG_AUTHPRIV
334-# define LOG_AUTHPRIV (10<<3)
335-#endif
336-
337-#define LOG_PRI(p) ((p) & LOG_PRIMASK)
338-#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
339-
340-#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
341- /* mark "facility" */
342-#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0)
343-typedef struct _code {
344- const char *c_name;
345- int c_val;
346-} CODE;
347-
348-CODE prioritynames[] =
349- {
350- { "alert", LOG_ALERT },
351- { "crit", LOG_CRIT },
352- { "debug", LOG_DEBUG },
353- { "emerg", LOG_EMERG },
354- { "err", LOG_ERR },
355- { "error", LOG_ERR }, /* DEPRECATED */
356- { "info", LOG_INFO },
357- { "none", INTERNAL_NOPRI }, /* INTERNAL */
358- { "notice", LOG_NOTICE },
359- { "panic", LOG_EMERG }, /* DEPRECATED */
360- { "warn", LOG_WARNING }, /* DEPRECATED */
361- { "warning", LOG_WARNING },
362- { NULL, -1 }
363- };
364-
365-
366-CODE facilitynames[] =
367- {
368- { "auth", LOG_AUTH },
369- { "authpriv", LOG_AUTHPRIV },
370- { "cron", LOG_CRON },
371- { "daemon", LOG_DAEMON },
372- { "ftp", LOG_FTP },
373- { "kern", LOG_KERN },
374- { "lpr", LOG_LPR },
375- { "mail", LOG_MAIL },
376- { "mark", INTERNAL_MARK }, /* INTERNAL */
377- { "news", LOG_NEWS },
378- { "security", LOG_AUTH }, /* DEPRECATED */
379- { "syslog", LOG_SYSLOG },
380- { "user", LOG_USER },
381- { "uucp", LOG_UUCP },
382- { "local0", LOG_LOCAL0 },
383- { "local1", LOG_LOCAL1 },
384- { "local2", LOG_LOCAL2 },
385- { "local3", LOG_LOCAL3 },
386- { "local4", LOG_LOCAL4 },
387- { "local5", LOG_LOCAL5 },
388- { "local6", LOG_LOCAL6 },
389- { "local7", LOG_LOCAL7 },
390- { NULL, -1 }
391- };
392-
393-
394-#endif /* PLUGIN_LOGGING_SYSLOG_NAMES_H */
395
396=== removed file 'plugin/logging_syslog/plugin.ini'
397--- plugin/logging_syslog/plugin.ini 2009-11-29 19:55:08 +0000
398+++ plugin/logging_syslog/plugin.ini 1970-01-01 00:00:00 +0000
399@@ -1,4 +0,0 @@
400-[plugin]
401-title=Syslog Logging Plugin
402-description=Logging Plugin that writes to syslog.
403-headers=names.h
404
405=== added directory 'plugin/syslog'
406=== added file 'plugin/syslog/errmsg.cc'
407--- plugin/syslog/errmsg.cc 1970-01-01 00:00:00 +0000
408+++ plugin/syslog/errmsg.cc 2010-06-24 03:55:40 +0000
409@@ -0,0 +1,66 @@
410+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
411+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
412+ *
413+ * Copyright (C) 2010 Mark Atwood
414+ *
415+ * This program is free software; you can redistribute it and/or modify
416+ * it under the terms of the GNU General Public License as published by
417+ * the Free Software Foundation; version 2 of the License.
418+ *
419+ * This program is distributed in the hope that it will be useful,
420+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
421+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
422+ * GNU General Public License for more details.
423+ *
424+ * You should have received a copy of the GNU General Public License
425+ * along with this program; if not, write to the Free Software
426+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
427+ */
428+
429+#include "config.h"
430+
431+#include <drizzled/gettext.h>
432+#include <drizzled/session.h>
433+
434+#include <stdarg.h>
435+
436+#include "errmsg.h"
437+#include "wrap.h"
438+
439+using namespace drizzled;
440+
441+ErrorMessage_syslog::ErrorMessage_syslog()
442+ : drizzled::plugin::ErrorMessage("ErrorMessage_syslog")
443+{
444+ syslog_facility= WrapSyslog::getFacilityByName(syslog_module::sysvar_facility);
445+ if (syslog_facility == -1)
446+ {
447+ errmsg_printf(ERRMSG_LVL_WARN,
448+ _("syslog facility \"%s\" not known, using \"local0\""),
449+ syslog_module::sysvar_facility);
450+ syslog_facility= WrapSyslog::getFacilityByName("local0");
451+ assert (! (syslog_facility == -1));
452+ }
453+
454+ syslog_priority= WrapSyslog::getPriorityByName(syslog_module::sysvar_errmsg_priority);
455+ if (syslog_priority == -1)
456+ {
457+ errmsg_printf(ERRMSG_LVL_WARN,
458+ _("syslog priority \"%s\" not known, using \"warn\""),
459+ syslog_module::sysvar_errmsg_priority);
460+ syslog_priority= WrapSyslog::getPriorityByName("warn");
461+ assert (! (syslog_priority == -1));
462+ }
463+
464+ WrapSyslog::singleton().openlog(syslog_module::sysvar_ident);
465+}
466+
467+bool ErrorMessage_syslog::errmsg(drizzled::Session *,
468+ int,
469+ const char *format, va_list ap)
470+{
471+ if (syslog_module::sysvar_errmsg_enable == false)
472+ return false;
473+ WrapSyslog::singleton().vlog(syslog_facility, syslog_priority, format, ap);
474+ return false;
475+}
476
477=== added file 'plugin/syslog/errmsg.h'
478--- plugin/syslog/errmsg.h 1970-01-01 00:00:00 +0000
479+++ plugin/syslog/errmsg.h 2010-06-24 03:55:40 +0000
480@@ -0,0 +1,42 @@
481+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
482+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
483+ *
484+ * Copyright (C) 2010 Mark Atwood
485+ *
486+ * This program is free software; you can redistribute it and/or modify
487+ * it under the terms of the GNU General Public License as published by
488+ * the Free Software Foundation; version 2 of the License.
489+ *
490+ * This program is distributed in the hope that it will be useful,
491+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
492+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
493+ * GNU General Public License for more details.
494+ *
495+ * You should have received a copy of the GNU General Public License
496+ * along with this program; if not, write to the Free Software
497+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
498+ */
499+
500+#ifndef PLUGIN_SYSLOG_ERRMSG_H
501+#define PLUGIN_SYSLOG_ERRMSG_H
502+
503+#include "module.h"
504+#include <stdarg.h>
505+#include <drizzled/plugin/error_message.h>
506+
507+class ErrorMessage_syslog : public drizzled::plugin::ErrorMessage
508+{
509+ private:
510+ int syslog_facility;
511+ int syslog_priority;
512+
513+ ErrorMessage_syslog(const ErrorMessage_syslog&);
514+ ErrorMessage_syslog& operator=(const ErrorMessage_syslog&);
515+
516+ public:
517+ ErrorMessage_syslog();
518+
519+ virtual bool errmsg(drizzled::Session *, int, const char *format, va_list ap);
520+};
521+
522+#endif /* PLUGIN_SYSLOG_ERRMSG_H */
523
524=== added file 'plugin/syslog/function.cc'
525--- plugin/syslog/function.cc 1970-01-01 00:00:00 +0000
526+++ plugin/syslog/function.cc 2010-06-24 03:55:40 +0000
527@@ -0,0 +1,76 @@
528+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
529+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
530+ *
531+ * Copyright (C) 2010 Mark Atwood
532+ *
533+ * This program is free software; you can redistribute it and/or modify
534+ * it under the terms of the GNU General Public License as published by
535+ * the Free Software Foundation; version 2 of the License.
536+ *
537+ * This program is distributed in the hope that it will be useful,
538+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
539+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
540+ * GNU General Public License for more details.
541+ *
542+ * You should have received a copy of the GNU General Public License
543+ * along with this program; if not, write to the Free Software
544+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
545+ */
546+
547+#include "config.h"
548+
549+#include <drizzled/gettext.h>
550+#include <drizzled/session.h>
551+
552+#include "function.h"
553+#include "wrap.h"
554+
555+using namespace drizzled;
556+
557+Function_syslog::Function_syslog()
558+ : Item_str_func()
559+{
560+ WrapSyslog::singleton().openlog(syslog_module::sysvar_ident);
561+}
562+
563+String *Function_syslog::val_str(String *s)
564+{
565+
566+ if (args[0]->null_value || args[1]->null_value || args[2]->null_value)
567+ {
568+ null_value= 1;
569+ return 0;
570+ }
571+
572+ int syslog_facility= WrapSyslog::getFacilityByName(args[0]->val_str(s)->c_ptr());
573+ int syslog_priority= WrapSyslog::getPriorityByName(args[1]->val_str(s)->c_ptr());
574+
575+ if ((syslog_facility == -1) || (syslog_priority == -1))
576+ {
577+ null_value= 1;
578+ return 0;
579+ }
580+
581+ char *syslog_string= args[2]->val_str(s)->c_ptr();
582+ if ((syslog_string == 0) || (syslog_string[0] == 0))
583+ {
584+ null_value= 1;
585+ return 0;
586+ }
587+
588+ WrapSyslog::singleton().log(syslog_facility, syslog_priority, "%s", syslog_string);
589+
590+ null_value= 0;
591+ return args[2]->val_str(s);
592+}
593+
594+void Function_syslog::fix_length_and_dec()
595+{
596+ max_length= args[0]->max_length;
597+}
598+
599+bool Function_syslog::check_argument_count(int n)
600+{
601+ return (n == 3);
602+}
603+
604
605=== added file 'plugin/syslog/function.h'
606--- plugin/syslog/function.h 1970-01-01 00:00:00 +0000
607+++ plugin/syslog/function.h 2010-06-24 03:55:40 +0000
608@@ -0,0 +1,45 @@
609+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
610+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
611+ *
612+ * Copyright (C) 2010 Mark Atwood
613+ *
614+ * This program is free software; you can redistribute it and/or modify
615+ * it under the terms of the GNU General Public License as published by
616+ * the Free Software Foundation; version 2 of the License.
617+ *
618+ * This program is distributed in the hope that it will be useful,
619+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
620+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
621+ * GNU General Public License for more details.
622+ *
623+ * You should have received a copy of the GNU General Public License
624+ * along with this program; if not, write to the Free Software
625+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
626+ */
627+
628+#ifndef PLUGIN_SYSLOG_FUNCTION_H
629+#define PLUGIN_SYSLOG_FUNCTION_H
630+
631+#include "module.h"
632+
633+#include <drizzled/plugin/function.h>
634+#include <drizzled/item/func.h>
635+#include <drizzled/function/str/strfunc.h>
636+
637+class Function_syslog : public drizzled::Item_str_func
638+{
639+private:
640+ Function_syslog(const Function_syslog&);
641+ Function_syslog& operator=(const Function_syslog&);
642+
643+public:
644+ Function_syslog();
645+
646+ const char *func_name() const { return "syslog"; }
647+
648+ drizzled::String *val_str(drizzled::String *s);
649+ void fix_length_and_dec();
650+ bool check_argument_count(int n);
651+};
652+
653+#endif /* PLUGIN_SYSLOG_FUNCTION_H */
654
655=== added file 'plugin/syslog/logging.cc'
656--- plugin/syslog/logging.cc 1970-01-01 00:00:00 +0000
657+++ plugin/syslog/logging.cc 2010-06-24 03:55:40 +0000
658@@ -0,0 +1,137 @@
659+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
660+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
661+ *
662+ * Copyright (C) 2009 Sun Microsystems
663+ * Copyright (C) 2010 Mark Atwood
664+ *
665+ * This program is free software; you can redistribute it and/or modify
666+ * it under the terms of the GNU General Public License as published by
667+ * the Free Software Foundation; version 2 of the License.
668+ *
669+ * This program is distributed in the hope that it will be useful,
670+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
671+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
672+ * GNU General Public License for more details.
673+ *
674+ * You should have received a copy of the GNU General Public License
675+ * along with this program; if not, write to the Free Software
676+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
677+ */
678+
679+#include "config.h"
680+
681+#include <drizzled/gettext.h>
682+#include <drizzled/session.h>
683+
684+#include <stdarg.h>
685+#include <limits.h>
686+#include <sys/time.h>
687+#include <sys/types.h>
688+#include <sys/stat.h>
689+#include <fcntl.h>
690+
691+#include "logging.h"
692+#include "wrap.h"
693+
694+using namespace drizzled;
695+
696+/* stolen from mysys/my_getsystime
697+ until the Session has a good utime "now" we can use
698+ will have to use this instead */
699+
700+static uint64_t get_microtime()
701+{
702+#if defined(HAVE_GETHRTIME)
703+ return gethrtime()/1000;
704+#else
705+ uint64_t newtime;
706+ struct timeval t;
707+ /* loop is because gettimeofday may fail on some systems */
708+ while (gettimeofday(&t, NULL) != 0) {}
709+ newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
710+ return newtime;
711+#endif
712+}
713+
714+Logging_syslog::Logging_syslog()
715+ : drizzled::plugin::Logging("Logging_syslog")
716+{
717+ syslog_facility= WrapSyslog::getFacilityByName(syslog_module::sysvar_facility);
718+ if (syslog_facility < 0)
719+ {
720+ errmsg_printf(ERRMSG_LVL_WARN,
721+ _("syslog facility \"%s\" not known, using \"local0\""),
722+ syslog_module::sysvar_facility);
723+ syslog_facility= WrapSyslog::getFacilityByName("local0");
724+ }
725+
726+ syslog_priority= WrapSyslog::getPriorityByName(syslog_module::sysvar_logging_priority);
727+ if (syslog_priority < 0)
728+ {
729+ errmsg_printf(ERRMSG_LVL_WARN,
730+ _("syslog priority \"%s\" not known, using \"info\""),
731+ syslog_module::sysvar_logging_priority);
732+ syslog_priority= WrapSyslog::getPriorityByName("info");
733+ }
734+
735+ WrapSyslog::singleton().openlog(syslog_module::sysvar_ident);
736+}
737+
738+
739+bool Logging_syslog::post (Session *session)
740+{
741+ assert(session != NULL);
742+
743+ if (syslog_module::sysvar_logging_enable == false)
744+ return false;
745+
746+ // return if query was not too small
747+ if (session->sent_row_count < syslog_module::sysvar_logging_threshold_big_resultset)
748+ return false;
749+ if (session->examined_row_count < syslog_module::sysvar_logging_threshold_big_examined)
750+ return false;
751+
752+ /* TODO, the session object should have a "utime command completed"
753+ inside itself, so be more accurate, and so this doesnt have to
754+ keep calling current_utime, which can be slow */
755+
756+ uint64_t t_mark= get_microtime();
757+
758+ // return if query was not too slow
759+ if ((t_mark - session->start_utime) < syslog_module::sysvar_logging_threshold_slow)
760+ return false;
761+
762+ /* to avoid trying to printf %s something that is potentially NULL */
763+
764+ const char *dbs= session->db.empty() ? "" : session->db.c_str();
765+
766+ const char *qys= (! session->getQueryString().empty()) ? session->getQueryString().c_str() : "";
767+ int qyl= 0;
768+ if (qys)
769+ qyl= session->getQueryLength();
770+
771+ WrapSyslog::singleton()
772+ .log(syslog_facility, syslog_priority,
773+ "thread_id=%ld query_id=%ld"
774+ " db=\"%.*s\""
775+ " query=\"%.*s\""
776+ " command=\"%.*s\""
777+ " t_connect=%lld t_start=%lld t_lock=%lld"
778+ " rows_sent=%ld rows_examined=%ld"
779+ " tmp_table=%ld total_warn_count=%ld\n",
780+ (unsigned long) session->thread_id,
781+ (unsigned long) session->getQueryId(),
782+ (int) session->db.length(), dbs,
783+ qyl, qys,
784+ (int) command_name[session->command].length,
785+ command_name[session->command].str,
786+ (unsigned long long) (t_mark - session->getConnectMicroseconds()),
787+ (unsigned long long) (t_mark - session->start_utime),
788+ (unsigned long long) (t_mark - session->utime_after_lock),
789+ (unsigned long) session->sent_row_count,
790+ (unsigned long) session->examined_row_count,
791+ (unsigned long) session->tmp_table,
792+ (unsigned long) session->total_warn_count);
793+
794+ return false;
795+}
796
797=== added file 'plugin/syslog/logging.h'
798--- plugin/syslog/logging.h 1970-01-01 00:00:00 +0000
799+++ plugin/syslog/logging.h 2010-06-24 03:55:40 +0000
800@@ -0,0 +1,42 @@
801+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
802+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
803+ *
804+ * Copyright (C) 2009 Sun Microsystems
805+ * Copyright (C) 2010 Mark Atwood
806+ *
807+ * This program is free software; you can redistribute it and/or modify
808+ * it under the terms of the GNU General Public License as published by
809+ * the Free Software Foundation; version 2 of the License.
810+ *
811+ * This program is distributed in the hope that it will be useful,
812+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
813+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
814+ * GNU General Public License for more details.
815+ *
816+ * You should have received a copy of the GNU General Public License
817+ * along with this program; if not, write to the Free Software
818+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
819+ */
820+
821+#ifndef PLUGIN_SYSLOG_LOGGING_H
822+#define PLUGIN_SYSLOG_LOGGING_H
823+
824+#include "module.h"
825+#include <drizzled/plugin/logging.h>
826+
827+class Logging_syslog: public drizzled::plugin::Logging
828+{
829+ private:
830+ int syslog_facility;
831+ int syslog_priority;
832+
833+ Logging_syslog(const Logging_syslog&);
834+ Logging_syslog& operator=(const Logging_syslog&);
835+
836+ public:
837+ Logging_syslog();
838+
839+ virtual bool post (drizzled::Session *session);
840+};
841+
842+#endif /* PLUGIN_SYSLOG_LOGGING_H */
843
844=== added file 'plugin/syslog/module.cc'
845--- plugin/syslog/module.cc 1970-01-01 00:00:00 +0000
846+++ plugin/syslog/module.cc 2010-06-24 03:55:40 +0000
847@@ -0,0 +1,160 @@
848+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
849+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
850+ *
851+ * Copyright (C) 2010 Mark Atwood
852+ *
853+ * This program is free software; you can redistribute it and/or modify
854+ * it under the terms of the GNU General Public License as published by
855+ * the Free Software Foundation; version 2 of the License.
856+ *
857+ * This program is distributed in the hope that it will be useful,
858+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
859+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
860+ * GNU General Public License for more details.
861+ *
862+ * You should have received a copy of the GNU General Public License
863+ * along with this program; if not, write to the Free Software
864+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
865+ */
866+
867+#include "config.h"
868+#include "module.h"
869+
870+#include <drizzled/plugin.h>
871+#include <drizzled/plugin/logging.h>
872+#include <drizzled/plugin/error_message.h>
873+#include <drizzled/plugin/function.h>
874+
875+#include "logging.h"
876+#include "errmsg.h"
877+#include "function.h"
878+
879+using namespace drizzled;
880+
881+namespace syslog_module
882+{
883+
884+char* sysvar_ident;
885+char* sysvar_facility;
886+bool sysvar_logging_enable;
887+char* sysvar_logging_priority;
888+unsigned long sysvar_logging_threshold_slow;
889+unsigned long sysvar_logging_threshold_big_resultset;
890+unsigned long sysvar_logging_threshold_big_examined;
891+bool sysvar_errmsg_enable;
892+char* sysvar_errmsg_priority;
893+
894+static int init(drizzled::module::Context &context)
895+{
896+ context.add(new Logging_syslog());
897+ context.add(new ErrorMessage_syslog());
898+ context.add(new plugin::Create_function<Function_syslog>("syslog"));
899+ return 0;
900+}
901+
902+static DRIZZLE_SYSVAR_STR(
903+ ident,
904+ sysvar_ident,
905+ PLUGIN_VAR_READONLY,
906+ N_("Syslog Ident"),
907+ NULL, /* check func */
908+ NULL, /* update func*/
909+ "drizzled" /* default */);
910+
911+static DRIZZLE_SYSVAR_STR(
912+ facility,
913+ sysvar_facility,
914+ PLUGIN_VAR_READONLY,
915+ N_("Syslog Facility"),
916+ NULL, /* check func */
917+ NULL, /* update func*/
918+ "local0" /* default */); // local0 is what PostGreSQL uses by default
919+
920+static DRIZZLE_SYSVAR_BOOL(
921+ logging_enable,
922+ sysvar_logging_enable,
923+ PLUGIN_VAR_NOCMDARG,
924+ N_("Enable logging to syslog of the query log"),
925+ NULL, /* check func */
926+ NULL, /* update func */
927+ false /* default */);
928+
929+static DRIZZLE_SYSVAR_STR(
930+ logging_priority,
931+ sysvar_logging_priority,
932+ PLUGIN_VAR_READONLY,
933+ N_("Syslog Priority of query logging"),
934+ NULL, /* check func */
935+ NULL, /* update func*/
936+ "info" /* default */);
937+
938+static DRIZZLE_SYSVAR_ULONG(
939+ logging_threshold_slow,
940+ sysvar_logging_threshold_slow,
941+ PLUGIN_VAR_OPCMDARG,
942+ N_("Threshold for logging slow queries, in microseconds"),
943+ NULL, /* check func */
944+ NULL, /* update func */
945+ 0, /* default */
946+ 0, /* min */
947+ ULONG_MAX, /* max */
948+ 0 /* blksiz */);
949+
950+static DRIZZLE_SYSVAR_ULONG(
951+ logging_threshold_big_resultset,
952+ sysvar_logging_threshold_big_resultset,
953+ PLUGIN_VAR_OPCMDARG,
954+ N_("Threshold for logging big queries, for rows returned"),
955+ NULL, /* check func */
956+ NULL, /* update func */
957+ 0, /* default */
958+ 0, /* min */
959+ ULONG_MAX, /* max */
960+ 0 /* blksiz */);
961+
962+static DRIZZLE_SYSVAR_ULONG(
963+ logging_threshold_big_examined,
964+ sysvar_logging_threshold_big_examined,
965+ PLUGIN_VAR_OPCMDARG,
966+ N_("Threshold for logging big queries, for rows examined"),
967+ NULL, /* check func */
968+ NULL, /* update func */
969+ 0, /* default */
970+ 0, /* min */
971+ ULONG_MAX, /* max */
972+ 0 /* blksiz */);
973+
974+static DRIZZLE_SYSVAR_BOOL(
975+ errmsg_enable,
976+ sysvar_errmsg_enable,
977+ PLUGIN_VAR_NOCMDARG,
978+ N_("Enable logging to syslog of the error messages"),
979+ NULL, /* check func */
980+ NULL, /* update func */
981+ false /* default */);
982+
983+static DRIZZLE_SYSVAR_STR(
984+ errmsg_priority,
985+ sysvar_errmsg_priority,
986+ PLUGIN_VAR_READONLY,
987+ N_("Syslog Priority of error messages"),
988+ NULL, /* check func */
989+ NULL, /* update func*/
990+ "warning" /* default */);
991+
992+static drizzle_sys_var* system_variables[]= {
993+ DRIZZLE_SYSVAR(ident),
994+ DRIZZLE_SYSVAR(facility),
995+ DRIZZLE_SYSVAR(logging_enable),
996+ DRIZZLE_SYSVAR(logging_priority),
997+ DRIZZLE_SYSVAR(logging_threshold_slow),
998+ DRIZZLE_SYSVAR(logging_threshold_big_resultset),
999+ DRIZZLE_SYSVAR(logging_threshold_big_examined),
1000+ DRIZZLE_SYSVAR(errmsg_enable),
1001+ DRIZZLE_SYSVAR(errmsg_priority),
1002+ NULL
1003+};
1004+
1005+} // namespace syslog_module
1006+
1007+DRIZZLE_PLUGIN(syslog_module::init, syslog_module::system_variables);
1008
1009=== added file 'plugin/syslog/module.h'
1010--- plugin/syslog/module.h 1970-01-01 00:00:00 +0000
1011+++ plugin/syslog/module.h 2010-06-24 03:55:40 +0000
1012@@ -0,0 +1,38 @@
1013+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1014+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1015+ *
1016+ * Copyright (C) 2010 Mark Atwood
1017+ *
1018+ * This program is free software; you can redistribute it and/or modify
1019+ * it under the terms of the GNU General Public License as published by
1020+ * the Free Software Foundation; version 2 of the License.
1021+ *
1022+ * This program is distributed in the hope that it will be useful,
1023+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1024+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1025+ * GNU General Public License for more details.
1026+ *
1027+ * You should have received a copy of the GNU General Public License
1028+ * along with this program; if not, write to the Free Software
1029+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1030+ */
1031+
1032+#ifndef PLUGIN_SYSLOG_MODULE_H
1033+#define PLUGIN_SYSLOG_MODULE_H
1034+
1035+namespace syslog_module
1036+{
1037+
1038+extern char* sysvar_ident;
1039+extern char* sysvar_facility;
1040+extern bool sysvar_logging_enable;
1041+extern char* sysvar_logging_priority;
1042+extern unsigned long sysvar_logging_threshold_slow;
1043+extern unsigned long sysvar_logging_threshold_big_resultset;
1044+extern unsigned long sysvar_logging_threshold_big_examined;
1045+extern bool sysvar_errmsg_enable;
1046+extern char* sysvar_errmsg_priority;
1047+
1048+} // namespace syslog_module
1049+
1050+#endif /* PLUGIN_SYSLOG_MODULE_H */
1051
1052=== added file 'plugin/syslog/names.h'
1053--- plugin/syslog/names.h 1970-01-01 00:00:00 +0000
1054+++ plugin/syslog/names.h 2010-06-24 03:55:40 +0000
1055@@ -0,0 +1,100 @@
1056+/*
1057+ * Copyright (c) 1982, 1986, 1988, 1993
1058+ * The Regents of the University of California. All rights reserved.
1059+ *
1060+ * Redistribution and use in source and binary forms, with or without
1061+ * modification, are permitted provided that the following conditions
1062+ * are met:
1063+ * 1. Redistributions of source code must retain the above copyright
1064+ * notice, this list of conditions and the following disclaimer.
1065+ * 2. Redistributions in binary form must reproduce the above copyright
1066+ * notice, this list of conditions and the following disclaimer in the
1067+ * documentation and/or other materials provided with the distribution.
1068+ * 4. Neither the name of the University nor the names of its contributors
1069+ * may be used to endorse or promote products derived from this software
1070+ * without specific prior written permission.
1071+ *
1072+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1073+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1074+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1075+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1076+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1077+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1078+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1079+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1080+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1081+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1082+ * SUCH DAMAGE.
1083+ *
1084+ * @(#)syslog.h 8.1 (Berkeley) 6/2/93
1085+ */
1086+#ifndef PLUGIN_SYSLOG_NAMES_H
1087+#define PLUGIN_SYSLOG_NAMES_H
1088+
1089+/* Solaris doesn't define these, so we copy them in. So Sad. */
1090+
1091+#ifndef LOG_FTP
1092+# define LOG_FTP (11<<3)
1093+#endif
1094+#ifndef LOG_AUTHPRIV
1095+# define LOG_AUTHPRIV (10<<3)
1096+#endif
1097+
1098+#define LOG_PRI(p) ((p) & LOG_PRIMASK)
1099+#define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri))
1100+
1101+#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
1102+ /* mark "facility" */
1103+#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0)
1104+typedef struct _code {
1105+ const char *c_name;
1106+ int c_val;
1107+} CODE;
1108+
1109+CODE prioritynames[] =
1110+ {
1111+ { "alert", LOG_ALERT },
1112+ { "crit", LOG_CRIT },
1113+ { "debug", LOG_DEBUG },
1114+ { "emerg", LOG_EMERG },
1115+ { "err", LOG_ERR },
1116+ { "error", LOG_ERR }, /* DEPRECATED */
1117+ { "info", LOG_INFO },
1118+ { "none", INTERNAL_NOPRI }, /* INTERNAL */
1119+ { "notice", LOG_NOTICE },
1120+ { "panic", LOG_EMERG }, /* DEPRECATED */
1121+ { "warn", LOG_WARNING }, /* DEPRECATED */
1122+ { "warning", LOG_WARNING },
1123+ { NULL, -1 }
1124+ };
1125+
1126+
1127+CODE facilitynames[] =
1128+ {
1129+ { "auth", LOG_AUTH },
1130+ { "authpriv", LOG_AUTHPRIV },
1131+ { "cron", LOG_CRON },
1132+ { "daemon", LOG_DAEMON },
1133+ { "ftp", LOG_FTP },
1134+ { "kern", LOG_KERN },
1135+ { "lpr", LOG_LPR },
1136+ { "mail", LOG_MAIL },
1137+ { "mark", INTERNAL_MARK }, /* INTERNAL */
1138+ { "news", LOG_NEWS },
1139+ { "security", LOG_AUTH }, /* DEPRECATED */
1140+ { "syslog", LOG_SYSLOG },
1141+ { "user", LOG_USER },
1142+ { "uucp", LOG_UUCP },
1143+ { "local0", LOG_LOCAL0 },
1144+ { "local1", LOG_LOCAL1 },
1145+ { "local2", LOG_LOCAL2 },
1146+ { "local3", LOG_LOCAL3 },
1147+ { "local4", LOG_LOCAL4 },
1148+ { "local5", LOG_LOCAL5 },
1149+ { "local6", LOG_LOCAL6 },
1150+ { "local7", LOG_LOCAL7 },
1151+ { NULL, -1 }
1152+ };
1153+
1154+
1155+#endif /* PLUGIN_SYSLOG_NAMES_H */
1156
1157=== added file 'plugin/syslog/plugin.ini'
1158--- plugin/syslog/plugin.ini 1970-01-01 00:00:00 +0000
1159+++ plugin/syslog/plugin.ini 2010-06-24 03:55:40 +0000
1160@@ -0,0 +1,20 @@
1161+[plugin]
1162+title=Syslog
1163+description=Syslog interface for query log, error messages, and functions
1164+version=0.3
1165+author=Mark Atwood <me@mark.atwood.name>
1166+license=PLUGIN_LICENSE_GPL
1167+load_by_default=yes
1168+headers=
1169+ module.h
1170+ logging.h
1171+ errmsg.h
1172+ function.h
1173+ wrap.h
1174+ names.h
1175+sources=
1176+ module.cc
1177+ logging.cc
1178+ errmsg.cc
1179+ function.cc
1180+ wrap.cc
1181
1182=== added file 'plugin/syslog/wrap.cc'
1183--- plugin/syslog/wrap.cc 1970-01-01 00:00:00 +0000
1184+++ plugin/syslog/wrap.cc 2010-06-24 03:55:40 +0000
1185@@ -0,0 +1,105 @@
1186+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1187+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1188+ *
1189+ * Copyright (C) 2010 Mark Atwood
1190+ *
1191+ * This program is free software; you can redistribute it and/or modify
1192+ * it under the terms of the GNU General Public License as published by
1193+ * the Free Software Foundation; version 2 of the License.
1194+ *
1195+ * This program is distributed in the hope that it will be useful,
1196+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1197+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1198+ * GNU General Public License for more details.
1199+ *
1200+ * You should have received a copy of the GNU General Public License
1201+ * along with this program; if not, write to the Free Software
1202+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1203+ */
1204+
1205+#include "wrap.h"
1206+
1207+#include <assert.h>
1208+#include <stdarg.h>
1209+#include <string.h>
1210+
1211+#ifdef __sun
1212+# include <syslog.h>
1213+# include "names.h"
1214+#else
1215+# define SYSLOG_NAMES 1
1216+# include <syslog.h>
1217+#endif
1218+
1219+WrapSyslog::WrapSyslog () :
1220+ openlog_check(false)
1221+{ }
1222+
1223+WrapSyslog::~WrapSyslog ()
1224+{
1225+ ::closelog();
1226+ delete &(WrapSyslog::singleton());
1227+}
1228+
1229+WrapSyslog& WrapSyslog::singleton()
1230+{
1231+ static WrapSyslog *handle = new WrapSyslog();
1232+ return *handle;
1233+}
1234+
1235+/* TODO, for the sake of performance, scan through all the priority
1236+ and facility names, and construct a stl hash, minimal perfect hash,
1237+ or some other high performance read data structure. This can even
1238+ be done at compile time. */
1239+
1240+int WrapSyslog::getPriorityByName(const char *priority_name)
1241+{
1242+ for (int ndx= 0; prioritynames[ndx].c_name; ndx++)
1243+ {
1244+ if (strcasecmp(prioritynames[ndx].c_name, priority_name) == 0)
1245+ {
1246+ return prioritynames[ndx].c_val;
1247+ }
1248+ }
1249+ // no matching priority found
1250+ return -1;
1251+}
1252+
1253+int WrapSyslog::getFacilityByName(const char *facility_name)
1254+{
1255+ for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
1256+ {
1257+ if (strcasecmp(facilitynames[ndx].c_name, facility_name) == 0)
1258+ {
1259+ return facilitynames[ndx].c_val;
1260+ }
1261+ }
1262+ // no matching facility found
1263+ return -1;
1264+}
1265+
1266+void WrapSyslog::openlog(char *ident)
1267+{
1268+ if (openlog_check == false)
1269+ {
1270+ memset(openlog_ident, 0, sizeof(openlog_ident));
1271+ strncpy(openlog_ident, ident, sizeof(openlog_ident)-1);
1272+ ::openlog(openlog_ident, LOG_PID, LOG_USER);
1273+ openlog_check= true;
1274+ }
1275+}
1276+
1277+void WrapSyslog::vlog(int facility, int priority, const char *format, va_list ap)
1278+{
1279+ assert(openlog_check == true);
1280+ vsyslog(facility | priority, format, ap);
1281+}
1282+
1283+void WrapSyslog::log (int facility, int priority, const char *format, ...)
1284+{
1285+ assert(openlog_check == true);
1286+ va_list ap;
1287+ va_start(ap, format);
1288+ vsyslog(facility | priority, format, ap);
1289+ va_end(ap);
1290+}
1291
1292=== added file 'plugin/syslog/wrap.h'
1293--- plugin/syslog/wrap.h 1970-01-01 00:00:00 +0000
1294+++ plugin/syslog/wrap.h 2010-06-24 03:55:40 +0000
1295@@ -0,0 +1,48 @@
1296+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1297+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
1298+ *
1299+ * Copyright (C) 2010 Mark Atwood
1300+ *
1301+ * This program is free software; you can redistribute it and/or modify
1302+ * it under the terms of the GNU General Public License as published by
1303+ * the Free Software Foundation; version 2 of the License.
1304+ *
1305+ * This program is distributed in the hope that it will be useful,
1306+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1307+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1308+ * GNU General Public License for more details.
1309+ *
1310+ * You should have received a copy of the GNU General Public License
1311+ * along with this program; if not, write to the Free Software
1312+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1313+ */
1314+
1315+#ifndef PLUGIN_SYSLOG_WRAP_H
1316+#define PLUGIN_SYSLOG_WRAP_H
1317+
1318+#include <stdarg.h>
1319+
1320+class WrapSyslog
1321+{
1322+ private:
1323+ WrapSyslog(const WrapSyslog&);
1324+ WrapSyslog& operator=(const WrapSyslog&);
1325+
1326+ WrapSyslog();
1327+
1328+ bool openlog_check;
1329+ char openlog_ident[32];
1330+
1331+ public:
1332+ ~WrapSyslog();
1333+ static WrapSyslog& singleton();
1334+
1335+ static int getFacilityByName(const char *);
1336+ static int getPriorityByName(const char *);
1337+
1338+ void openlog(char *ident);
1339+ void vlog(int facility, int priority, const char *format, va_list ap);
1340+ void log(int facility, int priority, const char *format, ...);
1341+};
1342+
1343+#endif /* PLUGIN_SYSLOG_WRAP_H */
1344
1345=== modified file 'support-files/drizzle.spec.in'
1346--- support-files/drizzle.spec.in 2010-05-14 20:38:31 +0000
1347+++ support-files/drizzle.spec.in 2010-06-24 03:55:40 +0000
1348@@ -522,8 +522,6 @@
1349 %{_libdir}/drizzle/liblength_plugin.so
1350 %{_libdir}/drizzle/liblogging_query_plugin.la
1351 %{_libdir}/drizzle/liblogging_query_plugin.so
1352-%{_libdir}/drizzle/liblogging_syslog_plugin.la
1353-%{_libdir}/drizzle/liblogging_syslog_plugin.so
1354 %{_libdir}/drizzle/libmd5_plugin.la
1355 %{_libdir}/drizzle/libmd5_plugin.so
1356 %{_libdir}/drizzle/libmemcached_functions_plugin.la
1357@@ -542,6 +540,8 @@
1358 %{_libdir}/drizzle/libsingle_thread_plugin.so
1359 %{_libdir}/drizzle/libsleep_plugin.la
1360 %{_libdir}/drizzle/libsleep_plugin.so
1361+%{_libdir}/drizzle/libsyslog_plugin.la
1362+%{_libdir}/drizzle/libsyslog_plugin.so
1363 %{_libdir}/drizzle/libtableprototester_plugin.la
1364 %{_libdir}/drizzle/libtableprototester_plugin.so
1365 %{_libdir}/drizzle/libtransaction_log_plugin.la