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

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