RTCLogging.h 2.4 KB

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