2
#include "rutil/Logger.hxx"
3
#include "rutil/Data.hxx"
4
#include "rutil/ThreadIf.hxx"
5
#include "rutil/Timer.hxx"
7
#include "TestSubsystemLogLevel.hxx"
8
#include "rutil/WinLeakCheck.hxx"
11
#define usleep(x) Sleep(x/1000)
12
#define sleep(x) Sleep(x*1000)
15
using namespace resip;
18
#define RESIPROCATE_SUBSYSTEM Subsystem::SIP
21
class LogThread : public ThreadIf
24
LogThread(const Data& description, const Log::ThreadSetting& s,
25
Log::LocalLoggerId id = 0)
26
: mDescription(description),
33
Log::setThreadSetting(mSetting);
34
int reval = Log::setThreadLocalLogger(mId);
35
(void)reval; // make gcc4 happy
36
// InfoLog(<< "setThreadLocalLogger(" << mId << ") returned " << reval);
37
while(!waitForShutdown(1000))
39
StackLog(<< mDescription << " STACK");
40
DebugLog(<< mDescription << " DEBUG");
41
InfoLog(<< mDescription << " INFO");
46
Log::ThreadSetting mSetting;
47
Log::LocalLoggerId mId;
52
InfoLog(<< "Got here?");
59
DebugLog(<< "Got here?");
63
class TestExternalLogger : public ExternalLogger
66
virtual bool operator()(Log::Level level,
67
const Subsystem& subsystem,
72
const Data& messageWithHeaders)
74
cout << "From TestExternalLogger: " << message << endl;
80
testThreadLocalLoggers(const char *appname)
82
Log::initialize(Log::Cout, Log::Info, appname);
84
InfoLog(<<"Going to test thread local loggers.");
85
Noisy::outputLogMessages();
87
Log::LocalLoggerId id1 = Log::localLoggerCreate(Log::File, Log::Info, "testLogger-local1.txt");
88
Log::LocalLoggerId id2 = Log::localLoggerCreate(Log::File, Log::Info, "testLogger-local2.txt");
90
LogThread serviceErr("service with wrong local logger Id",
91
Log::ThreadSetting(1, Log::Debug), id2+10);
93
LogThread service0("global", Log::ThreadSetting(1, Log::Debug));
94
LogThread service1a("local1----A", Log::ThreadSetting(1, Log::Debug), id1);
95
LogThread service1b("local1-------B", Log::ThreadSetting(1, Log::Debug), id1);
96
LogThread service2a("local2---------C", Log::ThreadSetting(1, Log::Debug), id2);
97
LogThread service2b("local2-----------D", Log::ThreadSetting(1, Log::Debug), id2);
108
service1a.shutdown();
109
service1b.shutdown();
110
service2a.shutdown();
111
service2b.shutdown();
119
int retval = Log::localLoggerRemove(id1);
122
std::cerr << "Local logger 1 hasn't been cleaned up correctly! "
123
"Log::localLoggerRemove() return code is " << retval << std::endl;
125
retval = Log::localLoggerRemove(id2);
128
std::cerr << "Local logger 2 hasn't been cleaned up correctly! "
129
"Log::localLoggerRemove() return code is " << retval << std::endl;
134
main(int argc, char* argv[])
136
#if defined(WIN32) && defined(_DEBUG) && defined(LEAK_CHECK)
140
CritLog(<< "logging before initializing is ok");
142
Log::initialize(Log::Cout, Log::Info, argv[0]);
144
InfoLog(<<"Subsystem level for TEST subsystem, not level set, global is info.");
145
Noisy::outputLogMessages();
146
Log::setLevel(Log::Debug, Subsystem::TEST);
147
InfoLog(<<"Subsystem level for TEST subsystem, TEST set to Debug, global is info.");
148
Noisy::outputLogMessages();
149
Log::setLevel(Log::Crit, Subsystem::TEST);
150
InfoLog(<<"Subsystem level for TEST subsystem, TEST set to Crit, global is info.");
151
Noisy::outputLogMessages();
153
DebugLog(<<"This should not appear.");
154
InfoLog(<<"This should appear.");
156
LogThread service1a("service1----A", Log::ThreadSetting(1, Log::Debug));
157
LogThread service1b("service1-------B", Log::ThreadSetting(1, Log::Debug));
158
LogThread service1c("service1---------C", Log::ThreadSetting(1, Log::Debug));
160
LogThread service2a("service2-----------A", Log::ThreadSetting(2, Log::Debug));
161
LogThread service2b("service2------------------B", Log::ThreadSetting(2, Log::Err));
171
InfoLog(<<"Setting service 1 to INFO\n");
172
Log::setServiceLevel(1, Log::Info);
175
InfoLog(<<"Setting service 1 to CRIT\n");
176
Log::setServiceLevel(1, Log::Crit);
179
InfoLog(<<"Setting service 2 to STACK\n");
180
Log::setServiceLevel(2, Log::Stack);
183
InfoLog(<<"Setting service 1 to DEBUG\n");
184
Log::setServiceLevel(1, Log::Debug);
187
DebugLog(<<"This should still not appear.");
188
InfoLog(<<"This should still appear.");
190
InfoLog(<<"Log will now be written to testLoggerOut.txt.");
192
Log::initialize(Log::File, Log::Info, argv[0], "testLoggerOut.txt");
193
InfoLog(<<"This should be in the file");
196
Log::initialize(Log::Cout, Log::Info, argv[0]);
197
InfoLog(<<"This should appear-back to Cout");
200
TestExternalLogger tel;
201
Log::initialize(Log::OnlyExternal, Log::Info, argv[0], tel);
202
InfoLog(<<"This should appear-back in cout through the extenal logger, and nowhere else");
205
service1a.shutdown();
206
service1b.shutdown();
207
service1c.shutdown();
208
service2a.shutdown();
209
service2b.shutdown();
217
Log::initialize(Log::Cout, Log::Info, argv[0]);
218
InfoLog(<<"This should appear-back to Cout");
221
Log::setLevel(Log::Info);
225
UInt64 start = Timer::getTimeMs();
226
for (int i = 0; i < 10000; i++)
228
InfoLog(<< "string");
230
cerr << "Info Took: " << Timer::getTimeMs() - start << endl;
235
UInt64 start = Timer::getTimeMs();
236
for (int i = 0; i < 10000; i++)
238
DebugLog(<< "string");
240
cerr << "Debug Took: " << Timer::getTimeMs() - start << endl;
243
InfoLog(<< "Recursive debug: " << debugLogsInCall());
244
DebugLog(<< "Recursive non-debug OK: " << logsInCall());
246
InfoLog(<< "Recursive non-debug OK!: " << logsInCall());
249
testThreadLocalLoggers(argv[0]);
254
/* ====================================================================
255
* The Vovida Software License, Version 1.0
257
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
259
* Redistribution and use in source and binary forms, with or without
260
* modification, are permitted provided that the following conditions
263
* 1. Redistributions of source code must retain the above copyright
264
* notice, this list of conditions and the following disclaimer.
266
* 2. Redistributions in binary form must reproduce the above copyright
267
* notice, this list of conditions and the following disclaimer in
268
* the documentation and/or other materials provided with the
271
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
272
* and "Vovida Open Communication Application Library (VOCAL)" must
273
* not be used to endorse or promote products derived from this
274
* software without prior written permission. For written
275
* permission, please contact vocal@vovida.org.
277
* 4. Products derived from this software may not be called "VOCAL", nor
278
* may "VOCAL" appear in their name, without prior written
279
* permission of Vovida Networks, Inc.
281
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
282
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
283
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
284
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
285
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
286
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
287
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
288
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
289
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
290
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
291
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
292
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
295
* ====================================================================
297
* This software consists of voluntary contributions made by Vovida
298
* Networks, Inc. and many individuals on behalf of Vovida Networks,
299
* Inc. For more information on Vovida Networks, Inc., please see
300
* <http://www.vovida.org/>.