tkchin | 42f580e | 2015-11-26 23:18:23 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | #import <Foundation/Foundation.h> |
| 12 | |
| 13 | // Subset of rtc::LoggingSeverity. |
| 14 | typedef NS_ENUM(NSInteger, RTCLoggingSeverity) { |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 15 | RTCLoggingSeverityVerbose, |
| 16 | RTCLoggingSeverityInfo, |
| 17 | RTCLoggingSeverityWarning, |
| 18 | RTCLoggingSeverityError, |
tkchin | 42f580e | 2015-11-26 23:18:23 -0800 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | #if defined(__cplusplus) |
| 22 | extern "C" void RTCLogEx(RTCLoggingSeverity severity, NSString* log_string); |
| 23 | extern "C" void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity); |
| 24 | extern "C" NSString* RTCFileName(const char* filePath); |
| 25 | #else |
| 26 | |
| 27 | // Wrapper for C++ LOG(sev) macros. |
| 28 | // Logs the log string to the webrtc logstream for the given severity. |
| 29 | extern void RTCLogEx(RTCLoggingSeverity severity, NSString* log_string); |
| 30 | |
| 31 | // Wrapper for rtc::LogMessage::LogToDebug. |
| 32 | // Sets the minimum severity to be logged to console. |
| 33 | extern void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity); |
| 34 | |
| 35 | // Returns the filename with the path prefix removed. |
| 36 | extern NSString* RTCFileName(const char* filePath); |
| 37 | |
| 38 | #endif |
| 39 | |
| 40 | // Some convenience macros. |
| 41 | |
| 42 | #define RTCLogString(format, ...) \ |
| 43 | [NSString stringWithFormat:@"(%@:%d %s): " format, \ |
| 44 | RTCFileName(__FILE__), \ |
| 45 | __LINE__, \ |
| 46 | __FUNCTION__, \ |
| 47 | ##__VA_ARGS__] |
| 48 | |
| 49 | #define RTCLogFormat(severity, format, ...) \ |
| 50 | do { \ |
| 51 | NSString* log_string = RTCLogString(format, ##__VA_ARGS__); \ |
| 52 | RTCLogEx(severity, log_string); \ |
| 53 | } while (false) |
| 54 | |
| 55 | #define RTCLogVerbose(format, ...) \ |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 56 | RTCLogFormat(RTCLoggingSeverityVerbose, format, ##__VA_ARGS__) \ |
tkchin | 42f580e | 2015-11-26 23:18:23 -0800 | [diff] [blame] | 57 | |
| 58 | #define RTCLogInfo(format, ...) \ |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 59 | RTCLogFormat(RTCLoggingSeverityInfo, format, ##__VA_ARGS__) \ |
tkchin | 42f580e | 2015-11-26 23:18:23 -0800 | [diff] [blame] | 60 | |
| 61 | #define RTCLogWarning(format, ...) \ |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 62 | RTCLogFormat(RTCLoggingSeverityWarning, format, ##__VA_ARGS__) \ |
tkchin | 42f580e | 2015-11-26 23:18:23 -0800 | [diff] [blame] | 63 | |
| 64 | #define RTCLogError(format, ...) \ |
tkchin | 8b9ca95 | 2016-03-31 12:08:03 -0700 | [diff] [blame] | 65 | RTCLogFormat(RTCLoggingSeverityError, format, ##__VA_ARGS__) \ |
tkchin | 42f580e | 2015-11-26 23:18:23 -0800 | [diff] [blame] | 66 | |
| 67 | #if !defined(NDEBUG) |
| 68 | #define RTCLogDebug(format, ...) RTCLogInfo(format, ##__VA_ARGS__) |
| 69 | #else |
| 70 | #define RTCLogDebug(format, ...) \ |
| 71 | do { \ |
| 72 | } while (false) |
| 73 | #endif |
| 74 | |
| 75 | #define RTCLog(format, ...) RTCLogInfo(format, ##__VA_ARGS__) |