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