Skip to content

Commit

Permalink
Merge logging changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
samgreen committed Jul 15, 2016
2 parents 5f545a3 + 13ddb49 commit 5dfc829
Show file tree
Hide file tree
Showing 25 changed files with 273 additions and 248 deletions.
28 changes: 14 additions & 14 deletions HelloMixpanel/HelloMixpanel.xcodeproj/project.pbxproj
Expand Up @@ -31,13 +31,13 @@
48324589F27775A10F52DA8E /* Pods_HelloMixpanel_tvOSTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8943B032B4AB174C4AD3BBDF /* Pods_HelloMixpanel_tvOSTests.framework */; };
515B59D61CB6C8FD00A34060 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05C13E5118184DBE00848D48 /* CFNetwork.framework */; };
515B59D71CB6C90200A34060 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05C13E5318184DC700848D48 /* Security.framework */; };
515B5A0A1CB6F96700A34060 /* Mixpanel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 515B5A031CB6F95200A34060 /* Mixpanel.framework */; };
515B5A0B1CB6F96700A34060 /* Mixpanel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 515B5A031CB6F95200A34060 /* Mixpanel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
515EE7CC1D10D31A00D035A4 /* HelloMixpanelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2808F9BF1610EFE4005772B7 /* HelloMixpanelTests.m */; };
517ABB711D14ADE900FF8061 /* MPNetworkTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 517ABB6D1D14ADCD00FF8061 /* MPNetworkTests.m */; };
517ABB771D14CA7B00FF8061 /* MixpanelPeopleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 51D96E821D120D4F001F622D /* MixpanelPeopleTests.m */; };
517ABB7A1D14CA8300FF8061 /* MPNetworkTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 517ABB6D1D14ADCD00FF8061 /* MPNetworkTests.m */; };
518010161D11CEA300C5F3EA /* Nocilla.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 518010151D11CEA300C5F3EA /* Nocilla.framework */; };
51AF3D3C1D380D31002E8325 /* Mixpanel.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 515B5A031CB6F95200A34060 /* Mixpanel.framework */; };
51AF3D3D1D380D31002E8325 /* Mixpanel.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 515B5A031CB6F95200A34060 /* Mixpanel.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
51D96E781D11EF7D001F622D /* Nocilla.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = 518010151D11CEA300C5F3EA /* Nocilla.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
51D96E7F1D120D2A001F622D /* MPSurveyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 51D96E7E1D120D2A001F622D /* MPSurveyTests.m */; };
51D96E811D120D3E001F622D /* MPNotificationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 51D96E801D120D3E001F622D /* MPNotificationTests.m */; };
Expand Down Expand Up @@ -169,14 +169,14 @@
remoteGlobalIDString = 513B0BB61C73CA35008EEE6E;
remoteInfo = MixpanelAppExtension;
};
515B5A081CB6F96100A34060 /* PBXContainerItemProxy */ = {
51AF3D3A1D380D2A002E8325 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 515B59FC1CB6F95200A34060 /* Mixpanel.xcodeproj */;
proxyType = 1;
remoteGlobalIDString = 7C170C291A4A02F500D9E0F2;
remoteInfo = Mixpanel;
};
515B5A0C1CB6F96700A34060 /* PBXContainerItemProxy */ = {
51AF3D3E1D380D31002E8325 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 515B59FC1CB6F95200A34060 /* Mixpanel.xcodeproj */;
proxyType = 1;
Expand Down Expand Up @@ -207,13 +207,13 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
515B5A0E1CB6F96700A34060 /* Embed Frameworks */ = {
51AF3D401D380D31002E8325 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
515B5A0B1CB6F96700A34060 /* Mixpanel.framework in Embed Frameworks */,
51AF3D3D1D380D31002E8325 /* Mixpanel.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -344,7 +344,7 @@
515B59D61CB6C8FD00A34060 /* CFNetwork.framework in Frameworks */,
05E98DF1191AE10000AFF3E1 /* MapKit.framework in Frameworks */,
A7BB224519183EB800EEDCCD /* ImageIO.framework in Frameworks */,
515B5A0A1CB6F96700A34060 /* Mixpanel.framework in Frameworks */,
51AF3D3C1D380D31002E8325 /* Mixpanel.framework in Frameworks */,
2802054017DEC234000D71F5 /* QuartzCore.framework in Frameworks */,
2805EDE617C6B815003A0D72 /* Accelerate.framework in Frameworks */,
2892541F16548283003DAFFE /* CoreTelephony.framework in Frameworks */,
Expand Down Expand Up @@ -625,13 +625,13 @@
2808F9891610EFE3005772B7 /* Sources */,
2808F98A1610EFE3005772B7 /* Frameworks */,
2808F98B1610EFE3005772B7 /* Resources */,
515B5A0E1CB6F96700A34060 /* Embed Frameworks */,
51AF3D401D380D31002E8325 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
515B5A091CB6F96100A34060 /* PBXTargetDependency */,
515B5A0D1CB6F96700A34060 /* PBXTargetDependency */,
51AF3D3B1D380D2A002E8325 /* PBXTargetDependency */,
51AF3D3F1D380D31002E8325 /* PBXTargetDependency */,
);
name = HelloMixpanel;
productName = HelloMixpanel;
Expand Down Expand Up @@ -1042,15 +1042,15 @@
target = 2808F98C1610EFE3005772B7 /* HelloMixpanel */;
targetProxy = 2808F9B61610EFE4005772B7 /* PBXContainerItemProxy */;
};
515B5A091CB6F96100A34060 /* PBXTargetDependency */ = {
51AF3D3B1D380D2A002E8325 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = Mixpanel;
targetProxy = 515B5A081CB6F96100A34060 /* PBXContainerItemProxy */;
targetProxy = 51AF3D3A1D380D2A002E8325 /* PBXContainerItemProxy */;
};
515B5A0D1CB6F96700A34060 /* PBXTargetDependency */ = {
51AF3D3F1D380D31002E8325 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = Mixpanel;
targetProxy = 515B5A0C1CB6F96700A34060 /* PBXContainerItemProxy */;
targetProxy = 51AF3D3E1D380D31002E8325 /* PBXContainerItemProxy */;
};
E123C4A01D1354EC0015B425 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
Expand Down
20 changes: 10 additions & 10 deletions Mixpanel/MPABTestDesignerConnection.m
Expand Up @@ -94,7 +94,7 @@ - (void)open:(BOOL)initiate maxInterval:(int)maxInterval maxRetries:(int)maxRetr
static int retries = 0;
BOOL inRetryLoop = retries > 0;

