/[resiprocate]/main/resip/stack/test/testExternalLogger.cxx
ViewVC logotype

Contents of /main/resip/stack/test/testExternalLogger.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8161 - (show annotations) (download)
Fri Jul 25 20:54:42 2008 UTC (11 years, 3 months ago) by jmatthewsr
File MIME type: text/plain
File size: 6274 byte(s)
Stream performance enhancements for encoding objects.  New encoding code should use 'EncodeStream','resipCerr' and 'resipCout' for encoding any resip objects.  Merge from b-jmatthewsr-streamperf2 -r 8137:8160.  
1 #include "rutil/Logger.hxx"
2 #include "rutil/Data.hxx"
3 #include "rutil/ThreadIf.hxx"
4 #include "rutil/Timer.hxx"
5
6 using namespace resip;
7 using namespace std;
8
9 #ifdef WIN32
10 #define usleep(x) Sleep(x/1000)
11 #define sleep(x) Sleep(x*1000)
12 #endif
13
14 #define RESIPROCATE_SUBSYSTEM Subsystem::SIP
15
16
17 class LogThread : public ThreadIf
18 {
19 public:
20 LogThread(const Data& description, const Log::ThreadSetting& s)
21 : mDescription(description),
22 mSetting(s)
23 {}
24
25 void thread()
26 {
27 #ifdef LOG_ENABLE_THREAD_SETTING
28 Log::setThreadSetting(mSetting);
29 #endif
30 while(!waitForShutdown(100))
31 {
32 DebugLog(<< mDescription << " DEBUG");
33 InfoLog(<< mDescription << " INFO");
34 }
35 }
36 private:
37 Data mDescription;
38 Log::ThreadSetting mSetting;
39 };
40
41 int logsInCall()
42 {
43 InfoLog(<< "Got here?");
44 return 17;
45 }
46
47
48 int debugLogsInCall()
49 {
50 DebugLog(<< "Got here?");
51 return 17;
52 }
53
54 class ExampleExternalLogger : public ExternalLogger
55 {
56 virtual bool operator()(Log::Level level,
57 const Subsystem& subsystem,
58 const Data& appName,
59 const char* file,
60 int line,
61 const Data& message,
62 const Data& messageWithHeaders)
63 {
64 resipCerr << "ExampleExternalLogger " << level << " $ "
65 << subsystem << " $ "
66 << appName << " $ "
67 << file << ":" << line
68 << " $ "
69 << message << std::endl;
70
71 // supress normal logging
72 return false;
73 }
74 };
75
76 int
77 main(int argc, char* argv[])
78 {
79 ExampleExternalLogger exampleExternalLogger;
80 Log::initialize(Log::Syslog, Log::Info, argv[0], exampleExternalLogger);
81
82 DebugLog(<<"This should not appear.");
83 InfoLog(<<"This should appear.");
84
85 LogThread service1a("service1----A", Log::ThreadSetting(1, Log::Debug));
86 LogThread service1b("service1-------B", Log::ThreadSetting(1, Log::Debug));
87 LogThread service1c("service1---------C", Log::ThreadSetting(1, Log::Debug));
88
89 LogThread service2a("service2-----------A", Log::ThreadSetting(2, Log::Debug));
90 LogThread service2b("service2------------------B", Log::ThreadSetting(2, Log::Err));
91
92 service1a.run();
93 service1b.run();
94 service1c.run();
95 service2a.run();
96 service2b.run();
97
98 #if !defined(WIN32) && !defined(TARGET_OS_MAC)
99 sleep(2);
100
101 InfoLog(<<"Setting service 1 to INFO\n");
102 Log::setServiceLevel(1, Log::Info);
103 sleep(2);
104
105 InfoLog(<<"Setting service 1 to CRIT\n");
106 Log::setServiceLevel(1, Log::Crit);
107 sleep(2);
108
109 InfoLog(<<"Setting service 2 to STACK\n");
110 Log::setServiceLevel(2, Log::Stack);
111 sleep(2);
112
113 InfoLog(<<"Setting service 1 to DEBUG\n");
114 Log::setServiceLevel(1, Log::Debug);
115 sleep(2);
116 #endif
117
118 DebugLog(<<"This should still not appear.");
119 InfoLog(<<"This should still appear.");
120
121 service1a.shutdown();
122 service1b.shutdown();
123 service1c.shutdown();
124 service2a.shutdown();
125 service2b.shutdown();
126
127 service1a.join();
128 service1b.join();
129 service1c.join();
130 service2a.join();
131 service2b.join();
132
133 Log::setLevel(Log::Info);
134
135 if (false)
136 {
137 UInt64 start = Timer::getTimeMs();
138 for (int i = 0; i < 10000; i++)
139 {
140 InfoLog(<< "string");
141 }
142 cerr << "Info Took: " << Timer::getTimeMs() - start << endl;
143 }
144
145 if (false)
146 {
147 UInt64 start = Timer::getTimeMs();
148 for (int i = 0; i < 10000; i++)
149 {
150 DebugLog(<< "string");
151 }
152 cerr << "Debug Took: " << Timer::getTimeMs() - start << endl;
153 }
154
155 InfoLog(<< "Recursive debug: " << debugLogsInCall());
156 DebugLog(<< "Recursive non-debug OK: " << logsInCall());
157
158 InfoLog(<< "Recursive non-debug OK!: " << logsInCall());
159 return 0;
160 }
161
162 /* ====================================================================
163 * The Vovida Software License, Version 1.0
164 *
165 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
166 *
167 * Redistribution and use in source and binary forms, with or without
168 * modification, are permitted provided that the following conditions
169 * are met:
170 *
171 * 1. Redistributions of source code must retain the above copyright
172 * notice, this list of conditions and the following disclaimer.
173 *
174 * 2. Redistributions in binary form must reproduce the above copyright
175 * notice, this list of conditions and the following disclaimer in
176 * the documentation and/or other materials provided with the
177 * distribution.
178 *
179 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
180 * and "Vovida Open Communication Application Library (VOCAL)" must
181 * not be used to endorse or promote products derived from this
182 * software without prior written permission. For written
183 * permission, please contact vocal@vovida.org.
184 *
185 * 4. Products derived from this software may not be called "VOCAL", nor
186 * may "VOCAL" appear in their name, without prior written
187 * permission of Vovida Networks, Inc.
188 *
189 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
190 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
191 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
192 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
193 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
194 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
195 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
196 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
197 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
198 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
199 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
200 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
201 * DAMAGE.
202 *
203 * ====================================================================
204 *
205 * This software consists of voluntary contributions made by Vovida
206 * Networks, Inc. and many individuals on behalf of Vovida Networks,
207 * Inc. For more information on Vovida Networks, Inc., please see
208 * <http://www.vovida.org/>.
209 *
210 */
211

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27