RTCLogging.h 2.3 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 "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, RTCFileName(__FILE__), \
  31. __LINE__, __FUNCTION__, ##__VA_ARGS__]
  32. #define RTCLogFormat(severity, format, ...) \
  33. do { \
  34. NSString* log_string = RTCLogString(format, ##__VA_ARGS__); \
  35. RTCLogEx(severity, log_string); \
  36. } while (false)
  37. #define RTCLogVerbose(format, ...) \
  38. RTCLogFormat(RTCLoggingSeverityVerbose, format, ##__VA_ARGS__)
  39. #define RTCLogInfo(format, ...) \
  40. RTCLogFormat(RTCLoggingSeverityInfo, format, ##__VA_ARGS__)
  41. #define RTCLogWarning(format, ...) \
  42. RTCLogFormat(RTCLoggingSeverityWarning, format, ##__VA_ARGS__)
  43. #define RTCLogError(format, ...) \
  44. RTCLogFormat(RTCLoggingSeverityError, format, ##__VA_ARGS__)
  45. #if !defined(NDEBUG)
  46. #define RTCLogDebug(format, ...) RTCLogInfo(format, ##__VA_ARGS__)
  47. #else
  48. #define RTCLogDebug(format, ...) \
  49. do { \
  50. } while (false)
  51. #endif
  52. #define RTCLog(format, ...) RTCLogInfo(format, ##__VA_ARGS__)