MessagingDebug(@"In open. initiate = %d, retries = %d, maxRetries = %d, maxInterval = %d, connected = %d", initiate, retries, maxRetries, maxInterval, _connected);
MPLogDebug(@"In open. initiate = %d, retries = %d, maxRetries = %d, maxInterval = %d, connected = %d", initiate, retries, maxRetries, maxInterval, _connected);

if (self.sessionEnded || _connected || (inRetryLoop && retries >= maxRetries) ) {
// break out of retry loop if any of the success conditions are met.
Expand All @@ -103,7 +103,7 @@ - (void)open:(BOOL)initiate maxInterval:(int)maxInterval maxRetries:(int)maxRetr
// If we are initiating a new connection, or we are already in a
// retry loop (but not both). Then open a socket.
if (!_open) {
MessagingDebug(@"Attempting to open WebSocket to: %@, try %d/%d ", _url, retries, maxRetries);
MPLogDebug(@"Attempting to open WebSocket to: %@, try %d/%d ", _url, retries, maxRetries);
_open = YES;
_webSocket = [[MPWebSocket alloc] initWithURL:_url];
_webSocket.delegate = self;
Expand Down Expand Up @@ -161,17 +161,17 @@ - (id)sessionObjectForKey:(NSString *)key
- (void)sendMessage:(id<MPABTestDesignerMessage>)message
{
if (_connected) {
MessagingDebug(@"Sending message: %@", [message debugDescription]);
MPLogDebug(@"Sending message: %@", [message debugDescription]);
NSString *jsonString = [[NSString alloc] initWithData:[message JSONData] encoding:NSUTF8StringEncoding];
[_webSocket send:jsonString];
} else {
MessagingDebug(@"Not sending message as we are not connected: %@", [message debugDescription]);
MPLogDebug(@"Not sending message as we are not connected: %@", [message debugDescription]);
}
}

- (id <MPABTestDesignerMessage>)designerMessageForMessage:(id)message
{
MessagingDebug(@"raw message: %@", message);
MPLogInfo(@"raw message: %@", message);

NSParameterAssert([message isKindOfClass:[NSString class]] || [message isKindOfClass:[NSData class]]);

Expand All @@ -188,7 +188,7 @@ - (void)sendMessage:(id<MPABTestDesignerMessage>)message

designerMessage = [_typeToMessageClassMap[type] messageWithType:type payload:payload];
} else {
MessagingDebug(@"Badly formed socket message expected JSON dictionary: %@", error);
MPLogWarning(@"Badly formed socket message expected JSON dictionary: %@", error);
}

return designerMessage;
Expand All @@ -206,7 +206,7 @@ - (void)webSocket:(MPWebSocket *)webSocket didReceiveMessage:(id)message
}
}
id<MPABTestDesignerMessage> designerMessage = [self designerMessageForMessage:message];
MessagingDebug(@"WebSocket received message: %@", [designerMessage debugDescription]);
MPLogInfo(@"WebSocket received message: %@", [designerMessage debugDescription]);
NSOperation *commandOperation = [designerMessage responseCommandWithConnection:self];

