00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <config.h>
00021
00022 #include "wrap.h"
00023
00024 #include <cassert>
00025 #include <cstdarg>
00026 #include <cstring>
00027
00028 #ifdef __sun
00029 # include <syslog.h>
00030 # include "names.h"
00031 #else
00032 # define SYSLOG_NAMES 1
00033 # include <syslog.h>
00034 #endif
00035
00036 namespace drizzle_plugin {
00037
00038 WrapSyslog::WrapSyslog () :
00039 _check(false)
00040 {
00041 }
00042
00043 WrapSyslog::~WrapSyslog ()
00044 {
00045 ::closelog();
00046 }
00047
00048 int WrapSyslog::getFacilityByName(const char *facility_name)
00049 {
00050 for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
00051 {
00052 if (strcasecmp(facilitynames[ndx].c_name, facility_name) == 0)
00053 {
00054 return facilitynames[ndx].c_val;
00055 }
00056 }
00057
00058 return -1;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067 int WrapSyslog::getPriorityByName(const char *priority_name)
00068 {
00069 for (int ndx= 0; prioritynames[ndx].c_name; ndx++)
00070 {
00071 if (strcasecmp(prioritynames[ndx].c_name, priority_name) == 0)
00072 {
00073 return prioritynames[ndx].c_val;
00074 }
00075 }
00076
00077 return -1;
00078 }
00079
00080 void WrapSyslog::openlog(const std::string &ident)
00081 {
00082 if (_check == false)
00083 {
00084 ::openlog(ident.c_str(), LOG_PID, LOG_USER);
00085 _check= true;
00086 }
00087 }
00088
00089 void WrapSyslog::vlog(int facility, const drizzled::error::priority_t priority, const char *format, va_list ap)
00090 {
00091 assert(_check == true);
00092 vsyslog(facility | int(priority), format, ap);
00093 }
00094
00095 void WrapSyslog::log (int facility, const drizzled::error::priority_t priority, const char *format, ...)
00096 {
00097 assert(_check == true);
00098 va_list ap;
00099 va_start(ap, format);
00100 vsyslog(facility | int(priority), format, ap);
00101 va_end(ap);
00102 }
00103
00104 }