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