~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/syslog/wrap.cc

  • Committer: Brian Aker
  • Date: 2011-10-19 19:30:54 UTC
  • mto: This revision was merged to the branch mainline in revision 2444.
  • Revision ID: brian@tangent.org-20111019193054-pxnb4hflrmbfhmbm
Fix level_t to be more inline with syslog

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>
35
37
 
36
38
WrapSyslog::WrapSyslog () :
37
39
  _check(false)
38
 
{ }
 
40
{
 
41
}
39
42
 
40
43
WrapSyslog::~WrapSyslog ()
41
44
{
42
45
  ::closelog();
43
46
}
44
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
}
45
60
 
46
 
/* TODO, for the sake of performance, scan through all the priority
 
61
/* 
 
62
  TODO, for the sake of performance, scan through all the priority
47
63
   and facility names, and construct a stl hash, minimal perfect hash,
48
64
   or some other high performance read data structure.  This can even
49
 
   be done at compile time. */
50
 
 
 
65
   be done at compile time. 
 
66
 */
51
67
int WrapSyslog::getPriorityByName(const char *priority_name)
52
68
{
53
69
  for (int ndx= 0; prioritynames[ndx].c_name; ndx++)
61
77
  return -1;
62
78
}
63
79
 
64
 
int WrapSyslog::getFacilityByName(const char *facility_name)
65
 
{
66
 
  for (int ndx= 0; facilitynames[ndx].c_name; ndx++)
67
 
  {
68
 
    if (strcasecmp(facilitynames[ndx].c_name, facility_name) == 0)
69
 
    {
70
 
      return facilitynames[ndx].c_val;
71
 
    }
72
 
  }
73
 
  // no matching facility found
74
 
  return -1;
75
 
}
76
 
 
77
80
void WrapSyslog::openlog(const std::string &ident)
78
81
{
79
82
  if (_check == false)
83
86
  }
84
87
}
85
88
 
86
 
void WrapSyslog::vlog(int facility, int priority, const char *format, va_list ap)
 
89
void WrapSyslog::vlog(int facility, const drizzled::error::level_t priority, const char *format, va_list ap)
87
90
{
88
91
  assert(_check == true);
89
 
  vsyslog(facility | priority, format, ap);
 
92
  vsyslog(facility | int(priority), format, ap);
90
93
}
91
94
 
92
 
void WrapSyslog::log (int facility, int priority, const char *format, ...)
 
95
void WrapSyslog::log (int facility, const drizzled::error::level_t priority, const char *format, ...)
93
96
{
94
97
  assert(_check == true);
95
98
  va_list ap;
96
99
  va_start(ap, format);
97
 
  vsyslog(facility | priority, format, ap);
 
100
  vsyslog(facility | int(priority), format, ap);
98
101
  va_end(ap);
99
102
}
100
103