| 1 | /*
|
|---|
| 2 | * synergy -- mouse and keyboard sharing utility
|
|---|
| 3 | * Copyright (C) 2002 Chris Schoeneman
|
|---|
| 4 | *
|
|---|
| 5 | * This package is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU General Public License
|
|---|
| 7 | * found in the file COPYING that should have accompanied this file.
|
|---|
| 8 | *
|
|---|
| 9 | * This package is distributed in the hope that it will be useful,
|
|---|
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | * GNU General Public License for more details.
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 | #include "LogOutputters.h"
|
|---|
| 16 | #include "CArch.h"
|
|---|
| 17 |
|
|---|
| 18 | //
|
|---|
| 19 | // CStopLogOutputter
|
|---|
| 20 | //
|
|---|
| 21 |
|
|---|
| 22 | CStopLogOutputter::CStopLogOutputter()
|
|---|
| 23 | {
|
|---|
| 24 | // do nothing
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | CStopLogOutputter::~CStopLogOutputter()
|
|---|
| 28 | {
|
|---|
| 29 | // do nothing
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | void
|
|---|
| 33 | CStopLogOutputter::open(const char*)
|
|---|
| 34 | {
|
|---|
| 35 | // do nothing
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | void
|
|---|
| 39 | CStopLogOutputter::close()
|
|---|
| 40 | {
|
|---|
| 41 | // do nothing
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | void
|
|---|
| 45 | CStopLogOutputter::show(bool)
|
|---|
| 46 | {
|
|---|
| 47 | // do nothing
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | bool
|
|---|
| 51 | CStopLogOutputter::write(ELevel, const char*)
|
|---|
| 52 | {
|
|---|
| 53 | return false;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | const char*
|
|---|
| 57 | CStopLogOutputter::getNewline() const
|
|---|
| 58 | {
|
|---|
| 59 | return "";
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | //
|
|---|
| 64 | // CConsoleLogOutputter
|
|---|
| 65 | //
|
|---|
| 66 |
|
|---|
| 67 | CConsoleLogOutputter::CConsoleLogOutputter()
|
|---|
| 68 | {
|
|---|
| 69 | // do nothing
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | CConsoleLogOutputter::~CConsoleLogOutputter()
|
|---|
| 73 | {
|
|---|
| 74 | // do nothing
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | void
|
|---|
| 78 | CConsoleLogOutputter::open(const char* title)
|
|---|
| 79 | {
|
|---|
| 80 | ARCH->openConsole(title);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | void
|
|---|
| 84 | CConsoleLogOutputter::close()
|
|---|
| 85 | {
|
|---|
| 86 | ARCH->closeConsole();
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | void
|
|---|
| 90 | CConsoleLogOutputter::show(bool showIfEmpty)
|
|---|
| 91 | {
|
|---|
| 92 | ARCH->showConsole(showIfEmpty);
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | bool
|
|---|
| 96 | CConsoleLogOutputter::write(ELevel, const char* msg)
|
|---|
| 97 | {
|
|---|
| 98 | ARCH->writeConsole(msg);
|
|---|
| 99 | return true;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | const char*
|
|---|
| 103 | CConsoleLogOutputter::getNewline() const
|
|---|
| 104 | {
|
|---|
| 105 | return ARCH->getNewlineForConsole();
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | //
|
|---|
| 110 | // CSystemLogOutputter
|
|---|
| 111 | //
|
|---|
| 112 |
|
|---|
| 113 | CSystemLogOutputter::CSystemLogOutputter()
|
|---|
| 114 | {
|
|---|
| 115 | // do nothing
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | CSystemLogOutputter::~CSystemLogOutputter()
|
|---|
| 119 | {
|
|---|
| 120 | // do nothing
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | void
|
|---|
| 124 | CSystemLogOutputter::open(const char* title)
|
|---|
| 125 | {
|
|---|
| 126 | ARCH->openLog(title);
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | void
|
|---|
| 130 | CSystemLogOutputter::close()
|
|---|
| 131 | {
|
|---|
| 132 | ARCH->closeLog();
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | void
|
|---|
| 136 | CSystemLogOutputter::show(bool showIfEmpty)
|
|---|
| 137 | {
|
|---|
| 138 | ARCH->showLog(showIfEmpty);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | bool
|
|---|
| 142 | CSystemLogOutputter::write(ELevel level, const char* msg)
|
|---|
| 143 | {
|
|---|
| 144 | IArchLog::ELevel archLogLevel;
|
|---|
| 145 | switch (level) {
|
|---|
| 146 | case CLog::kFATAL:
|
|---|
| 147 | case CLog::kERROR:
|
|---|
| 148 | archLogLevel = IArchLog::kERROR;
|
|---|
| 149 | break;
|
|---|
| 150 |
|
|---|
| 151 | case CLog::kWARNING:
|
|---|
| 152 | archLogLevel = IArchLog::kWARNING;
|
|---|
| 153 | break;
|
|---|
| 154 |
|
|---|
| 155 | case CLog::kNOTE:
|
|---|
| 156 | archLogLevel = IArchLog::kNOTE;
|
|---|
| 157 | break;
|
|---|
| 158 |
|
|---|
| 159 | case CLog::kINFO:
|
|---|
| 160 | archLogLevel = IArchLog::kINFO;
|
|---|
| 161 | break;
|
|---|
| 162 |
|
|---|
| 163 | default:
|
|---|
| 164 | archLogLevel = IArchLog::kDEBUG;
|
|---|
| 165 | break;
|
|---|
| 166 |
|
|---|
| 167 | };
|
|---|
| 168 | ARCH->writeLog(archLogLevel, msg);
|
|---|
| 169 | return true;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | const char*
|
|---|
| 173 | CSystemLogOutputter::getNewline() const
|
|---|
| 174 | {
|
|---|
| 175 | return "";
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 | //
|
|---|
| 180 | // CSystemLogger
|
|---|
| 181 | //
|
|---|
| 182 |
|
|---|
| 183 | CSystemLogger::CSystemLogger(const char* title, bool blockConsole) :
|
|---|
| 184 | m_stop(NULL)
|
|---|
| 185 | {
|
|---|
| 186 | // redirect log messages
|
|---|
| 187 | if (blockConsole) {
|
|---|
| 188 | m_stop = new CStopLogOutputter;
|
|---|
| 189 | CLOG->insert(m_stop);
|
|---|
| 190 | }
|
|---|
| 191 | m_syslog = new CSystemLogOutputter;
|
|---|
| 192 | m_syslog->open(title);
|
|---|
| 193 | CLOG->insert(m_syslog);
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | CSystemLogger::~CSystemLogger()
|
|---|
| 197 | {
|
|---|
| 198 | CLOG->remove(m_syslog);
|
|---|
| 199 | delete m_syslog;
|
|---|
| 200 | if (m_stop != NULL) {
|
|---|
| 201 | CLOG->remove(m_stop);
|
|---|
| 202 | delete m_stop;
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 | //
|
|---|
| 208 | // CBufferedLogOutputter
|
|---|
| 209 | //
|
|---|
| 210 |
|
|---|
| 211 | CBufferedLogOutputter::CBufferedLogOutputter(UInt32 maxBufferSize) :
|
|---|
| 212 | m_maxBufferSize(maxBufferSize)
|
|---|
| 213 | {
|
|---|
| 214 | // do nothing
|
|---|
| 215 | }
|
|---|
| 216 |
|
|---|
| 217 | CBufferedLogOutputter::~CBufferedLogOutputter()
|
|---|
| 218 | {
|
|---|
| 219 | // do nothing
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | CBufferedLogOutputter::const_iterator
|
|---|
| 223 | CBufferedLogOutputter::begin() const
|
|---|
| 224 | {
|
|---|
| 225 | return m_buffer.begin();
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | CBufferedLogOutputter::const_iterator
|
|---|
| 229 | CBufferedLogOutputter::end() const
|
|---|
| 230 | {
|
|---|
| 231 | return m_buffer.end();
|
|---|
| 232 | }
|
|---|
| 233 |
|
|---|
| 234 | void
|
|---|
| 235 | CBufferedLogOutputter::open(const char*)
|
|---|
| 236 | {
|
|---|
| 237 | // do nothing
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | void
|
|---|
| 241 | CBufferedLogOutputter::close()
|
|---|
| 242 | {
|
|---|
| 243 | // remove all elements from the buffer
|
|---|
| 244 | m_buffer.clear();
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | void
|
|---|
| 248 | CBufferedLogOutputter::show(bool)
|
|---|
| 249 | {
|
|---|
| 250 | // do nothing
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | bool
|
|---|
| 254 | CBufferedLogOutputter::write(ELevel, const char* message)
|
|---|
| 255 | {
|
|---|
| 256 | while (m_buffer.size() >= m_maxBufferSize) {
|
|---|
| 257 | m_buffer.pop_front();
|
|---|
| 258 | }
|
|---|
| 259 | m_buffer.push_back(CString(message));
|
|---|
| 260 | return true;
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | const char*
|
|---|
| 264 | CBufferedLogOutputter::getNewline() const
|
|---|
| 265 | {
|
|---|
| 266 | return "";
|
|---|
| 267 | }
|
|---|