git.fiddlerwoaroof.com
sys_syslog.h
bc6c3d35
 /* Copyright (C) CJ Affiliate
  *
  * You may use, distribute and modify this code under  the
  * terms of the  GNU General Public License  version 2  or
  * later.
  *
  * You should have received a copy of the license with this
  * file. If not, you will find a copy in the "LICENSE" file
  * at https://github.com/cjdev/dual-control.
  */
 
a9690b1d
 #ifndef SYS_SYSLOG_H
 #define SYS_SYSLOG_H
 
 #include <memory>
 #include <cstdarg>
 #include <syslog.h>
 
bc6c3d35
 class sys_syslog_ifc
 {
 public:
4d825470
     virtual ~sys_syslog_ifc() {}
bc6c3d35
     virtual void openlog (const char *ident, int logopt, int facility) {}
     virtual void vsyslog (int priority, const char *message, va_list args) {}
     virtual void closelog() {}
a9690b1d
 };
 
3ae0e083
 class sys_syslog
bc6c3d35
 {
 public:
     typedef std::shared_ptr<sys_syslog_ifc> delegate;
 private:
     delegate delegate_;
 public:
     sys_syslog (const delegate &delegate) : delegate_ (delegate) {}
     sys_syslog() : sys_syslog (delegate (new sys_syslog_ifc)) {}
     void openlog (const char *ident, int logopt, int facility)
     {
         delegate_->openlog (ident, logopt, facility);
     }
     void syslog (int priority, const char *format, ...)
     {
         va_list vargs;
         va_start (vargs, format);
         vsyslog (priority, format, vargs);
         va_end (vargs);
     }
     void vsyslog (int priority, const char *message, va_list vargs)
     {
         delegate_->vsyslog (priority, message, vargs);
     }
     void closelog()
     {
         delegate_->closelog();
     }
a9690b1d
 
bc6c3d35
     static sys_syslog create();
a9690b1d
 };
 
 #endif
bc6c3d35