diff --git a/MVMCore/MVMCore/ActionHandling/ActionActionsModel.swift b/MVMCore/MVMCore/ActionHandling/ActionActionsModel.swift index c7e00fc..ba7fa10 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionActionsModel.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionActionsModel.swift @@ -65,3 +65,10 @@ public struct ActionActionsModel: ActionModelProtocol { try container.encodeIfPresent(analyticsData, forKey: .analyticsData) } } + +extension ActionActionsModel: CustomDebugStringConvertible { + + public var debugDescription: String { + return "\(Self.self) [\(actions)]" + } +} diff --git a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift index ff2378e..8d20194 100644 --- a/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift +++ b/MVMCore/MVMCore/ActionHandling/MVMCoreActionHandler.swift @@ -85,9 +85,9 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { open func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) async throws { try Task.checkCancellation() var (additionalData, uuid) = MVMCoreActionHandler.setUUID(additionalData: additionalData) - MVMCoreActionHandler.log(string: "Begin Action: \(model.actionType)", additionalData: additionalData) + MVMCoreActionHandler.log(string: "Begin Action: \(model)", additionalData: additionalData) defer { - MVMCoreActionHandler.log(string: "End Action: \(model.actionType)", additionalData: additionalData) + MVMCoreActionHandler.log(string: "End Action: \(model)", additionalData: additionalData) } let json = try additionalData.removeValue(forKey: jsonKey) as? [AnyHashable : Any] ?? MVMCoreActionHandler.convertActionToJSON(model) @@ -148,7 +148,7 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol { } static public func log(string: String, additionalData: [AnyHashable: Any]?) { - MVMCoreLoggingHandler.logDebugMessage(withDelegate: "ActionHandler: UUID: \(String(describing: getUUID(additionalData: additionalData))), \(string)") + MVMCoreLoggingHandler.shared()?.handleDebugMessage("ActionHandler: UUID: \(getUUID(additionalData: additionalData) ?? "untracked"), \(string)", category: String(describing: Self.self)) } fileprivate func logActionError(_ error: Error, _ actionType: String?, _ additionalData: [AnyHashable: Any]?, _ delegateObject: DelegateObject?) { diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m index 3446798..a4baf05 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadHandler.m @@ -232,7 +232,7 @@ return; } NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; - MVMCoreLog(@"Request Parameters for URL %@:\n%@", [url absoluteString], jsonString); + MVMCoreNetworkLog(@"Request Parameters for URL %@:\n%@", [url absoluteString], jsonString); #endif // Standard condensed to send to the server. @@ -309,15 +309,15 @@ return nil; } - MVMCoreLog(@"********************************* Cookie Sent *********************************"); + MVMCoreNetworkLog(@"********************************* Cookie Sent *********************************"); [[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:request.URL] enumerateObjectsUsingBlock:^(NSHTTPCookie * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { - MVMCoreLog(@"Cookie Name: %@, Cookie Value: %@, Domain: %@", obj.name, obj.value, obj.domain); + MVMCoreNetworkLog(@"Cookie Name: %@, Cookie Value: %@, Domain: %@", obj.name, obj.value, obj.domain); }]; NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate]; NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { - MVMCoreLog(@"Request Time %f", [NSDate timeIntervalSinceReferenceDate] - startTime); + MVMCoreNetworkLog(@"Request Time %f", [NSDate timeIntervalSinceReferenceDate] - startTime); NSDate *startTimeDate = [NSDate dateWithTimeIntervalSinceReferenceDate:startTime]; @@ -330,7 +330,7 @@ [trackInfo setObject:error.localizedDescription forKey:@"error"]; } - MVMCoreLog(@"Set-Cookie %@ Value: %@", requestParameters.pageType, [(NSHTTPURLResponse *)response allHeaderFields][@"Set-Cookie"]); + MVMCoreNetworkLog(@"Set-Cookie %@ Value: %@", requestParameters.pageType, [(NSHTTPURLResponse *)response allHeaderFields][@"Set-Cookie"]); id jsonObject = nil; MVMCoreErrorObject *errorObject = nil; @@ -354,7 +354,7 @@ // Log the response pretty. NSData *prettyData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:&error]; NSString *responseString = [[NSString alloc] initWithData:prettyData encoding:NSUTF8StringEncoding]; - MVMCoreLog(@"Response for Request Page Type %@:\n%@",requestParameters.pageType, responseString); + MVMCoreNetworkLog(@"Response for Request Page Type %@:\n%@",requestParameters.pageType, responseString); } } else { // Empty response. diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 699df7b..801f2d0 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -86,7 +86,7 @@ // stop any loading animation we may have started [self stopLoadingAnimationIfNeeded]; - MVMCoreLog(@"Load Operation finished for page type %@, background load %@", self.requestParameters.pageType, @(self.backgroundLoad)); + MVMCoreNetworkLog(@"Load Operation finished for page type %@, background load %@", self.requestParameters.pageType, @(self.backgroundLoad)); [super markAsFinished]; } @@ -107,7 +107,7 @@ } - (void)main { - MVMCoreLog(@"Load Operation begun for page type %@, background load %@, delegate %@", self.requestParameters.pageType, @(self.backgroundLoad),self.delegateObject.loadDelegate); + MVMCoreNetworkLog(@"Load Operation begun for page type %@, background load %@, delegate %@", self.requestParameters.pageType, @(self.backgroundLoad),self.delegateObject.loadDelegate); [self.requestParameters resolveURL:[MVMCoreSessionObject sharedGlobal]]; @@ -139,10 +139,10 @@ // Log if loaded from cache. if (pageFromCache) { - MVMCoreLog(@"loaded from cache page %@",[MVMCoreActionUtility formatDictionaryAsJSONString:pageFromCache]); + MVMCoreNetworkLog(@"loaded from cache page %@",[MVMCoreActionUtility formatDictionaryAsJSONString:pageFromCache]); } if (modulesFromCache) { - MVMCoreLog(@"loaded from cache modules %@",[MVMCoreActionUtility formatDictionaryAsJSONString:modulesFromCache]); + MVMCoreNetworkLog(@"loaded from cache modules %@",[MVMCoreActionUtility formatDictionaryAsJSONString:modulesFromCache]); } // Create a load object from any data we fetched. @@ -822,7 +822,7 @@ return; } - MVMCoreLog(@"Error: %@ %@ %@ %@ %@",[error stringErrorCode], error.domain, error.location,error.messageToDisplay, error.messageToLog); + MVMCoreNetworkLog(@"Error: %@ %@ %@ %@ %@",[error stringErrorCode], error.domain, error.location,error.messageToDisplay, error.messageToLog); if (showAlertForErrorIfApplicable && (!loadObject.operation.backgroundLoad || loadObject.requestParameters.allowAlertsIfBackgroundRequest) && !loadObject.requestParameters.handleErrorsSilently && !error.silentError && !error.errorScreenError) { diff --git a/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift b/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift index 028af05..24f5011 100644 --- a/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift +++ b/MVMCore/MVMCore/Models/ActionType/ActionModelProtocol.swift @@ -7,7 +7,7 @@ // -public protocol ActionModelProtocol: ModelProtocol { +public protocol ActionModelProtocol: ModelProtocol, CustomDebugStringConvertible { var actionType: String { get } var extraParameters: JSONValueDictionary? { get set } @@ -33,4 +33,8 @@ public extension ActionModelProtocol { static var categoryName: String { return "\(ActionModelProtocol.self)" } + + var debugDescription: String { + return actionType + } } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift index 86047d0..e562854 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler.swift @@ -50,7 +50,7 @@ import os #if LOGGING guard let message = message else { return } guard message.count < 1024 else { - logger.debug("\(message.prefix(100), privacy: .public)... ") // Send initial log to console. + logger.debug("\(message.prefix(300), privacy: .public)... ") // Send initial log to console. print(message) // Print the whole on stdout. return } @@ -59,10 +59,10 @@ import os #endif } - open func handleDebugMessage(_ message: String, category: String?) { + @objc open func handleDebugMessage(_ message: String, category: String?) { #if LOGGING guard message.count < 1024 else { - getLogger(category: category).debug("\(message.prefix(100), privacy: .public)... ") // Send initial log to console. + getLogger(category: category).debug("\(message.prefix(300), privacy: .public)... ") // Send initial log to console. print(message) // Print the whole on stdout. return } diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandlerHelper.h b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandlerHelper.h index bb0fe9b..1ba0edf 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandlerHelper.h +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandlerHelper.h @@ -8,7 +8,11 @@ #ifndef MVMCoreLoggingHandlerHelper_h #define MVMCoreLoggingHandlerHelper_h + #define MVMCoreLog(fmt, ...) \ [MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:(@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__]]; -#endif +#define MVMCoreNetworkLog(fmt, ...) \ +[MVMCoreLoggingHandler.sharedLoggingHandler handleDebugMessage:[NSString stringWithFormat:(@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__] category: @"Network"]; + +#endif