ECLogger.i 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // ECLogger director
  2. %{
  3. #include <kopano/ECLogger.h>
  4. class IECSimpleLogger {
  5. public:
  6. virtual ~IECSimpleLogger() {};
  7. virtual HRESULT Log(unsigned int loglevel, const char *szMessage) = 0;
  8. };
  9. #include <kopano/swig_iunknown.h>
  10. typedef IUnknownImplementor<IECSimpleLogger> ECSimpleLogger;
  11. class ECLoggerProxy : public KC::ECLogger {
  12. public:
  13. static HRESULT Create(unsigned int ulLevel, ECSimpleLogger *lpSimpleLogger, ECLoggerProxy **lppProxy) {
  14. auto lpProxy = new ECLoggerProxy(ulLevel, lpSimpleLogger);
  15. //lpProxy->AddRef();
  16. *lppProxy = lpProxy;
  17. return hrSuccess;
  18. }
  19. ~ECLoggerProxy() {
  20. if (m_lpLogger)
  21. m_lpLogger->Release();
  22. };
  23. virtual void Reset() { };
  24. virtual void Log(unsigned int loglevel, const std::string &message) { Log(loglevel, "%s", message.c_str()); };
  25. virtual void Log(unsigned int Loglevel, const char *format, ...) __LIKE_PRINTF(3, 4) {
  26. va_list va;
  27. va_start(va, format);
  28. LogVA(Loglevel, format, va);
  29. va_end(va);
  30. };
  31. virtual void LogVA(unsigned int loglevel, const char *format, va_list& va) {
  32. if (m_lpLogger) {
  33. char buf[4096];
  34. vsnprintf(buf, sizeof(buf), format, va);
  35. m_lpLogger->Log(loglevel, buf);
  36. }
  37. };
  38. private:
  39. ECLoggerProxy(unsigned int ulLevel, ECSimpleLogger *lpSimpleLogger) : ECLogger(ulLevel), m_lpLogger(lpSimpleLogger) {
  40. if (m_lpLogger)
  41. m_lpLogger->AddRef();
  42. };
  43. ECSimpleLogger *m_lpLogger;
  44. };
  45. %}
  46. // Directors for ECLogger
  47. %feature("director") ECSimpleLogger;
  48. class ECSimpleLogger : public IECSimpleLogger{
  49. public:
  50. virtual HRESULT Log(unsigned int loglevel, const char *szMessage) = 0;
  51. };
  52. %include "cstring.i"
  53. %include "cwstring.i"
  54. class ECLogger {
  55. public:
  56. virtual bool Log(unsigned int loglevel) = 0;
  57. virtual void Reset() = 0;
  58. virtual int GetFileDescriptor() = 0;
  59. %extend {
  60. ~ECLogger() { self->Release(); }
  61. void Log(unsigned int loglevel, const char *szMessage) {
  62. self->Log(loglevel, "%s", szMessage);
  63. }
  64. }
  65. };
  66. enum {
  67. EC_LOGLEVEL_NONE,
  68. EC_LOGLEVEL_FATAL,
  69. EC_LOGLEVEL_ERROR,
  70. EC_LOGLEVEL_WARNING,
  71. EC_LOGLEVEL_NOTICE,
  72. EC_LOGLEVEL_INFO,
  73. EC_LOGLEVEL_DEBUG,
  74. EC_LOGLEVEL_FATAL = EC_LOGLEVEL_CRIT,
  75. EC_LOGLEVEL_ALWAYS = 0xf,
  76. };
  77. static const unsigned int EC_LOGLEVEL_CRIT = EC_LOGLEVEL_FATAL;
  78. static const unsigned int EC_LOGLEVEL_ALWAYS = 0xf;
  79. class ECLogger_File {
  80. public:
  81. ECLogger_File(const unsigned int max_ll, const bool add_timestamp, const char *const filename, const bool compress);
  82. };
  83. class ECLogger_Syslog {
  84. public:
  85. ECLogger_Syslog(unsigned int max_ll, const char *ident, int facility);
  86. };
  87. class ECLogger_Null {
  88. public:
  89. ECLogger_Null();
  90. };
  91. void ec_log_set(ECLogger_File *);
  92. void ec_log_set(ECLogger_Syslog *);
  93. void ec_log_set(ECLogger_Null *);
  94. ECLogger *ec_log_get(void);
  95. void ec_log(unsigned int level, const std::string &msg);