source: vendor/synergy/current/lib/base/LogOutputters.cpp

Last change on this file was 2749, checked in by bird, 19 years ago

synergy v1.3.1 sources (zip).

File size: 3.9 KB
Line 
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
22CStopLogOutputter::CStopLogOutputter()
23{
24 // do nothing
25}
26
27CStopLogOutputter::~CStopLogOutputter()
28{
29 // do nothing
30}
31
32void
33CStopLogOutputter::open(const char*)
34{
35 // do nothing
36}
37
38void
39CStopLogOutputter::close()
40{
41 // do nothing
42}
43
44void
45CStopLogOutputter::show(bool)
46{
47 // do nothing
48}
49
50bool
51CStopLogOutputter::write(ELevel, const char*)
52{
53 return false;
54}
55
56const char*
57CStopLogOutputter::getNewline() const
58{
59 return "";
60}
61
62
63//
64// CConsoleLogOutputter
65//
66
67CConsoleLogOutputter::CConsoleLogOutputter()
68{
69 // do nothing
70}
71
72CConsoleLogOutputter::~CConsoleLogOutputter()
73{
74 // do nothing
75}
76
77void
78CConsoleLogOutputter::open(const char* title)
79{
80 ARCH->openConsole(title);
81}
82
83void
84CConsoleLogOutputter::close()
85{
86 ARCH->closeConsole();
87}
88
89void
90CConsoleLogOutputter::show(bool showIfEmpty)
91{
92 ARCH->showConsole(showIfEmpty);
93}
94
95bool
96CConsoleLogOutputter::write(ELevel, const char* msg)
97{
98 ARCH->writeConsole(msg);
99 return true;
100}
101
102const char*
103CConsoleLogOutputter::getNewline() const
104{
105 return ARCH->getNewlineForConsole();
106}
107
108
109//
110// CSystemLogOutputter
111//
112
113CSystemLogOutputter::CSystemLogOutputter()
114{
115 // do nothing
116}
117
118CSystemLogOutputter::~CSystemLogOutputter()
119{
120 // do nothing
121}
122
123void
124CSystemLogOutputter::open(const char* title)
125{
126 ARCH->openLog(title);
127}
128
129void
130CSystemLogOutputter::close()
131{
132 ARCH->closeLog();
133}
134
135void
136CSystemLogOutputter::show(bool showIfEmpty)
137{
138 ARCH->showLog(showIfEmpty);
139}
140
141bool
142CSystemLogOutputter::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
172const char*
173CSystemLogOutputter::getNewline() const
174{
175 return "";
176}
177
178
179//
180// CSystemLogger
181//
182
183CSystemLogger::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
196CSystemLogger::~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
211CBufferedLogOutputter::CBufferedLogOutputter(UInt32 maxBufferSize) :
212 m_maxBufferSize(maxBufferSize)
213{
214 // do nothing
215}
216
217CBufferedLogOutputter::~CBufferedLogOutputter()
218{
219 // do nothing
220}
221
222CBufferedLogOutputter::const_iterator
223CBufferedLogOutputter::begin() const
224{
225 return m_buffer.begin();
226}
227
228CBufferedLogOutputter::const_iterator
229CBufferedLogOutputter::end() const
230{
231 return m_buffer.end();
232}
233
234void
235CBufferedLogOutputter::open(const char*)
236{
237 // do nothing
238}
239
240void
241CBufferedLogOutputter::close()
242{
243 // remove all elements from the buffer
244 m_buffer.clear();
245}
246
247void
248CBufferedLogOutputter::show(bool)
249{
250 // do nothing
251}
252
253bool
254CBufferedLogOutputter::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
263const char*
264CBufferedLogOutputter::getNewline() const
265{
266 return "";
267}
Note: See TracBrowser for help on using the repository browser.