blob: 16804d95f915410b150e281f15273d3f4bb3155a [file] [log] [blame]
andrew@webrtc.org50419b02012-11-14 19:07:54 +00001/*
2 * Copyright (c) 2012 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/system_wrappers/interface/logging.h"
12
13#include <string.h>
14#include <iostream>
15
16#include "webrtc/common_types.h"
17#include "webrtc/system_wrappers/interface/trace.h"
18
19namespace webrtc {
20
21static TraceLevel WebRtcSeverity(LoggingSeverity sev) {
22 switch (sev) {
23 // TODO(andrew): SENSITIVE doesn't have a corresponding webrtc level.
24 case LS_SENSITIVE: return kTraceInfo;
25 case LS_VERBOSE: return kTraceDebug;
26 case LS_INFO: return kTraceInfo;
27 case LS_WARNING: return kTraceWarning;
28 case LS_ERROR: return kTraceError;
29 default: return kTraceNone;
30 }
31}
32
33LogMessage::LogMessage(const char* file, int line, LoggingSeverity sev)
34 : severity_(sev) {
35 print_stream_ << "(" << DescribeFile(file) << ":" << line << "): ";
36}
37
38LogMessage::~LogMessage() {
39 const std::string& str = print_stream_.str();
40 WEBRTC_TRACE(WebRtcSeverity(severity_), kTraceUndefined, 0, str.c_str());
41}
42
43const char* LogMessage::DescribeFile(const char* file) {
44 const char* end1 = ::strrchr(file, '/');
45 const char* end2 = ::strrchr(file, '\\');
46 if (!end1 && !end2)
47 return file;
48 else
49 return (end1 > end2) ? end1 + 1 : end2 + 1;
50}
51
52} // namespace webrtc