andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 1 | /* |
| 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.org | c3e5d34 | 2012-11-23 19:30:59 +0000 | [diff] [blame] | 14 | #include <sstream> |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 15 | |
| 16 | #include "webrtc/common_types.h" |
| 17 | #include "webrtc/system_wrappers/interface/trace.h" |
| 18 | |
| 19 | namespace webrtc { |
andrew@webrtc.org | c3e5d34 | 2012-11-23 19:30:59 +0000 | [diff] [blame] | 20 | namespace { |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 21 | |
andrew@webrtc.org | c3e5d34 | 2012-11-23 19:30:59 +0000 | [diff] [blame] | 22 | TraceLevel WebRtcSeverity(LoggingSeverity sev) { |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 23 | switch (sev) { |
| 24 | // TODO(andrew): SENSITIVE doesn't have a corresponding webrtc level. |
| 25 | case LS_SENSITIVE: return kTraceInfo; |
andrew@webrtc.org | 655d8f5 | 2012-11-20 07:34:45 +0000 | [diff] [blame] | 26 | case LS_VERBOSE: return kTraceInfo; |
| 27 | case LS_INFO: return kTraceTerseInfo; |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 28 | case LS_WARNING: return kTraceWarning; |
| 29 | case LS_ERROR: return kTraceError; |
| 30 | default: return kTraceNone; |
| 31 | } |
| 32 | } |
| 33 | |
andrew@webrtc.org | c3e5d34 | 2012-11-23 19:30:59 +0000 | [diff] [blame] | 34 | const 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.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 45 | LogMessage::LogMessage(const char* file, int line, LoggingSeverity sev) |
| 46 | : severity_(sev) { |
| 47 | print_stream_ << "(" << DescribeFile(file) << ":" << line << "): "; |
| 48 | } |
| 49 | |
| 50 | LogMessage::~LogMessage() { |
| 51 | const std::string& str = print_stream_.str(); |
| 52 | WEBRTC_TRACE(WebRtcSeverity(severity_), kTraceUndefined, 0, str.c_str()); |
| 53 | } |
| 54 | |
andrew@webrtc.org | 50419b0 | 2012-11-14 19:07:54 +0000 | [diff] [blame] | 55 | } // namespace webrtc |