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