~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/syslog/wrap.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-12-09 06:02:39 UTC
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20101209060239-t0ujftvcvd558yno
Tags: upstream-2010.12.05
ImportĀ upstreamĀ versionĀ 2010.12.05

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
# include <syslog.h>
32
32
#endif
33
33
 
 
34
namespace drizzle_plugin
 
35
{
 
36
 
34
37
WrapSyslog::WrapSyslog () :
35
 
  openlog_check(false)
 
38
  _check(false)
36
39
{ }
37
40
 
38
41
WrapSyslog::~WrapSyslog ()
40
43
  ::closelog();
41
44
}
42
45
 
43
 
WrapSyslog& WrapSyslog::singleton()
44
 
{
45
 
  static WrapSyslog handle;
46
 
  return handle;
47
 
}
48
46
 
49
47
/* TODO, for the sake of performance, scan through all the priority
50
48
   and facility names, and construct a stl hash, minimal perfect hash,
77
75
  return -1;
78
76
}
79
77
 
80
 
void WrapSyslog::openlog(char *ident)
 
78
void WrapSyslog::openlog(const std::string &ident)
81
79
{
82
 
  if (openlog_check == false)
 
80
  if (_check == false)
83
81
  {
84
 
    memset(openlog_ident, 0, sizeof(openlog_ident));
85
 
    strncpy(openlog_ident, ident, sizeof(openlog_ident)-1);
86
 
    ::openlog(openlog_ident, LOG_PID, LOG_USER);
87
 
    openlog_check= true;
 
82
    ::openlog(ident.c_str(), LOG_PID, LOG_USER);
 
83
    _check= true;
88
84
  }
89
85
}
90
86
 
91
87
void WrapSyslog::vlog(int facility, int priority, const char *format, va_list ap)
92
88
{
93
 
  assert(openlog_check == true);
 
89
  assert(_check == true);
94
90
  vsyslog(facility | priority, format, ap);
95
91
}
96
92
 
97
93
void WrapSyslog::log (int facility, int priority, const char *format, ...)
98
94
{
99
 
  assert(openlog_check == true);
 
95
  assert(_check == true);
100
96
  va_list ap;
101
97
  va_start(ap, format);
102
98
  vsyslog(facility | priority, format, ap);
103
99
  va_end(ap);
104
100
}
 
101
 
 
102
} /* namespace drizzle_plugin */