~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/syslog/wrap.cc

mergeĀ lp:~hingo/drizzle/drizzle-auth_ldap-fix-and-docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
 
20
#include <config.h>
 
21
 
20
22
#include "wrap.h"
21
23
 
22
 
#include <assert.h>
23
 
#include <stdarg.h>
24
 
#include <string.h>
 
24
#include <cassert>
 
25
#include <cstdarg>
 
26
#include <cstring>
25
27
 
26
28
#ifdef __sun
27
29
# include <syslog.h>
31
33
# include <syslog.h>
32
34
#endif
33
35
 
34
 
namespace drizzle_plugin
35
 
{
 
36
namespace drizzle_plugin {
36
37
 
37
38
WrapSyslog::WrapSyslog () :
38
39
  _check(false)
39
 
{ }
 
40
{
 
41
}
40
42
 
41
43
WrapSyslog::~WrapSyslog ()
42
44
{
43
45
  ::closelog();
44
46
}
45
47
 
 
48
int WrapSyslog::getFacilityByName(const char *facility_name)
 
49
{
 
50
  for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
 
51
  {
 
52
    if (strcasecmp(facilitynames[ndx].c_name, facility_name) == 0)
 
53
    {
 
54
      return facilitynames[ndx].c_val;
 
55
    }
 
56
  }
 
57
  // no matching facility found
 
58
  return -1;
 
59
}
46
60
 
47
 
/* TODO, for the sake of performance, scan through all the priority
 
61
/* 
 
62
  TODO, for the sake of performance, scan through all the priority
48
63
   and facility names, and construct a stl hash, minimal perfect hash,
49
64
   or some other high performance read data structure.  This can even
50
 
   be done at compile time. */
51
 
 
 
65
   be done at compile time. 
 
66
 */
52
67
int WrapSyslog::getPriorityByName(const char *priority_name)
53
68
{
54
69
  for (int ndx= 0; prioritynames[ndx].c_name; ndx++)
62
77
  return -1;
63
78
}
64
79
 
65
 
int WrapSyslog::getFacilityByName(const char *facility_name)
66
 
{
67
 
  for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
68
 
  {
69
 
    if (strcasecmp(facilitynames[ndx].c_name, facility_name) == 0)
70
 
    {
71
 
      return facilitynames[ndx].c_val;
72
 
    }
73
 
  }
74
 
  // no matching facility found
75
 
  return -1;
76
 
}
77
 
 
78
80
void WrapSyslog::openlog(const std::string &ident)
79
81
{
80
82
  if (_check == false)
84
86
  }
85
87
}
86
88
 
87
 
void WrapSyslog::vlog(int facility, int priority, const char *format, va_list ap)
 
89
void WrapSyslog::vlog(int facility, const drizzled::error::priority_t priority, const char *format, va_list ap)
88
90
{
89
91
  assert(_check == true);
90
 
  vsyslog(facility | priority, format, ap);
 
92
  vsyslog(facility | int(priority), format, ap);
91
93
}
92
94
 
93
 
void WrapSyslog::log (int facility, int priority, const char *format, ...)
 
95
void WrapSyslog::log (int facility, const drizzled::error::priority_t priority, const char *format, ...)
94
96
{
95
97
  assert(_check == true);
96
98
  va_list ap;
97
99
  va_start(ap, format);
98
 
  vsyslog(facility | priority, format, ap);
 
100
  vsyslog(facility | int(priority), format, ap);
99
101
  va_end(ap);
100
102
}
101
103