blob: b758785115a629ce37489e001b054bab791dd119 [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
tkchin9eeb6242016-04-27 01:54:20 -070013#import <WebRTC/RTCMacros.h>
tkchin8b577ed2016-04-19 10:04:41 -070014
tkchin42f580e2015-11-26 23:18:23 -080015// Subset of rtc::LoggingSeverity.
16typedef NS_ENUM(NSInteger, RTCLoggingSeverity) {
tkchin8b9ca952016-03-31 12:08:03 -070017 RTCLoggingSeverityVerbose,
18 RTCLoggingSeverityInfo,
19 RTCLoggingSeverityWarning,
20 RTCLoggingSeverityError,
tkchin42f580e2015-11-26 23:18:23 -080021};
22
Mirko Bonadei675513b2017-11-09 11:09:25 +010023// Wrapper for C++ RTC_LOG(sev) macros.
tkchin42f580e2015-11-26 23:18:23 -080024// Logs the log string to the webrtc logstream for the given severity.
tkchin8b577ed2016-04-19 10:04:41 -070025RTC_EXTERN void RTCLogEx(RTCLoggingSeverity severity, NSString* log_string);
tkchin42f580e2015-11-26 23:18:23 -080026
27// Wrapper for rtc::LogMessage::LogToDebug.
28// Sets the minimum severity to be logged to console.
tkchin8b577ed2016-04-19 10:04:41 -070029RTC_EXTERN void RTCSetMinDebugLogLevel(RTCLoggingSeverity severity);
tkchin42f580e2015-11-26 23:18:23 -080030
31// Returns the filename with the path prefix removed.
tkchin8b577ed2016-04-19 10:04:41 -070032RTC_EXTERN NSString* RTCFileName(const char* filePath);
tkchin42f580e2015-11-26 23:18:23 -080033
34// Some convenience macros.
35
Yves Gerey665174f2018-06-19 15:03:05 +020036#define RTCLogString(format, ...) \
37 [NSString stringWithFormat:@"(%@:%d %s): " format, RTCFileName(__FILE__), \
38 __LINE__, __FUNCTION__, ##__VA_ARGS__]
tkchin42f580e2015-11-26 23:18:23 -080039
40#define RTCLogFormat(severity, format, ...) \
41 do { \
42 NSString* log_string = RTCLogString(format, ##__VA_ARGS__); \
43 RTCLogEx(severity, log_string); \
44 } while (false)
45
Yves Gerey665174f2018-06-19 15:03:05 +020046#define RTCLogVerbose(format, ...) \
47 RTCLogFormat(RTCLoggingSeverityVerbose, format, ##__VA_ARGS__)
tkchin42f580e2015-11-26 23:18:23 -080048
Yves Gerey665174f2018-06-19 15:03:05 +020049#define RTCLogInfo(format, ...) \
50 RTCLogFormat(RTCLoggingSeverityInfo, format, ##__VA_ARGS__)
tkchin42f580e2015-11-26 23:18:23 -080051
Yves Gerey665174f2018-06-19 15:03:05 +020052#define RTCLogWarning(format, ...) \
53 RTCLogFormat(RTCLoggingSeverityWarning, format, ##__VA_ARGS__)
tkchin42f580e2015-11-26 23:18:23 -080054
Yves Gerey665174f2018-06-19 15:03:05 +020055#define RTCLogError(format, ...) \
56 RTCLogFormat(RTCLoggingSeverityError, format, ##__VA_ARGS__)
tkchin42f580e2015-11-26 23:18:23 -080057
58#if !defined(NDEBUG)
59#define RTCLogDebug(format, ...) RTCLogInfo(format, ##__VA_ARGS__)
60#else
61#define RTCLogDebug(format, ...) \
62 do { \
63 } while (false)
64#endif
65
66#define RTCLog(format, ...) RTCLogInfo(format, ##__VA_ARGS__)