-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrace_to_stderr.cc
47 lines (38 loc) · 1.36 KB
/
trace_to_stderr.cc
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
/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/test/testsupport/trace_to_stderr.h"
#include <cassert>
#include <cstdio>
#include <string>
namespace webrtc {
namespace test {
static const int kLevelFilter = kTraceError | kTraceWarning | kTraceTerseInfo;
TraceToStderr::TraceToStderr() {
Trace::CreateTrace();
Trace::SetTraceCallback(this);
Trace::SetLevelFilter(kLevelFilter);
}
TraceToStderr::~TraceToStderr() {
Trace::SetTraceCallback(NULL);
Trace::ReturnTrace();
}
void TraceToStderr::Print(TraceLevel level, const char* msg_array, int length) {
if (level & kLevelFilter) {
assert(length > Trace::kBoilerplateLength);
std::string msg = msg_array;
std::string msg_time = msg.substr(Trace::kTimestampPosition,
Trace::kTimestampLength);
std::string msg_log = msg.substr(Trace::kBoilerplateLength);
fprintf(stderr, "%s %s\n", msg_time.c_str(), msg_log.c_str());
fflush(stderr);
}
}
} // namespace test
} // namespace webrtc