SyslogAppender.hh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * SyslogAppender.hh
  3. *
  4. * Copyright 2000, LifeLine Networks BV (www.lifeline.nl). All rights reserved.
  5. * Copyright 2000, Bastiaan Bakker. All rights reserved.
  6. *
  7. * See the COPYING file for the terms of usage and distribution.
  8. */
  9. #ifndef _LOG4CPP_SYSLOGAPPENDER_HH
  10. #define _LOG4CPP_SYSLOGAPPENDER_HH
  11. #include <log4cpp/Portability.hh>
  12. #include <string>
  13. #include <stdarg.h>
  14. #include <syslog.h>
  15. #include <log4cpp/LayoutAppender.hh>
  16. #include <log4cpp/Priority.hh>
  17. LOG4CPP_NS_BEGIN
  18. /**
  19. * SyslogAppender sends LoggingEvents to the local syslog system.
  20. **/
  21. class LOG4CPP_EXPORT SyslogAppender : public LayoutAppender {
  22. public:
  23. /**
  24. * Translates a log4cpp priority to a syslog priority
  25. * @param priority The log4cpp priority.
  26. * @returns the syslog priority.
  27. **/
  28. static int toSyslogPriority(Priority::Value priority);
  29. /**
  30. * Instantiate a SyslogAppender with given name and name and facility
  31. * for syslog. Note that the C syslog API is process global, so
  32. * instantion of a second SyslogAppender will 'overwrite' the
  33. * syslog name of the first.
  34. * @param name The name of the Appender
  35. * @param syslogName The ident parameter in the openlog(3) call.
  36. * @param facility The syslog facility to log to. Defaults to LOG_USER.
  37. **/
  38. SyslogAppender(const std::string& name, const std::string& syslogName,
  39. int facility = LOG_USER);
  40. virtual ~SyslogAppender();
  41. /**
  42. * Calls closelog(3) and openlog(3).
  43. **/
  44. virtual bool reopen();
  45. /**
  46. * Calls closelog(3) to close the syslog file descriptor.
  47. **/
  48. virtual void close();
  49. protected:
  50. /**
  51. * Calls openlog(3).
  52. **/
  53. virtual void open();
  54. /**
  55. * Sends a LoggingEvent to syslog.
  56. * @param event the LoggingEvent to log.
  57. **/
  58. virtual void _append(const LoggingEvent& event);
  59. const std::string _syslogName;
  60. int _facility;
  61. };
  62. LOG4CPP_NS_END
  63. #endif // _LOG4CPP_SYSLOGAPPENDER_HH