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