blob: 693f84460c3a855b0b6b78b6a30c44bf3568ae8f [file] [log] [blame]
Junxiao Shi7d054272016-08-04 17:00:41 +00001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
dmcoomese062a182017-06-12 11:10:31 -05002/*
Davide Pesavento38a061d2018-02-15 22:45:48 -05003 * Copyright (c) 2013-2018 Regents of the University of California.
Junxiao Shi7d054272016-08-04 17:00:41 +00004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
Junxiao Shi1fe7ce52016-08-08 05:48:02 +000021
Junxiao Shi7d054272016-08-04 17:00:41 +000022#include "util/logging.hpp"
23#include "util/logger.hpp"
dmcoomese062a182017-06-12 11:10:31 -050024#include "../unit-test-time-fixture.hpp"
Junxiao Shi7d054272016-08-04 17:00:41 +000025
26#include "boost-test.hpp"
Junxiao Shi7d054272016-08-04 17:00:41 +000027
28namespace ndn {
29namespace util {
30namespace tests {
31
Alexander Afanasyev354f3822017-03-27 15:26:41 -050032NDN_LOG_INIT(ndn.util.tests.Logging);
33
Junxiao Shi7d054272016-08-04 17:00:41 +000034using namespace ndn::tests;
35using boost::test_tools::output_test_stream;
36
37void
38logFromModule1();
39
40void
41logFromModule2();
42
43void
dmcoomese062a182017-06-12 11:10:31 -050044logFromFilterModule();
45
46static void
Junxiao Shi7d054272016-08-04 17:00:41 +000047logFromNewLogger(const std::string& moduleName)
48{
Junxiao Shi7d054272016-08-04 17:00:41 +000049 auto loggerPtr = make_unique<Logger>(moduleName);
50 Logger& logger = *loggerPtr;
51
52 auto getNdnCxxLogger = [&logger] () -> Logger& { return logger; };
Junxiao Shi1fe7ce52016-08-08 05:48:02 +000053 NDN_LOG_TRACE("trace" << moduleName);
54 NDN_LOG_DEBUG("debug" << moduleName);
55 NDN_LOG_INFO("info" << moduleName);
56 NDN_LOG_WARN("warn" << moduleName);
57 NDN_LOG_ERROR("error" << moduleName);
58 NDN_LOG_FATAL("fatal" << moduleName);
Junxiao Shi7d054272016-08-04 17:00:41 +000059
60 BOOST_CHECK(Logging::get().removeLogger(logger));
61}
62
63const time::system_clock::Duration LOG_SYSTIME = time::microseconds(1468108800311239LL);
64const std::string LOG_SYSTIME_STR = "1468108800.311239";
65
66class LoggingFixture : public UnitTestTimeFixture
67{
68protected:
69 explicit
70 LoggingFixture()
dmcoomese062a182017-06-12 11:10:31 -050071 : m_oldEnabledLevel(Logging::get().getLevels())
Junxiao Shi7d054272016-08-04 17:00:41 +000072 , m_oldDestination(Logging::get().getDestination())
73 {
74 this->systemClock->setNow(LOG_SYSTIME);
75 Logging::get().resetLevels();
76 Logging::setDestination(os);
77 }
78
79 ~LoggingFixture()
80 {
dmcoomese062a182017-06-12 11:10:31 -050081 Logging::get().setLevelImpl(m_oldEnabledLevel);
Junxiao Shi7d054272016-08-04 17:00:41 +000082 Logging::setDestination(m_oldDestination);
83 }
84
85protected:
86 output_test_stream os;
87
88private:
dmcoomese062a182017-06-12 11:10:31 -050089 std::unordered_map<std::string, LogLevel> m_oldEnabledLevel;
Junxiao Shi7d054272016-08-04 17:00:41 +000090 shared_ptr<std::ostream> m_oldDestination;
91};
92
93BOOST_AUTO_TEST_SUITE(Util)
94BOOST_FIXTURE_TEST_SUITE(TestLogging, LoggingFixture)
95
Alexander Afanasyev354f3822017-03-27 15:26:41 -050096BOOST_AUTO_TEST_CASE(GetLoggerNames)
97{
98 NDN_LOG_TRACE("GetLoggerNames"); // to avoid unused function warning
99 std::set<std::string> names = Logging::getLoggerNames();
100 BOOST_CHECK_GT(names.size(), 0);
101 BOOST_CHECK_EQUAL(names.count("ndn.util.tests.Logging"), 1);
102}
103
Junxiao Shi7d054272016-08-04 17:00:41 +0000104BOOST_AUTO_TEST_SUITE(Severity)
105
106BOOST_AUTO_TEST_CASE(None)
107{
108 Logging::setLevel("Module1", LogLevel::NONE);
109 logFromModule1();
110
111 Logging::flush();
112 BOOST_CHECK(os.is_equal(
113 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n"
114 ));
115}
116
117BOOST_AUTO_TEST_CASE(Error)
118{
119 Logging::setLevel("Module1", LogLevel::ERROR);
120 logFromModule1();
121
122 Logging::flush();
123 BOOST_CHECK(os.is_equal(
124 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
125 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n"
126 ));
127}
128
129BOOST_AUTO_TEST_CASE(Warn)
130{
131 Logging::setLevel("Module1", LogLevel::WARN);
132 logFromModule1();
133
134 Logging::flush();
135 BOOST_CHECK(os.is_equal(
136 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
137 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
138 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n"
139 ));
140}
141
142BOOST_AUTO_TEST_CASE(Info)
143{
144 Logging::setLevel("Module1", LogLevel::INFO);
145 logFromModule1();
146
147 Logging::flush();
148 BOOST_CHECK(os.is_equal(
149 LOG_SYSTIME_STR + " INFO: [Module1] info1\n" +
150 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
151 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
152 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n"
153 ));
154}
155
156BOOST_AUTO_TEST_CASE(Debug)
157{
158 Logging::setLevel("Module1", LogLevel::DEBUG);
159 logFromModule1();
160
161 Logging::flush();
162 BOOST_CHECK(os.is_equal(
163 LOG_SYSTIME_STR + " DEBUG: [Module1] debug1\n" +
164 LOG_SYSTIME_STR + " INFO: [Module1] info1\n" +
165 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
166 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
167 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n"
168 ));
169}
170
171BOOST_AUTO_TEST_CASE(Trace)
172{
173 Logging::setLevel("Module1", LogLevel::TRACE);
174 logFromModule1();
175
176 Logging::flush();
177 BOOST_CHECK(os.is_equal(
178 LOG_SYSTIME_STR + " TRACE: [Module1] trace1\n" +
179 LOG_SYSTIME_STR + " DEBUG: [Module1] debug1\n" +
180 LOG_SYSTIME_STR + " INFO: [Module1] info1\n" +
181 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
182 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
183 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n"
184 ));
185}
186
187BOOST_AUTO_TEST_CASE(All)
188{
189 Logging::setLevel("Module1", LogLevel::ALL);
190 logFromModule1();
191
192 Logging::flush();
193 BOOST_CHECK(os.is_equal(
194 LOG_SYSTIME_STR + " TRACE: [Module1] trace1\n" +
195 LOG_SYSTIME_STR + " DEBUG: [Module1] debug1\n" +
196 LOG_SYSTIME_STR + " INFO: [Module1] info1\n" +
197 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
198 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
199 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n"
200 ));
201}
202
203BOOST_AUTO_TEST_SUITE_END() // Severity
204
205BOOST_AUTO_TEST_CASE(SameNameLoggers)
206{
207 Logging::setLevel("Module1", LogLevel::WARN);
208 logFromModule1();
209 logFromNewLogger("Module1");
210
211 Logging::flush();
212 BOOST_CHECK(os.is_equal(
213 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
214 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
215 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
216 LOG_SYSTIME_STR + " WARNING: [Module1] warnModule1\n" +
217 LOG_SYSTIME_STR + " ERROR: [Module1] errorModule1\n" +
218 LOG_SYSTIME_STR + " FATAL: [Module1] fatalModule1\n"
219 ));
220}
221
222BOOST_AUTO_TEST_CASE(LateRegistration)
223{
224 BOOST_CHECK_NO_THROW(Logging::setLevel("Module3", LogLevel::DEBUG));
225 logFromNewLogger("Module3");
226
227 Logging::flush();
228 BOOST_CHECK(os.is_equal(
229 LOG_SYSTIME_STR + " DEBUG: [Module3] debugModule3\n" +
230 LOG_SYSTIME_STR + " INFO: [Module3] infoModule3\n" +
231 LOG_SYSTIME_STR + " WARNING: [Module3] warnModule3\n" +
232 LOG_SYSTIME_STR + " ERROR: [Module3] errorModule3\n" +
233 LOG_SYSTIME_STR + " FATAL: [Module3] fatalModule3\n"
234 ));
235}
236
237BOOST_AUTO_TEST_SUITE(DefaultSeverity)
238
239BOOST_AUTO_TEST_CASE(Unset)
240{
241 logFromModule1();
242 logFromModule2();
243
244 Logging::flush();
245 BOOST_CHECK(os.is_equal(
246 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
247 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
248 ));
249}
250
251BOOST_AUTO_TEST_CASE(NoOverride)
252{
253 Logging::setLevel("*", LogLevel::WARN);
254 logFromModule1();
255 logFromModule2();
256
257 Logging::flush();
258 BOOST_CHECK(os.is_equal(
259 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
260 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
261 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
262 LOG_SYSTIME_STR + " WARNING: [Module2] warn2\n" +
263 LOG_SYSTIME_STR + " ERROR: [Module2] error2\n" +
264 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
265 ));
266}
267
268BOOST_AUTO_TEST_CASE(Override)
269{
270 Logging::setLevel("*", LogLevel::WARN);
271 Logging::setLevel("Module2", LogLevel::DEBUG);
272 logFromModule1();
273 logFromModule2();
274
275 Logging::flush();
276 BOOST_CHECK(os.is_equal(
277 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
278 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
279 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
280 LOG_SYSTIME_STR + " DEBUG: [Module2] debug2\n" +
281 LOG_SYSTIME_STR + " INFO: [Module2] info2\n" +
282 LOG_SYSTIME_STR + " WARNING: [Module2] warn2\n" +
283 LOG_SYSTIME_STR + " ERROR: [Module2] error2\n" +
284 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
285 ));
286}
287
288BOOST_AUTO_TEST_SUITE_END() // DefaultSeverity
289
290BOOST_AUTO_TEST_SUITE(SeverityConfig)
291
292BOOST_AUTO_TEST_CASE(SetEmpty)
293{
294 Logging::setLevel("");
dmcoomese062a182017-06-12 11:10:31 -0500295 const auto& prefixMap = Logging::get().getLevels();
296 BOOST_CHECK_EQUAL(prefixMap.size(), 0);
Junxiao Shi7d054272016-08-04 17:00:41 +0000297 logFromModule1();
298 logFromModule2();
299
300 Logging::flush();
301 BOOST_CHECK(os.is_equal(
302 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
303 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
304 ));
305}
306
307BOOST_AUTO_TEST_CASE(SetDefault)
308{
309 Logging::setLevel("*=WARN");
dmcoomese062a182017-06-12 11:10:31 -0500310 const auto& prefixMap = Logging::get().getLevels();
311 // "*" is treated as "" internally
312 BOOST_CHECK_EQUAL(prefixMap.size(), 1);
313 BOOST_CHECK_EQUAL(prefixMap.at(""), LogLevel::WARN);
Junxiao Shi7d054272016-08-04 17:00:41 +0000314 logFromModule1();
315 logFromModule2();
316
317 Logging::flush();
318 BOOST_CHECK(os.is_equal(
319 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
320 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
321 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
322 LOG_SYSTIME_STR + " WARNING: [Module2] warn2\n" +
323 LOG_SYSTIME_STR + " ERROR: [Module2] error2\n" +
324 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
325 ));
326}
327
328BOOST_AUTO_TEST_CASE(SetModule)
329{
330 Logging::setLevel("Module1=ERROR");
dmcoomese062a182017-06-12 11:10:31 -0500331 const auto& prefixMap = Logging::get().getLevels();
332 BOOST_CHECK_EQUAL(prefixMap.size(), 1);
333 BOOST_CHECK_EQUAL(prefixMap.at("Module1"), LogLevel::ERROR);
Junxiao Shi7d054272016-08-04 17:00:41 +0000334 logFromModule1();
335 logFromModule2();
336
337 Logging::flush();
338 BOOST_CHECK(os.is_equal(
339 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
340 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
341 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
342 ));
343}
344
345BOOST_AUTO_TEST_CASE(SetOverride)
346{
347 Logging::setLevel("*=WARN:Module2=DEBUG");
dmcoomese062a182017-06-12 11:10:31 -0500348 const auto& prefixMap = Logging::get().getLevels();
349 BOOST_CHECK_EQUAL(prefixMap.size(), 2);
350 // "*" is treated as "" internally
351 BOOST_CHECK_EQUAL(prefixMap.at(""), LogLevel::WARN);
352 BOOST_CHECK_EQUAL(prefixMap.at("Module2"), LogLevel::DEBUG);
Junxiao Shi7d054272016-08-04 17:00:41 +0000353 logFromModule1();
354 logFromModule2();
355
356 Logging::flush();
357 BOOST_CHECK(os.is_equal(
358 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
359 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
360 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
361 LOG_SYSTIME_STR + " DEBUG: [Module2] debug2\n" +
362 LOG_SYSTIME_STR + " INFO: [Module2] info2\n" +
363 LOG_SYSTIME_STR + " WARNING: [Module2] warn2\n" +
364 LOG_SYSTIME_STR + " ERROR: [Module2] error2\n" +
365 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
366 ));
367}
368
369BOOST_AUTO_TEST_CASE(SetTwice)
370{
371 Logging::setLevel("*=WARN");
372 Logging::setLevel("Module2=DEBUG");
dmcoomese062a182017-06-12 11:10:31 -0500373 const auto& prefixMap = Logging::get().getLevels();
374 BOOST_CHECK_EQUAL(prefixMap.size(), 2);
375 // "*" is treated as "" internally
376 BOOST_CHECK_EQUAL(prefixMap.at(""), LogLevel::WARN);
377 BOOST_CHECK_EQUAL(prefixMap.at("Module2"), LogLevel::DEBUG);
Junxiao Shi7d054272016-08-04 17:00:41 +0000378 logFromModule1();
379 logFromModule2();
380
381 Logging::flush();
382 BOOST_CHECK(os.is_equal(
383 LOG_SYSTIME_STR + " WARNING: [Module1] warn1\n" +
384 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
385 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
386 LOG_SYSTIME_STR + " DEBUG: [Module2] debug2\n" +
387 LOG_SYSTIME_STR + " INFO: [Module2] info2\n" +
388 LOG_SYSTIME_STR + " WARNING: [Module2] warn2\n" +
389 LOG_SYSTIME_STR + " ERROR: [Module2] error2\n" +
390 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
391 ));
392}
393
394BOOST_AUTO_TEST_CASE(Reset)
395{
396 Logging::setLevel("Module2=DEBUG");
397 Logging::setLevel("*=ERROR");
dmcoomese062a182017-06-12 11:10:31 -0500398 const auto& prefixMap = Logging::get().getLevels();
399 BOOST_CHECK_EQUAL(prefixMap.size(), 1);
400 // "*" is treated as "" internally
401 BOOST_CHECK_EQUAL(prefixMap.at(""), LogLevel::ERROR);
Junxiao Shi7d054272016-08-04 17:00:41 +0000402 logFromModule1();
403 logFromModule2();
404
405 Logging::flush();
406 BOOST_CHECK(os.is_equal(
407 LOG_SYSTIME_STR + " ERROR: [Module1] error1\n" +
408 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
409 LOG_SYSTIME_STR + " ERROR: [Module2] error2\n" +
410 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
411 ));
412}
413
414BOOST_AUTO_TEST_CASE(Malformed)
415{
416 BOOST_CHECK_THROW(Logging::setLevel("Module1=INVALID-LEVEL"), std::invalid_argument);
417 BOOST_CHECK_THROW(Logging::setLevel("Module1-MISSING-EQUAL-SIGN"), std::invalid_argument);
418}
419
dmcoomese062a182017-06-12 11:10:31 -0500420BOOST_AUTO_TEST_CASE(SetFilter)
421{
422 Logging::setLevel("*=FATAL:fm.*=DEBUG");
423 const auto& prefixMap = Logging::get().getLevels();
424 BOOST_CHECK_EQUAL(prefixMap.size(), 2);
425 // "*" is treated as "" internally
426 BOOST_CHECK_EQUAL(prefixMap.at(""), LogLevel::FATAL);
427 // "name.*" is treated as "name." internally
428 BOOST_CHECK_EQUAL(prefixMap.at("fm."), LogLevel::DEBUG);
429 logFromModule1();
430 logFromFilterModule();
431
432 Logging::flush();
433 BOOST_CHECK(os.is_equal(
434 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
435 LOG_SYSTIME_STR + " DEBUG: [fm.FilterModule] debugFM\n" +
436 LOG_SYSTIME_STR + " INFO: [fm.FilterModule] infoFM\n" +
437 LOG_SYSTIME_STR + " WARNING: [fm.FilterModule] warnFM\n" +
438 LOG_SYSTIME_STR + " ERROR: [fm.FilterModule] errorFM\n" +
439 LOG_SYSTIME_STR + " FATAL: [fm.FilterModule] fatalFM\n"
440 ));
441}
442
443BOOST_AUTO_TEST_CASE(SetOverrideFilter)
444{
445 Logging::setLevel("*=FATAL:fm.FilterModule=DEBUG");
446 Logging::setLevel("fm.*", LogLevel::INFO);
447 const auto& prefixMap = Logging::get().getLevels();
448 BOOST_CHECK_EQUAL(prefixMap.size(), 2);
449 // "*" is treated as "" internally
450 BOOST_CHECK_EQUAL(prefixMap.at(""), LogLevel::FATAL);
451 // "name.*" is treated as "name." internally
452 BOOST_CHECK_EQUAL(prefixMap.at("fm."), LogLevel::INFO);
453 logFromModule1();
454 logFromFilterModule();
455
456 Logging::flush();
457 BOOST_CHECK(os.is_equal(
458 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n" +
459 LOG_SYSTIME_STR + " INFO: [fm.FilterModule] infoFM\n" +
460 LOG_SYSTIME_STR + " WARNING: [fm.FilterModule] warnFM\n" +
461 LOG_SYSTIME_STR + " ERROR: [fm.FilterModule] errorFM\n" +
462 LOG_SYSTIME_STR + " FATAL: [fm.FilterModule] fatalFM\n"
463 ));
464}
465
466BOOST_AUTO_TEST_CASE(FindPrefixRule)
467{
468 Logging::setLevel("*=FATAL:fm.a.*=ERROR:fm.a.b=INFO");
469 logFromNewLogger("fm.a.b");
470 logFromNewLogger("fm.a.b.c");
471 logFromNewLogger("fm.a.b.d");
472 logFromNewLogger("fm.b");
473
474 Logging::flush();
475 BOOST_CHECK(os.is_equal(
476 LOG_SYSTIME_STR + " INFO: [fm.a.b] infofm.a.b\n" +
477 LOG_SYSTIME_STR + " WARNING: [fm.a.b] warnfm.a.b\n" +
478 LOG_SYSTIME_STR + " ERROR: [fm.a.b] errorfm.a.b\n" +
479 LOG_SYSTIME_STR + " FATAL: [fm.a.b] fatalfm.a.b\n" +
480 LOG_SYSTIME_STR + " ERROR: [fm.a.b.c] errorfm.a.b.c\n" +
481 LOG_SYSTIME_STR + " FATAL: [fm.a.b.c] fatalfm.a.b.c\n" +
482 LOG_SYSTIME_STR + " ERROR: [fm.a.b.d] errorfm.a.b.d\n" +
483 LOG_SYSTIME_STR + " FATAL: [fm.a.b.d] fatalfm.a.b.d\n" +
484 LOG_SYSTIME_STR + " FATAL: [fm.b] fatalfm.b\n"
485 ));
486}
487
Junxiao Shi7d054272016-08-04 17:00:41 +0000488BOOST_AUTO_TEST_SUITE_END() // SeverityConfig
489
490BOOST_AUTO_TEST_CASE(ChangeDestination)
491{
492 logFromModule1();
493
494 auto os2 = make_shared<output_test_stream>();
495 Logging::setDestination(os2);
496 weak_ptr<output_test_stream> os2weak(os2);
497 os2.reset();
498
499 logFromModule2();
500
501 Logging::flush();
502 os2 = os2weak.lock();
503 BOOST_REQUIRE(os2 != nullptr);
504
505 BOOST_CHECK(os.is_equal(
506 LOG_SYSTIME_STR + " FATAL: [Module1] fatal1\n"
507 ));
508 BOOST_CHECK(os2->is_equal(
509 LOG_SYSTIME_STR + " FATAL: [Module2] fatal2\n"
510 ));
511
512 os2.reset();
513 Logging::setDestination(os);
514 BOOST_CHECK(os2weak.expired());
515}
516
517BOOST_AUTO_TEST_SUITE_END() // TestLogging
518BOOST_AUTO_TEST_SUITE_END() // Util
519
520} // namespace tests
521} // namespace util
522} // namespace ndn