You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LogWriter.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. // -=- LogWriter.h - The Log writer class.
  19. #ifndef __RFB_LOG_WRITER_H__
  20. #define __RFB_LOG_WRITER_H__
  21. #include <stdarg.h>
  22. #include <rfb/Logger.h>
  23. #include <rfb/Configuration.h>
  24. // Each log writer instance has a unique textual name,
  25. // and is attached to a particular Log instance and
  26. // is assigned a particular log level.
  27. #define DEF_LOGFUNCTION(name, level) \
  28. inline void v##name(const char* fmt, va_list ap) \
  29. __attribute__((__format__ (__printf__, 2, 0))) \
  30. { \
  31. if (m_log && (level <= m_level)) \
  32. m_log->write(level, m_name, fmt, ap); \
  33. } \
  34. inline void name(const char* fmt, ...) \
  35. __attribute__((__format__ (__printf__, 2, 3))) \
  36. { \
  37. if (m_log && (level <= m_level)) { \
  38. va_list ap; va_start(ap, fmt); \
  39. m_log->write(level, m_name, fmt, ap);\
  40. va_end(ap); \
  41. } \
  42. }
  43. namespace rfb {
  44. class LogWriter;
  45. class LogWriter {
  46. public:
  47. LogWriter(const char* name);
  48. ~LogWriter();
  49. const char *getName() {return m_name;}
  50. void setLog(Logger *logger);
  51. void setLevel(int level);
  52. int getLevel(void) { return m_level; }
  53. inline void write(int level, const char* format, ...)
  54. __attribute__((__format__ (__printf__, 3, 4)))
  55. {
  56. if (m_log && (level <= m_level)) {
  57. va_list ap;
  58. va_start(ap, format);
  59. m_log->write(level, m_name, format, ap);
  60. va_end(ap);
  61. }
  62. }
  63. static const int LEVEL_ERROR = 0;
  64. static const int LEVEL_STATUS = 10;
  65. static const int LEVEL_INFO = 30;
  66. static const int LEVEL_DEBUG = 100;
  67. DEF_LOGFUNCTION(error, LEVEL_ERROR)
  68. DEF_LOGFUNCTION(status, LEVEL_STATUS)
  69. DEF_LOGFUNCTION(info, LEVEL_INFO)
  70. DEF_LOGFUNCTION(debug, LEVEL_DEBUG)
  71. // -=- DIAGNOSTIC & HELPER ROUTINES
  72. static void listLogWriters(int width=79);
  73. // -=- CLASS FIELDS & FUNCTIONS
  74. static LogWriter* log_writers;
  75. static LogWriter* getLogWriter(const char* name);
  76. static bool setLogParams(const char* params);
  77. private:
  78. const char* m_name;
  79. int m_level;
  80. Logger* m_log;
  81. LogWriter* m_next;
  82. };
  83. class LogParameter : public StringParameter {
  84. public:
  85. LogParameter();
  86. virtual bool setParam(const char* v);
  87. };
  88. extern LogParameter logParams;
  89. };
  90. #endif // __RFB_LOG_WRITER_H__