1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
/* Copyright 2013 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, the copyright holders give permission to link the
* code of portions of this program with the OpenSSL library under certain
* conditions as described in each individual source file and distribute
* linked combinations including the program with the OpenSSL library. You
* must comply with the GNU Affero General Public License in all respects
* for all of the code used other than as permitted herein. If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. If you do not
* wish to do so, delete this exception statement from your version. If you
* delete this exception statement from all source files in the program,
* then also delete it in the license file.
*/
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
#include "mongo/platform/basic.h"
#include "mongo/logger/log_test.h"
#include <sstream>
#include <string>
#include <vector>
#include "mongo/logger/appender.h"
#include "mongo/logger/encoder.h"
#include "mongo/logger/log_component.h"
#include "mongo/logger/log_component_settings.h"
#include "mongo/logger/message_event_utf8_encoder.h"
#include "mongo/logger/message_log_domain.h"
#include "mongo/logger/rotatable_file_appender.h"
#include "mongo/logger/rotatable_file_writer.h"
#include "mongo/platform/compiler.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/concurrency/thread_name.h"
#include "mongo/util/log.h"
#include "mongo/util/mongoutils/str.h"
using namespace mongo::logger;
namespace mongo {
namespace {
typedef LogTest<MessageEventDetailsEncoder> LogTestDetailsEncoder;
typedef LogTest<MessageEventUnadornedEncoder> LogTestUnadornedEncoder;
TEST_F(LogTestUnadornedEncoder, logContext) {
logContext("WHA!");
ASSERT_GREATER_THAN(_logLines.size(), 1U);
ASSERT_NOT_EQUALS(_logLines[0].find("WHA!"), std::string::npos);
// TODO(schwerin): Ensure that logContext rights a proper context to the log stream,
// including the address of the logContext() function.
// void const* logContextFn = reinterpret_cast<void const*>(logContext);
}
class CountAppender : public Appender<MessageEventEphemeral> {
public:
CountAppender() : _count(0) {}
virtual ~CountAppender() {}
virtual Status append(const MessageEventEphemeral& event) {
++_count;
return Status::OK();
}
int getCount() {
return _count;
}
private:
int _count;
};
/** Simple tests for detaching appenders. */
TEST_F(LogTestUnadornedEncoder, DetachAppender) {
MessageLogDomain::AppenderAutoPtr countAppender(new CountAppender);
MessageLogDomain domain;
// Appending to the domain before attaching the appender does not affect the appender.
domain.append(MessageEventEphemeral(Date_t(), LogSeverity::Log(), "", "1"));
ASSERT_EQUALS(0, dynamic_cast<CountAppender*>(countAppender.get())->getCount());
// Appending to the domain after attaching the appender does affect the appender.
MessageLogDomain::AppenderHandle handle = domain.attachAppender(std::move(countAppender));
domain.append(MessageEventEphemeral(Date_t(), LogSeverity::Log(), "", "2"));
countAppender = domain.detachAppender(handle);
ASSERT_EQUALS(1, dynamic_cast<CountAppender*>(countAppender.get())->getCount());
// Appending to the domain after detaching the appender does not affect the appender.
domain.append(MessageEventEphemeral(Date_t(), LogSeverity::Log(), "", "3"));
ASSERT_EQUALS(1, dynamic_cast<CountAppender*>(countAppender.get())->getCount());
}
class A {
public:
std::string toString() const {
log() << "Golly!\n";
return "Golly!";
}
};
// Tests that logging while in the midst of logging produces two distinct log messages, with the
// inner log message appearing before the outer.
TEST_F(LogTestUnadornedEncoder, LogstreamBuilderReentrance) {
log() << "Logging A() -- " << A() << " -- done!" << std::endl;
ASSERT_EQUALS(2U, _logLines.size());
ASSERT_EQUALS(std::string("Golly!\n"), _logLines[0]);
ASSERT_EQUALS(std::string("Logging A() -- Golly! -- done!\n"), _logLines[1]);
}
//
// Instantiating this object is a basic test of static-initializer-time logging.
//
class B {
public:
B() {
log() << "Exercising initializer time logging.";
}
} b;
// Constants for log component test cases.
const LogComponent componentDefault = LogComponent::kDefault;
const LogComponent componentA = LogComponent::kCommand;
const LogComponent componentB = LogComponent::kAccessControl;
const LogComponent componentC = LogComponent::kNetwork;
const LogComponent componentD = LogComponent::kStorage;
const LogComponent componentE = LogComponent::kJournal;
// No log component declared at file scope.
// Component severity configuration:
// LogComponent::kDefault: 2
TEST_F(LogTestUnadornedEncoder, MongoLogMacroNoFileScopeLogComponent) {
globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Debug(2));
LOG(2) << "This is logged";
LOG(3) << "This is not logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]);
// MONGO_LOG_COMPONENT
_logLines.clear();
MONGO_LOG_COMPONENT(2, componentA) << "This is logged";
MONGO_LOG_COMPONENT(3, componentA) << "This is not logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]);
// MONGO_LOG_COMPONENT2
_logLines.clear();
MONGO_LOG_COMPONENT2(2, componentA, componentB) << "This is logged";
MONGO_LOG_COMPONENT2(3, componentA, componentB) << "This is not logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]);
// MONGO_LOG_COMPONENT3
_logLines.clear();
MONGO_LOG_COMPONENT3(2, componentA, componentB, componentC) << "This is logged";
MONGO_LOG_COMPONENT3(3, componentA, componentB, componentC) << "This is not logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_EQUALS(std::string("This is logged\n"), _logLines[0]);
}
//
// Component log level tests.
// The global log manager holds the component log level configuration for the global log domain.
// LOG() and MONGO_LOG_COMPONENT() macros in util/log.h determine at runtime if a log message
// should be written to the log domain.
//
TEST_F(LogTestUnadornedEncoder, LogComponentSettingsMinimumLogSeverity) {
LogComponentSettings settings;
ASSERT_TRUE(settings.hasMinimumLogSeverity(LogComponent::kDefault));
ASSERT_TRUE(settings.getMinimumLogSeverity(LogComponent::kDefault) == LogSeverity::Log());
for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) {
LogComponent component = static_cast<LogComponent::Value>(i);
if (component == LogComponent::kDefault) {
continue;
}
ASSERT_FALSE(settings.hasMinimumLogSeverity(component));
}
// Override and clear minimum severity level.
for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) {
LogComponent component = static_cast<LogComponent::Value>(i);
LogSeverity severity = LogSeverity::Debug(2);
// Override severity level.
settings.setMinimumLoggedSeverity(component, severity);
ASSERT_TRUE(settings.hasMinimumLogSeverity(component));
ASSERT_TRUE(settings.getMinimumLogSeverity(component) == severity);
// Clear severity level.
// Special case: when clearing LogComponent::kDefault, the corresponding
// severity level is set to default values (ie. Log()).
settings.clearMinimumLoggedSeverity(component);
if (component == LogComponent::kDefault) {
ASSERT_TRUE(settings.hasMinimumLogSeverity(component));
ASSERT_TRUE(settings.getMinimumLogSeverity(LogComponent::kDefault) ==
LogSeverity::Log());
} else {
ASSERT_FALSE(settings.hasMinimumLogSeverity(component));
}
}
}
// Test for shouldLog() when the minimum logged severity is set only for LogComponent::kDefault.
TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogDefaultLogComponentOnly) {
LogComponentSettings settings;
// Initial log severity for LogComponent::kDefault is Log().
ASSERT_TRUE(shouldLog(LogSeverity::Info()));
ASSERT_TRUE(shouldLog(LogSeverity::Log()));
ASSERT_FALSE(shouldLog(LogSeverity::Debug(1)));
ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));
// If any components are provided to shouldLog(), we should get the same outcome
// because we have not configured any non-LogComponent::kDefault components.
ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Log()));
ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(1)));
// Set minimum logged severity so that Debug(1) messages are written to log domain.
settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
LogSeverity::Debug(1));
ASSERT_TRUE(shouldLog(LogSeverity::Info()));
ASSERT_TRUE(shouldLog(LogSeverity::Log()));
ASSERT_TRUE(shouldLog(LogSeverity::Debug(1)));
ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));
// Revert back.
logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Log());
// Same results when components are supplied to shouldLog().
ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(1)));
ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(2)));
}
// Test for shouldLog() when we have configured a single component.
// Also checks that severity level has been reverted to match LogComponent::kDefault
// after clearing level.
// Minimum severity levels:
// LogComponent::kDefault: 1
// componentA: 2
TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogSingleComponent) {
LogComponentSettings settings;
settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
settings.setMinimumLoggedSeverity(componentA, LogSeverity::Debug(2));
// Components for log message: componentA only.
ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(2)));
ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(3)));
// Clear severity level for componentA and check shouldLog() again.
settings.clearMinimumLoggedSeverity(componentA);
ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(1)));
ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(2)));
// Test shouldLog() with global settings.
logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
LogSeverity::Debug(1));
// Components for log message: LogComponent::kDefault only.
ASSERT_TRUE(shouldLog(LogSeverity::Debug(1)));
ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));
logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Log());
}
// Test for shouldLog() when we have configured multiple components.
// Minimum severity levels:
// LogComponent::kDefault: 1
// componentA: 2
// componentB: 0
TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogMultipleComponentsConfigured) {
LogComponentSettings settings;
settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
settings.setMinimumLoggedSeverity(componentA, LogSeverity::Debug(2));
settings.setMinimumLoggedSeverity(componentB, LogSeverity::Log());
// Components for log message: componentA only.
ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(2)));
ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(3)));
// Components for log message: componentB only.
ASSERT_TRUE(settings.shouldLog(componentB, LogSeverity::Log()));
ASSERT_FALSE(settings.shouldLog(componentB, LogSeverity::Debug(1)));
// Components for log message: componentC only.
// Since a component-specific minimum severity is not configured for componentC,
// shouldLog() falls back on LogComponent::kDefault.
ASSERT_TRUE(settings.shouldLog(componentC, LogSeverity::Debug(1)));
ASSERT_FALSE(settings.shouldLog(componentC, LogSeverity::Debug(2)));
// Test shouldLog() with global settings.
logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
LogSeverity::Debug(1));
// Components for log message: LogComponent::kDefault only.
ASSERT_TRUE(shouldLog(LogSeverity::Debug(1)));
ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));
logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Log());
}
// Log component hierarchy.
TEST_F(LogTestUnadornedEncoder, LogComponentHierarchy) {
// Parent component is not meaningful for kDefault and kNumLogComponents.
ASSERT_EQUALS(LogComponent::kNumLogComponents, LogComponent(LogComponent::kDefault).parent());
ASSERT_EQUALS(LogComponent::kNumLogComponents,
LogComponent(LogComponent::kNumLogComponents).parent());
// Default -> ComponentD -> ComponentE
ASSERT_EQUALS(LogComponent::kDefault, LogComponent(componentD).parent());
ASSERT_EQUALS(componentD, LogComponent(componentE).parent());
ASSERT_NOT_EQUALS(LogComponent::kDefault, LogComponent(componentE).parent());
// Log components should inherit parent's log severity in settings.
LogComponentSettings settings;
settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
settings.setMinimumLoggedSeverity(componentD, LogSeverity::Debug(2));
// componentE should inherit componentD's log severity.
ASSERT_TRUE(settings.shouldLog(componentE, LogSeverity::Debug(2)));
ASSERT_FALSE(settings.shouldLog(componentE, LogSeverity::Debug(3)));
// Clearing parent's log severity - componentE should inherit from Default.
settings.clearMinimumLoggedSeverity(componentD);
ASSERT_TRUE(settings.shouldLog(componentE, LogSeverity::Debug(1)));
ASSERT_FALSE(settings.shouldLog(componentE, LogSeverity::Debug(2)));
}
// Dotted name of component includes names of ancestors.
TEST_F(LogTestUnadornedEncoder, LogComponentDottedName) {
// Default -> ComponentD -> ComponentE
ASSERT_EQUALS(componentDefault.getShortName(),
LogComponent(LogComponent::kDefault).getDottedName());
ASSERT_EQUALS(componentD.getShortName(), componentD.getDottedName());
ASSERT_EQUALS(componentD.getShortName() + "." + componentE.getShortName(),
componentE.getDottedName());
}
// Log names of all components should have the same length.
TEST_F(LogTestUnadornedEncoder, LogComponentNameForLog) {
size_t defaultNameForLogLength = componentDefault.getNameForLog().toString().length();
ASSERT_NOT_EQUALS(0U, defaultNameForLogLength);
for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) {
LogComponent component = static_cast<LogComponent::Value>(i);
ASSERT_EQUALS(defaultNameForLogLength, component.getNameForLog().toString().length());
}
}
/**
* Verifies that the encoded log line contains string.
*/
void testEncodedLogLine(const MessageEventEphemeral& event, const std::string& expectedSubstring) {
MessageEventDetailsEncoder encoder;
std::ostringstream os;
ASSERT_TRUE(encoder.encode(event, os));
std::string s = os.str();
if (s.find(expectedSubstring) == std::string::npos) {
FAIL(str::stream() << "encoded log line does not contain substring \"" << expectedSubstring
<< "\". log line: " << s);
}
}
// Log severity should always be logged as a single capital letter.
TEST_F(LogTestUnadornedEncoder, MessageEventDetailsEncoderLogSeverity) {
Date_t d = Date_t::now();
StringData ctx("WHAT", StringData::LiteralTag());
StringData msg("HUH", StringData::LiteralTag());
// Severe is indicated by (F)atal.
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Severe(), ctx, msg), " F ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Error(), ctx, msg), " E ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Warning(), ctx, msg), " W ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Info(), ctx, msg), " I ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Log(), ctx, msg), " I ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(0), ctx, msg), " I ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(1), ctx, msg), " D ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(2), ctx, msg), " D ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(3), ctx, msg), " D ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(4), ctx, msg), " D ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(5), ctx, msg), " D ");
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Debug(100), ctx, msg), " D ");
// Unknown severity.
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Severe().moreSevere(), ctx, msg),
" U ");
}
// Non-default log component short name should always be logged.
TEST_F(LogTestUnadornedEncoder, MessageEventDetailsEncoderLogComponent) {
Date_t d = Date_t::now();
StringData ctx("WHAT", StringData::LiteralTag());
StringData msg("HUH", StringData::LiteralTag());
for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) {
LogComponent component = static_cast<LogComponent::Value>(i);
testEncodedLogLine(MessageEventEphemeral(d, LogSeverity::Info(), component, ctx, msg),
str::stream() << " I " << component.getNameForLog() << " [");
}
}
// Tests pass through of log component:
// log macros -> LogStreamBuilder -> MessageEventEphemeral -> MessageEventDetailsEncoder
TEST_F(LogTestDetailsEncoder, ) {
globalLogDomain()->setMinimumLoggedSeverity(LogSeverity::Log());
// Default log component short name should not appear in detailed log line.
MONGO_LOG_COMPONENT(0, componentDefault) << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(componentDefault.getNameForLog().toString()),
std::string::npos);
// Non-default log component short name should appear in detailed log line.
_logLines.clear();
MONGO_LOG_COMPONENT(0, componentA) << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()), std::string::npos);
// MONGO_LOG_COMPONENT2 - only the first component is sent to LogStreamBuilder.
_logLines.clear();
MONGO_LOG_COMPONENT2(0, componentA, componentB) << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()), std::string::npos);
ASSERT_EQUALS(_logLines[0].find(componentB.getNameForLog().toString()), std::string::npos);
// MONGO_LOG_COMPONENT3 - only the first component is sent to LogStreamBuilder.
_logLines.clear();
MONGO_LOG_COMPONENT3(0, componentA, componentB, componentC) << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(componentA.getNameForLog().toString()), std::string::npos);
ASSERT_EQUALS(_logLines[0].find(componentB.getNameForLog().toString()), std::string::npos);
ASSERT_EQUALS(_logLines[0].find(componentC.getNameForLog().toString()), std::string::npos);
}
// Tests pass through of log component:
// unconditional log functions -> LogStreamBuilder -> MessageEventEphemeral
// -> MessageEventDetailsEncoder
TEST_F(LogTestDetailsEncoder, LogFunctions) {
// severe() - no component specified.
severe() << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " F " << componentDefault.getNameForLog()),
std::string::npos);
// severe() - with component.
_logLines.clear();
severe(componentA) << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " F " << componentA.getNameForLog()),
std::string::npos);
// error() - no component specified.
_logLines.clear();
error() << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " E " << componentDefault.getNameForLog()),
std::string::npos);
// error() - with component.
_logLines.clear();
error(componentA) << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " E " << componentA.getNameForLog()),
std::string::npos);
// warning() - no component specified.
_logLines.clear();
warning() << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " W " << componentDefault.getNameForLog()),
std::string::npos);
// warning() - with component.
_logLines.clear();
warning(componentA) << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " W " << componentA.getNameForLog()),
std::string::npos);
// log() - no component specified.
_logLines.clear();
log() << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " I " << componentDefault.getNameForLog()),
std::string::npos);
// log() - with component.
_logLines.clear();
log(componentA) << "This is logged";
ASSERT_EQUALS(1U, _logLines.size());
ASSERT_NOT_EQUALS(_logLines[0].find(str::stream() << " I " << componentA.getNameForLog()),
std::string::npos);
}
} // namespace
} // namespace mongo
|