if (commandOperation) {
Expand All @@ -216,14 +216,14 @@ - (void)webSocket:(MPWebSocket *)webSocket didReceiveMessage:(id)message

- (void)webSocketDidOpen:(MPWebSocket *)webSocket
{
MessagingDebug(@"WebSocket %@ did open.", webSocket);
MPLogInfo(@"WebSocket %@ did open.", webSocket);
_commandQueue.suspended = NO;
[self showConnectedViewWithLoading:YES];
}

- (void)webSocket:(MPWebSocket *)webSocket didFailWithError:(NSError *)error
{
MessagingDebug(@"WebSocket did fail with error: %@", error);
MPLogError(@"WebSocket did fail with error: %@", error);
_commandQueue.suspended = YES;
[_commandQueue cancelAllOperations];
[self hideConnectedView];
Expand All @@ -239,7 +239,7 @@ - (void)webSocket:(MPWebSocket *)webSocket didFailWithError:(NSError *)error

- (void)webSocket:(MPWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean
{
MessagingDebug(@"WebSocket did close with code '%d' reason '%@'.", (int)code, reason);
MPLogDebug(@"WebSocket did close with code '%d' reason '%@'.", (int)code, reason);

_commandQueue.suspended = YES;
[_commandQueue cancelAllOperations];
Expand Down
4 changes: 2 additions & 2 deletions Mixpanel/MPAbstractABTestDesignerMessage.m
Expand Up @@ -59,8 +59,8 @@ - (NSData *)JSONData

NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonObject options:(NSJSONWritingOptions)0 error:&error];
if (jsonData == nil && error) {
MixpanelError(@"Failed to serialize test designer message: %@", error);
if (error) {
MPLogError(@"Failed to serialize test designer message: %@", error);
}

return jsonData;
Expand Down
2 changes: 1 addition & 1 deletion Mixpanel/MPApplicationStateSerializer.m
Expand Up @@ -38,7 +38,7 @@ - (UIImage *)screenshotImageForWindowAtIndex:(NSUInteger)index
if (window && !CGRectEqualToRect(window.frame, CGRectZero)) {
UIGraphicsBeginImageContextWithOptions(window.bounds.size, YES, window.screen.scale);
if ([window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO] == NO) {
MixpanelError(@"Unable to get complete screenshot for window at index: %d.", (int)index);
MPLogError(@"Unable to get complete screenshot for window at index: %d.", (int)index);
}
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Expand Down
53 changes: 26 additions & 27 deletions Mixpanel/MPLogger.h
Expand Up @@ -7,34 +7,33 @@
//

#import <Foundation/Foundation.h>
#import <asl.h>

#ifndef MPLogger_h
#define MPLogger_h
static bool gLoggingEnabled = NO;
static inline void MPSetLoggingEnabled(BOOL enabled) {

static inline void MPLog(NSString *format, ...) {
__block va_list arg_list;
va_start (arg_list, format);
NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:arg_list];
va_end(arg_list);
NSLog(@"[Mixpanel] %@", formattedString);
}

#ifdef MIXPANEL_ERROR
#define MixpanelError(...) MPLog(__VA_ARGS__)
#else
#define MixpanelError(...)
#endif

#ifdef MIXPANEL_DEBUG
#define MixpanelDebug(...) MPLog(__VA_ARGS__)
#else
#define MixpanelDebug(...)
#endif

#ifdef MIXPANEL_MESSAGING_DEBUG
#define MessagingDebug(...) MPLog(__VA_ARGS__)
#else
#define MessagingDebug(...)
#endif

#endif
#define __MP_MAKE_LOG_FUNCTION(LEVEL, NAME) \
static inline void NAME(NSString *format, ...) { \
if (!gLoggingEnabled) return; \
va_list arg_list; \
va_start(arg_list, format); \
NSString *formattedString = [[NSString alloc] initWithFormat:format arguments:arg_list]; \
asl_log(NULL, NULL, (LEVEL), "%s", [formattedString UTF8String]); \
va_end(arg_list); \
}

// Something has failed.
__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_ERR, MPLogError)

// Something is amiss and might fail if not corrected.
__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_WARNING, MPLogWarning)

// The lowest priority that you would normally log, and purely informational in nature.
__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_INFO, MPLogInfo)

// The lowest priority, and normally not logged except for code based messages.
__MP_MAKE_LOG_FUNCTION(ASL_LEVEL_DEBUG, MPLogDebug)

#undef __MP_MAKE_LOG_FUNCTION
4 changes: 2 additions & 2 deletions Mixpanel/MPNSAttributedStringToNSDictionaryValueTransformer.m
Expand Up @@ -31,7 +31,7 @@ - (id)transformedValue:(id)value
@"data": [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]
};
} else {
MixpanelError(@"Failed to convert NSAttributedString to HTML: %@", error);
MPLogError(@"Failed to convert NSAttributedString to HTML: %@", error);
}
}

Expand All @@ -53,7 +53,7 @@ - (id)reverseTransformedValue:(id)value
documentAttributes:NULL
error:&error];
if (attributedString == nil) {
MixpanelError(@"Failed to convert HTML to NSAttributed string: %@", error);
MPLogError(@"Failed to convert HTML to NSAttributed string: %@", error);
}

return attributedString;
Expand Down

0 comments on commit 5dfc829

Please sign in to comment.