blob: fbc4ffade279ef83175e31cc15f8945d97c42614 [file] [log] [blame]
tkchin42f580e2015-11-26 23:18:23 -08001/*
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.
14typedef NS_ENUM(NSInteger, RTCLoggingSeverity) {
tkchin8b9ca952016-03-31 12:08:03 -070015 RTCLoggingSeverityVerbose,
16 RTCLoggingSeverityInfo,
17 RTCLoggingSeverityWarning,
18 RTCLoggingSeverityError,
tkchin42f580e2015-11-26 23:18:23 -080019};
20
21#if defined(__cplusplus)
22extern "C" void RTCLogEx(RTCLoggingSeverity severity, NSString* log_string);
23extern "C" void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity);
24extern "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.
29extern void RTCLogEx(RTCLoggingSeverity severity, NSString* log_string);
30
31// Wrapper for rtc::LogMessage::LogToDebug.
32// Sets the minimum severity to be logged to console.
33extern void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity);
34
35// Returns the filename with the path prefix removed.
36extern 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, ...) \
tkchin8b9ca952016-03-31 12:08:03 -070056 RTCLogFormat(RTCLoggingSeverityVerbose, format, ##__VA_ARGS__) \
tkchin42f580e2015-11-26 23:18:23 -080057
58#define RTCLogInfo(format, ...) \
tkchin8b9ca952016-03-31 12:08:03 -070059 RTCLogFormat(RTCLoggingSeverityInfo, format, ##__VA_ARGS__) \
tkchin42f580e2015-11-26 23:18:23 -080060
61#define RTCLogWarning(format, ...) \
tkchin8b9ca952016-03-31 12:08:03 -070062 RTCLogFormat(RTCLoggingSeverityWarning, format, ##__VA_ARGS__) \
tkchin42f580e2015-11-26 23:18:23 -080063
64#define RTCLogError(format, ...) \
tkchin8b9ca952016-03-31 12:08:03 -070065 RTCLogFormat(RTCLoggingSeverityError, format, ##__VA_ARGS__) \
tkchin42f580e2015-11-26 23:18:23 -080066
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__)