• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) {
15   kRTCLoggingSeverityVerbose,
16   kRTCLoggingSeverityInfo,
17   kRTCLoggingSeverityWarning,
18   kRTCLoggingSeverityError,
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, ...)                                \
56   RTCLogFormat(kRTCLoggingSeverityVerbose, format, ##__VA_ARGS__) \
57 
58 #define RTCLogInfo(format, ...)                                   \
59   RTCLogFormat(kRTCLoggingSeverityInfo, format, ##__VA_ARGS__)    \
60 
61 #define RTCLogWarning(format, ...)                                \
62   RTCLogFormat(kRTCLoggingSeverityWarning, format, ##__VA_ARGS__) \
63 
64 #define RTCLogError(format, ...)                                  \
65   RTCLogFormat(kRTCLoggingSeverityError, format, ##__VA_ARGS__)   \
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__)
76