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.

Logger.cxx 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. // -=- Logger.cxx - support for the Logger and LogWriter classes
  19. #include <stdarg.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <rfb/Logger.h>
  23. #include <rfb/LogWriter.h>
  24. #include <rfb/util.h>
  25. using namespace rfb;
  26. Logger* Logger::loggers = 0;
  27. Logger::Logger(const char* name) : registered(false), m_name(name), m_next(0) {
  28. }
  29. Logger::~Logger() {
  30. // *** Should remove this logger here!
  31. }
  32. void Logger::write(int level, const char *logname, const char* format,
  33. va_list ap)
  34. {
  35. // - Format the supplied data, and pass it to the
  36. // actual log_message function
  37. // The log level is included as a hint for loggers capable of representing
  38. // different log levels in some way.
  39. char buf1[4096];
  40. vsnprintf(buf1, sizeof(buf1)-1, format, ap);
  41. buf1[sizeof(buf1)-1] = 0;
  42. char *buf = buf1;
  43. while (true) {
  44. char *end = strchr(buf, '\n');
  45. if (end)
  46. *end = '\0';
  47. write(level, logname, buf);
  48. if (!end)
  49. break;
  50. buf = end + 1;
  51. }
  52. }
  53. void
  54. Logger::registerLogger() {
  55. if (!registered) {
  56. registered = true;
  57. m_next = loggers;
  58. loggers=this;
  59. }
  60. }
  61. Logger*
  62. Logger::getLogger(const char* name) {
  63. Logger* current = loggers;
  64. while (current) {
  65. if (strcasecmp(name, current->m_name) == 0) return current;
  66. current = current->m_next;
  67. }
  68. return 0;
  69. }
  70. void
  71. Logger::listLoggers() {
  72. Logger* current = loggers;
  73. while (current) {
  74. printf(" %s\n", current->m_name);
  75. current = current->m_next;
  76. }
  77. }