AppRTCDemo file logging.
Adds logging macros to log logs to a file. Undeletes CircularFileStream
for that purpose.
BUG=
R=jiayl@webrtc.org, pbos@webrtc.org
Review URL: https://codereview.webrtc.org/1217473011 .
Cr-Commit-Position: refs/heads/master@{#9582}
diff --git a/talk/examples/objc/.clang-format b/talk/examples/objc/.clang-format
new file mode 120000
index 0000000..ce43d52
--- /dev/null
+++ b/talk/examples/objc/.clang-format
@@ -0,0 +1 @@
+../../app/webrtc/objc/.clang-format
\ No newline at end of file
diff --git a/talk/examples/objc/AppRTCDemo/ARDAppClient.m b/talk/examples/objc/AppRTCDemo/ARDAppClient.m
index ac99ca2..5b905c6 100644
--- a/talk/examples/objc/AppRTCDemo/ARDAppClient.m
+++ b/talk/examples/objc/AppRTCDemo/ARDAppClient.m
@@ -30,6 +30,7 @@
#if defined(WEBRTC_IOS)
#import "RTCAVFoundationVideoSource.h"
#endif
+#import "RTCFileLogger.h"
#import "RTCICEServer.h"
#import "RTCMediaConstraints.h"
#import "RTCMediaStream.h"
@@ -41,6 +42,7 @@
#import "ARDAppEngineClient.h"
#import "ARDCEODTURNClient.h"
#import "ARDJoinResponse.h"
+#import "ARDLogging.h"
#import "ARDMessageResponse.h"
#import "ARDSDPUtils.h"
#import "ARDSignalingMessage.h"
@@ -65,7 +67,9 @@
static NSInteger const kARDAppClientErrorInvalidClient = -5;
static NSInteger const kARDAppClientErrorInvalidRoom = -6;
-@implementation ARDAppClient
+@implementation ARDAppClient {
+ RTCFileLogger *_fileLogger;
+}
@synthesize delegate = _delegate;
@synthesize state = _state;
@@ -131,6 +135,8 @@
_factory = [[RTCPeerConnectionFactory alloc] init];
_messageQueue = [NSMutableArray array];
_iceServers = [NSMutableArray arrayWithObject:[self defaultSTUNServer]];
+ _fileLogger = [[RTCFileLogger alloc] init];
+ [_fileLogger start];
}
- (void)dealloc {
@@ -156,7 +162,7 @@
[_turnClient requestServersWithCompletionHandler:^(NSArray *turnServers,
NSError *error) {
if (error) {
- NSLog(@"Error retrieving TURN servers: %@", error);
+ ARDLog("Error retrieving TURN servers: %@", error.localizedDescription);
}
ARDAppClient *strongSelf = weakSelf;
[strongSelf.iceServers addObjectsFromArray:turnServers];
@@ -175,12 +181,12 @@
NSError *joinError =
[[strongSelf class] errorForJoinResultType:response.result];
if (joinError) {
- NSLog(@"Failed to join room:%@ on room server.", roomId);
+ ARDLog(@"Failed to join room:%@ on room server.", roomId);
[strongSelf disconnect];
[strongSelf.delegate appClient:strongSelf didError:joinError];
return;
}
- NSLog(@"Joined room:%@ on room server.", roomId);
+ ARDLog(@"Joined room:%@ on room server.", roomId);
strongSelf.roomId = response.roomId;
strongSelf.clientId = response.clientId;
strongSelf.isInitiator = response.isInitiator;
@@ -272,13 +278,13 @@
- (void)peerConnection:(RTCPeerConnection *)peerConnection
signalingStateChanged:(RTCSignalingState)stateChanged {
- NSLog(@"Signaling state changed: %d", stateChanged);
+ ARDLog(@"Signaling state changed: %d", stateChanged);
}
- (void)peerConnection:(RTCPeerConnection *)peerConnection
addedStream:(RTCMediaStream *)stream {
dispatch_async(dispatch_get_main_queue(), ^{
- NSLog(@"Received %lu video tracks and %lu audio tracks",
+ ARDLog(@"Received %lu video tracks and %lu audio tracks",
(unsigned long)stream.videoTracks.count,
(unsigned long)stream.audioTracks.count);
if (stream.videoTracks.count) {
@@ -290,17 +296,17 @@
- (void)peerConnection:(RTCPeerConnection *)peerConnection
removedStream:(RTCMediaStream *)stream {
- NSLog(@"Stream was removed.");
+ ARDLog(@"Stream was removed.");
}
- (void)peerConnectionOnRenegotiationNeeded:
(RTCPeerConnection *)peerConnection {
- NSLog(@"WARNING: Renegotiation needed but unimplemented.");
+ ARDLog(@"WARNING: Renegotiation needed but unimplemented.");
}
- (void)peerConnection:(RTCPeerConnection *)peerConnection
iceConnectionChanged:(RTCICEConnectionState)newState {
- NSLog(@"ICE state changed: %d", newState);
+ ARDLog(@"ICE state changed: %d", newState);
dispatch_async(dispatch_get_main_queue(), ^{
[_delegate appClient:self didChangeConnectionState:newState];
});
@@ -308,7 +314,7 @@
- (void)peerConnection:(RTCPeerConnection *)peerConnection
iceGatheringChanged:(RTCICEGatheringState)newState {
- NSLog(@"ICE gathering state changed: %d", newState);
+ ARDLog(@"ICE gathering state changed: %d", newState);
}
- (void)peerConnection:(RTCPeerConnection *)peerConnection
@@ -333,7 +339,7 @@
error:(NSError *)error {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
- NSLog(@"Failed to create session description. Error: %@", error);
+ ARDLog(@"Failed to create session description. Error: %@", error);
[self disconnect];
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to create session description.",
@@ -362,7 +368,7 @@
didSetSessionDescriptionWithError:(NSError *)error {
dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
- NSLog(@"Failed to set session description. Error: %@", error);
+ ARDLog(@"Failed to set session description. Error: %@", error);
[self disconnect];
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: @"Failed to set session description.",
diff --git a/talk/examples/objc/AppRTCDemo/ARDAppEngineClient.m b/talk/examples/objc/AppRTCDemo/ARDAppEngineClient.m
index 760a171..0b33325 100644
--- a/talk/examples/objc/AppRTCDemo/ARDAppEngineClient.m
+++ b/talk/examples/objc/AppRTCDemo/ARDAppEngineClient.m
@@ -28,6 +28,7 @@
#import "ARDAppEngineClient.h"
#import "ARDJoinResponse.h"
+#import "ARDLogging.h"
#import "ARDMessageResponse.h"
#import "ARDSignalingMessage.h"
#import "ARDUtilities.h"
@@ -57,7 +58,7 @@
NSString *urlString =
[NSString stringWithFormat:kARDRoomServerJoinFormat, roomId];
NSURL *roomURL = [NSURL URLWithString:urlString];
- NSLog(@"Joining room:%@ on room server.", roomId);
+ ARDLog(@"Joining room:%@ on room server.", roomId);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:roomURL];
request.HTTPMethod = @"POST";
__weak ARDAppEngineClient *weakSelf = self;
@@ -101,7 +102,7 @@
[NSString stringWithFormat:
kARDRoomServerMessageFormat, roomId, clientId];
NSURL *url = [NSURL URLWithString:urlString];
- NSLog(@"C->RS POST: %@", message);
+ ARDLog(@"C->RS POST: %@", message);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
request.HTTPBody = data;
@@ -147,19 +148,19 @@
NSError *error = nil;
// We want a synchronous request so that we know that we've left the room on
// room server before we do any further work.
- NSLog(@"C->RS: BYE");
+ ARDLog(@"C->RS: BYE");
[NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (error) {
- NSLog(@"Error leaving room %@ on room server: %@",
+ ARDLog(@"Error leaving room %@ on room server: %@",
roomId, error.localizedDescription);
if (completionHandler) {
completionHandler(error);
}
return;
}
- NSLog(@"Left room:%@ on room server.", roomId);
+ ARDLog(@"Left room:%@ on room server.", roomId);
if (completionHandler) {
completionHandler(nil);
}
diff --git a/talk/examples/objc/AppRTCDemo/ARDSDPUtils.m b/talk/examples/objc/AppRTCDemo/ARDSDPUtils.m
index 157d6fc..481b6ce 100644
--- a/talk/examples/objc/AppRTCDemo/ARDSDPUtils.m
+++ b/talk/examples/objc/AppRTCDemo/ARDSDPUtils.m
@@ -27,6 +27,7 @@
#import "ARDSDPUtils.h"
+#import "ARDLogging.h"
#import "RTCSessionDescription.h"
@implementation ARDSDPUtils
@@ -42,7 +43,7 @@
NSMutableArray *lines =
[NSMutableArray arrayWithArray:
[sdpString componentsSeparatedByString:lineSeparator]];
- int mLineIndex = -1;
+ NSInteger mLineIndex = -1;
NSString *codecRtpMap = nil;
// a=rtpmap:<payload type> <encoding name>/<clock rate>
// [/<encoding parameters>]
@@ -70,11 +71,11 @@
}
}
if (mLineIndex == -1) {
- NSLog(@"No m=video line, so can't prefer %@", codec);
+ ARDLog(@"No m=video line, so can't prefer %@", codec);
return description;
}
if (!codecRtpMap) {
- NSLog(@"No rtpmap for %@", codec);
+ ARDLog(@"No rtpmap for %@", codec);
return description;
}
NSArray *origMLineParts =
@@ -98,7 +99,7 @@
[lines replaceObjectAtIndex:mLineIndex
withObject:newMLine];
} else {
- NSLog(@"Wrong SDP media description format: %@", lines[mLineIndex]);
+ ARDLog(@"Wrong SDP media description format: %@", lines[mLineIndex]);
}
NSString *mangledSdpString = [lines componentsJoinedByString:lineSeparator];
return [[RTCSessionDescription alloc] initWithType:description.type
diff --git a/talk/examples/objc/AppRTCDemo/ARDSignalingMessage.m b/talk/examples/objc/AppRTCDemo/ARDSignalingMessage.m
index e9fb09a..dc00e8f 100644
--- a/talk/examples/objc/AppRTCDemo/ARDSignalingMessage.m
+++ b/talk/examples/objc/AppRTCDemo/ARDSignalingMessage.m
@@ -27,6 +27,7 @@
#import "ARDSignalingMessage.h"
+#import "ARDLogging.h"
#import "ARDUtilities.h"
#import "RTCICECandidate+JSON.h"
#import "RTCSessionDescription+JSON.h"
@@ -52,7 +53,7 @@
+ (ARDSignalingMessage *)messageFromJSONString:(NSString *)jsonString {
NSDictionary *values = [NSDictionary dictionaryWithJSONString:jsonString];
if (!values) {
- NSLog(@"Error parsing signaling message JSON.");
+ ARDLog(@"Error parsing signaling message JSON.");
return nil;
}
@@ -71,7 +72,7 @@
} else if ([typeString isEqualToString:@"bye"]) {
message = [[ARDByeMessage alloc] init];
} else {
- NSLog(@"Unexpected type: %@", typeString);
+ ARDLog(@"Unexpected type: %@", typeString);
}
return message;
}
diff --git a/talk/examples/objc/AppRTCDemo/ARDWebSocketChannel.m b/talk/examples/objc/AppRTCDemo/ARDWebSocketChannel.m
index 27dd25d..f25e9d0 100644
--- a/talk/examples/objc/AppRTCDemo/ARDWebSocketChannel.m
+++ b/talk/examples/objc/AppRTCDemo/ARDWebSocketChannel.m
@@ -27,6 +27,7 @@
#import "ARDWebSocketChannel.h"
+#import "ARDLogging.h"
#import "ARDUtilities.h"
#import "SRWebSocket.h"
@@ -57,7 +58,7 @@
_delegate = delegate;
_socket = [[SRWebSocket alloc] initWithURL:url];
_socket.delegate = self;
- NSLog(@"Opening WebSocket.");
+ ARDLog(@"Opening WebSocket.");
[_socket open];
}
return self;
@@ -104,12 +105,12 @@
NSString *messageString =
[[NSString alloc] initWithData:messageJSONObject
encoding:NSUTF8StringEncoding];
- NSLog(@"C->WSS: %@", messageString);
+ ARDLog(@"C->WSS: %@", messageString);
[_socket send:messageString];
} else {
NSString *dataString =
[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- NSLog(@"C->WSS POST: %@", dataString);
+ ARDLog(@"C->WSS POST: %@", dataString);
NSString *urlString =
[NSString stringWithFormat:@"%@/%@/%@",
[_restURL absoluteString], _roomId, _clientId];
@@ -126,7 +127,7 @@
return;
}
[_socket close];
- NSLog(@"C->WSS DELETE rid:%@ cid:%@", _roomId, _clientId);
+ ARDLog(@"C->WSS DELETE rid:%@ cid:%@", _roomId, _clientId);
NSString *urlString =
[NSString stringWithFormat:@"%@/%@/%@",
[_restURL absoluteString], _roomId, _clientId];
@@ -140,7 +141,7 @@
#pragma mark - SRWebSocketDelegate
- (void)webSocketDidOpen:(SRWebSocket *)webSocket {
- NSLog(@"WebSocket connection opened.");
+ ARDLog(@"WebSocket connection opened.");
self.state = kARDSignalingChannelStateOpen;
if (_roomId.length && _clientId.length) {
[self registerWithCollider];
@@ -154,24 +155,24 @@
options:0
error:nil];
if (![jsonObject isKindOfClass:[NSDictionary class]]) {
- NSLog(@"Unexpected message: %@", jsonObject);
+ ARDLog(@"Unexpected message: %@", jsonObject);
return;
}
NSDictionary *wssMessage = jsonObject;
NSString *errorString = wssMessage[kARDWSSMessageErrorKey];
if (errorString.length) {
- NSLog(@"WSS error: %@", errorString);
+ ARDLog(@"WSS error: %@", errorString);
return;
}
NSString *payload = wssMessage[kARDWSSMessagePayloadKey];
ARDSignalingMessage *signalingMessage =
[ARDSignalingMessage messageFromJSONString:payload];
- NSLog(@"WSS->C: %@", payload);
+ ARDLog(@"WSS->C: %@", payload);
[_delegate channel:self didReceiveMessage:signalingMessage];
}
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error {
- NSLog(@"WebSocket error: %@", error);
+ ARDLog(@"WebSocket error: %@", error);
self.state = kARDSignalingChannelStateError;
}
@@ -179,7 +180,7 @@
didCloseWithCode:(NSInteger)code
reason:(NSString *)reason
wasClean:(BOOL)wasClean {
- NSLog(@"WebSocket closed with code: %ld reason:%@ wasClean:%d",
+ ARDLog(@"WebSocket closed with code: %ld reason:%@ wasClean:%d",
(long)code, reason, wasClean);
NSParameterAssert(_state != kARDSignalingChannelStateError);
self.state = kARDSignalingChannelStateClosed;
@@ -204,7 +205,7 @@
error:nil];
NSString *messageString =
[[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding];
- NSLog(@"Registering on WSS for rid:%@ cid:%@", _roomId, _clientId);
+ ARDLog(@"Registering on WSS for rid:%@ cid:%@", _roomId, _clientId);
// Registration can fail if server rejects it. For example, if the room is
// full.
[_socket send:messageString];
diff --git a/talk/examples/objc/AppRTCDemo/RTCICECandidate+JSON.m b/talk/examples/objc/AppRTCDemo/RTCICECandidate+JSON.m
index c15d633..01d666d 100644
--- a/talk/examples/objc/AppRTCDemo/RTCICECandidate+JSON.m
+++ b/talk/examples/objc/AppRTCDemo/RTCICECandidate+JSON.m
@@ -27,6 +27,8 @@
#import "RTCICECandidate+JSON.h"
+#import "ARDLogging.h"
+
static NSString const *kRTCICECandidateTypeKey = @"type";
static NSString const *kRTCICECandidateTypeValue = @"candidate";
static NSString const *kRTCICECandidateMidKey = @"id";
@@ -56,7 +58,7 @@
options:NSJSONWritingPrettyPrinted
error:&error];
if (error) {
- NSLog(@"Error serializing JSON: %@", error);
+ ARDLog(@"Error serializing JSON: %@", error);
return nil;
}
return data;
diff --git a/talk/examples/objc/AppRTCDemo/common/ARDLogging.h b/talk/examples/objc/AppRTCDemo/common/ARDLogging.h
new file mode 100644
index 0000000..dfb31d8
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/common/ARDLogging.h
@@ -0,0 +1,88 @@
+/*
+ * libjingle
+ * Copyright 2015 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+
+// We route all logging through the WebRTC logger. By doing this we will get
+// both app and WebRTC logs in the same place, which we can then route to a
+// file if we need to. A side effect of this is that we get severity for free.
+typedef NS_ENUM(NSInteger, ARDLogSeverity) {
+ kARDLogSeverityVerbose,
+ kARDLogSeverityInfo,
+ kARDLogSeverityWarning,
+ kARDLogSeverityError,
+};
+
+#if defined(__cplusplus)
+extern "C" void ARDLogToWebRTCLogger(ARDLogSeverity severity,
+ NSString *logString);
+extern "C" NSString *ARDFileName(const char *filePath);
+extern "C" void ARDLogInit();
+#else
+// Logs |logString| to the WebRTC logger at the given severity.
+extern void ARDLogToWebRTCLogger(ARDLogSeverity severity, NSString *logString);
+// Returns the filename with the path prefix removed.
+extern NSString *ARDFileName(const char *filePath);
+// Initializes the correct logging levels. This should be called once on app
+// startup.
+extern void ARDLogInit();
+#endif
+
+#define ARDLogString(format, ...) \
+ [NSString stringWithFormat:@"(%@:%d %s): " format, \
+ ARDFileName(__FILE__), \
+ __LINE__, \
+ __FUNCTION__, \
+ ##__VA_ARGS__]
+
+#define ARDLogEx(severity, format, ...) \
+ do { \
+ NSString *logString = ARDLogString(format, ##__VA_ARGS__); \
+ ARDLogToWebRTCLogger(severity, logString); \
+ } while (false)
+
+#define ARDLogVerbose(format, ...) \
+ ARDLogEx(kARDLogSeverityVerbose, format, ##__VA_ARGS__) \
+
+#define ARDLogInfo(format, ...) \
+ ARDLogEx(kARDLogSeverityInfo, format, ##__VA_ARGS__) \
+
+#define ARDLogWarning(format, ...) \
+ ARDLogEx(kARDLogSeverityWarning, format, ##__VA_ARGS__) \
+
+#define ARDLogError(format, ...) \
+ ARDLogEx(kARDLogSeverityError, format, ##__VA_ARGS__) \
+
+#ifdef _DEBUG
+#define ARDLogDebug(format, ...) ARDLogInfo(format, ##__VA_ARGS__)
+#else
+#define ARDLogDebug(format, ...) \
+ do { \
+ } while (false)
+#endif
+
+#define ARDLog(format, ...) ARDLogInfo(format, ##__VA_ARGS__)
diff --git a/talk/examples/objc/AppRTCDemo/common/ARDLogging.mm b/talk/examples/objc/AppRTCDemo/common/ARDLogging.mm
new file mode 100644
index 0000000..7bd773d
--- /dev/null
+++ b/talk/examples/objc/AppRTCDemo/common/ARDLogging.mm
@@ -0,0 +1,68 @@
+/*
+ * libjingle
+ * Copyright 2015 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "ARDLogging.h"
+
+#include "webrtc/base/logging.h"
+
+void ARDLogInit() {
+#ifndef _DEBUG
+ // In debug builds the default level is LS_INFO and in non-debug builds it is
+ // disabled. Continue to log to console in non-debug builds, but only
+ // warnings and errors.
+ rtc::LogMessage::LogToDebug(rtc::LS_WARNING);
+#endif
+}
+
+void ARDLogToWebRTCLogger(ARDLogSeverity severity, NSString *logString) {
+ if (logString.length) {
+ const char* utf8String = logString.UTF8String;
+ switch (severity) {
+ case kARDLogSeverityVerbose:
+ LOG(LS_VERBOSE) << utf8String;
+ break;
+ case kARDLogSeverityInfo:
+ LOG(LS_INFO) << utf8String;
+ break;
+ case kARDLogSeverityWarning:
+ LOG(LS_WARNING) << utf8String;
+ break;
+ case kARDLogSeverityError:
+ LOG(LS_ERROR) << utf8String;
+ break;
+ }
+ }
+}
+
+NSString *ARDFileName(const char *filePath) {
+ NSString *nsFilePath =
+ [[NSString alloc] initWithBytesNoCopy:const_cast<char *>(filePath)
+ length:strlen(filePath)
+ encoding:NSUTF8StringEncoding
+ freeWhenDone:NO];
+ return nsFilePath.lastPathComponent;
+}
diff --git a/talk/examples/objc/AppRTCDemo/ARDUtilities.h b/talk/examples/objc/AppRTCDemo/common/ARDUtilities.h
similarity index 100%
rename from talk/examples/objc/AppRTCDemo/ARDUtilities.h
rename to talk/examples/objc/AppRTCDemo/common/ARDUtilities.h
diff --git a/talk/examples/objc/AppRTCDemo/ARDUtilities.m b/talk/examples/objc/AppRTCDemo/common/ARDUtilities.m
similarity index 93%
rename from talk/examples/objc/AppRTCDemo/ARDUtilities.m
rename to talk/examples/objc/AppRTCDemo/common/ARDUtilities.m
index 781e786..066ee02 100644
--- a/talk/examples/objc/AppRTCDemo/ARDUtilities.m
+++ b/talk/examples/objc/AppRTCDemo/common/ARDUtilities.m
@@ -25,6 +25,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#import "ARDLogging.h"
#import "ARDUtilities.h"
@implementation NSDictionary (ARDUtilites)
@@ -36,7 +37,7 @@
NSDictionary *dict =
[NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (error) {
- NSLog(@"Error parsing JSON: %@", error.localizedDescription);
+ ARDLog(@"Error parsing JSON: %@", error.localizedDescription);
}
return dict;
}
@@ -46,7 +47,7 @@
NSDictionary *dict =
[NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (error) {
- NSLog(@"Error parsing JSON: %@", error.localizedDescription);
+ ARDLog(@"Error parsing JSON: %@", error.localizedDescription);
}
return dict;
}
@@ -84,7 +85,7 @@
NSData *data,
NSError *error) {
if (error) {
- NSLog(@"Error posting data: %@", error.localizedDescription);
+ ARDLog(@"Error posting data: %@", error.localizedDescription);
if (completionHandler) {
completionHandler(NO, data);
}
@@ -95,7 +96,7 @@
NSString *serverResponse = data.length > 0 ?
[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] :
nil;
- NSLog(@"Received bad response: %@", serverResponse);
+ ARDLog(@"Received bad response: %@", serverResponse);
if (completionHandler) {
completionHandler(NO, data);
}
diff --git a/talk/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m b/talk/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m
index 2a7a155..352ade6 100644
--- a/talk/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m
+++ b/talk/examples/objc/AppRTCDemo/ios/ARDAppDelegate.m
@@ -27,6 +27,7 @@
#import "ARDAppDelegate.h"
+#import "ARDLogging.h"
#import "ARDMainViewController.h"
#import "RTCPeerConnectionFactory.h"
@@ -43,6 +44,7 @@
[_window makeKeyAndVisible];
ARDMainViewController *viewController = [[ARDMainViewController alloc] init];
_window.rootViewController = viewController;
+ ARDLogInit();
return YES;
}
diff --git a/talk/examples/objc/AppRTCDemo/ios/ARDVideoCallViewController.m b/talk/examples/objc/AppRTCDemo/ios/ARDVideoCallViewController.m
index 2f07c7a..149beef 100644
--- a/talk/examples/objc/AppRTCDemo/ios/ARDVideoCallViewController.m
+++ b/talk/examples/objc/AppRTCDemo/ios/ARDVideoCallViewController.m
@@ -30,6 +30,7 @@
#import "RTCAVFoundationVideoSource.h"
#import "ARDAppClient.h"
+#import "ARDLogging.h"
#import "ARDVideoCallView.h"
@interface ARDVideoCallViewController () <ARDAppClientDelegate,
@@ -69,13 +70,13 @@
didChangeState:(ARDAppClientState)state {
switch (state) {
case kARDAppClientStateConnected:
- NSLog(@"Client connected.");
+ ARDLog(@"Client connected.");
break;
case kARDAppClientStateConnecting:
- NSLog(@"Client connecting.");
+ ARDLog(@"Client connecting.");
break;
case kARDAppClientStateDisconnected:
- NSLog(@"Client disconnected.");
+ ARDLog(@"Client disconnected.");
[self hangup];
break;
}
@@ -83,7 +84,7 @@
- (void)appClient:(ARDAppClient *)client
didChangeConnectionState:(RTCICEConnectionState)state {
- NSLog(@"ICE state changed: %d", state);
+ ARDLog(@"ICE state changed: %d", state);
__weak ARDVideoCallViewController *weakSelf = self;
dispatch_async(dispatch_get_main_queue(), ^{
ARDVideoCallViewController *strongSelf = weakSelf;