blob: 19c5cefa648a94c4900acd8656ff82ed14191cea [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>
andrew@webrtc.orgc3e5d342012-11-23 19:30:59 +000014#include <sstream>
andrew@webrtc.org50419b02012-11-14 19:07:54 +000015
16#include "webrtc/common_types.h"
17#include "webrtc/system_wrappers/interface/trace.h"
18
19namespace webrtc {
andrew@webrtc.orgc3e5d342012-11-23 19:30:59 +000020namespace {
andrew@webrtc.org50419b02012-11-14 19:07:54 +000021
andrew@webrtc.orgc3e5d342012-11-23 19:30:59 +000022TraceLevel WebRtcSeverity(LoggingSeverity sev) {
andrew@webrtc.org50419b02012-11-14 19:07:54 +000023 switch (sev) {
24 // TODO(andrew): SENSITIVE doesn't have a corresponding webrtc level.
25 case LS_SENSITIVE: return kTraceInfo;
andrew@webrtc.org655d8f52012-11-20 07:34:45 +000026 case LS_VERBOSE: return kTraceInfo;
27 case LS_INFO: return kTraceTerseInfo;
andrew@webrtc.org50419b02012-11-14 19:07:54 +000028 case LS_WARNING: return kTraceWarning;
29 case LS_ERROR: return kTraceError;
30 default: return kTraceNone;
31 }
32}
33
andrew@webrtc.orgc3e5d342012-11-23 19:30:59 +000034const char* DescribeFile(const char* file) {
35 const char* end1 = ::strrchr(file, '/');
36 const char* end2 = ::strrchr(file, '\\');
37 if (!end1 && !end2)
38 return file;
39 else
40 return (end1 > end2) ? end1 + 1 : end2 + 1;
41}
42
43} // namespace
44
andrew@webrtc.org50419b02012-11-14 19:07:54 +000045LogMessage::LogMessage(const char* file, int line, LoggingSeverity sev)
46 : severity_(sev) {
47 print_stream_ << "(" << DescribeFile(file) << ":" << line << "): ";
48}
49
50LogMessage::~LogMessage() {
51 const std::string& str = print_stream_.str();
52 WEBRTC_TRACE(WebRtcSeverity(severity_), kTraceUndefined, 0, str.c_str());
53}
54
andrew@webrtc.org50419b02012-11-14 19:07:54 +000055} // namespace webrtc