andrew@webrtc.org | b87cc85 | 2013-03-25 16:23:37 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/test/testsupport/trace_to_stderr.h" |
| 12 | |
| 13 | #include <cassert> |
| 14 | #include <cstdio> |
| 15 | |
| 16 | #include <string> |
| 17 | |
| 18 | namespace webrtc { |
| 19 | namespace test { |
| 20 | |
| 21 | static const int kLevelFilter = kTraceError | kTraceWarning | kTraceTerseInfo; |
| 22 | |
| 23 | TraceToStderr::TraceToStderr() { |
| 24 | Trace::CreateTrace(); |
| 25 | Trace::SetTraceCallback(this); |
| 26 | Trace::SetLevelFilter(kLevelFilter); |
| 27 | } |
| 28 | |
| 29 | TraceToStderr::~TraceToStderr() { |
| 30 | Trace::SetTraceCallback(NULL); |
| 31 | Trace::ReturnTrace(); |
| 32 | } |
| 33 | |
| 34 | void TraceToStderr::Print(TraceLevel level, const char* msg_array, int length) { |
| 35 | if (level & kLevelFilter) { |
| 36 | assert(length > Trace::kBoilerplateLength); |
| 37 | std::string msg = msg_array; |
| 38 | std::string msg_time = msg.substr(Trace::kTimestampPosition, |
| 39 | Trace::kTimestampLength); |
| 40 | std::string msg_log = msg.substr(Trace::kBoilerplateLength); |
| 41 | fprintf(stderr, "%s %s\n", msg_time.c_str(), msg_log.c_str()); |
| 42 | fflush(stderr); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | } // namespace test |
| 47 | } // namespace webrtc |