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