Digital PCT265 story ONEAPP-7249 - More logging cleanups and categorization.

This commit is contained in:
Hedden, Kyle Matthew 2024-05-06 12:53:28 -04:00
parent dde3e565a3
commit e8552b0aa2
7 changed files with 34 additions and 19 deletions

View File

@ -65,3 +65,10 @@ public struct ActionActionsModel: ActionModelProtocol {
try container.encodeIfPresent(analyticsData, forKey: .analyticsData) try container.encodeIfPresent(analyticsData, forKey: .analyticsData)
} }
} }
extension ActionActionsModel: CustomDebugStringConvertible {
public var debugDescription: String {
return "\(Self.self) [\(actions)]"
}
}

View File

@ -85,9 +85,9 @@ public protocol MVMCoreJSONActionHandlerProtocol: MVMCoreActionHandlerProtocol {
open func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) async throws { open func handleAction(with model: ActionModelProtocol, additionalData: [AnyHashable: Any]?, delegateObject: DelegateObject?) async throws {
try Task.checkCancellation() try Task.checkCancellation()
var (additionalData, uuid) = MVMCoreActionHandler.setUUID(additionalData: additionalData) 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 { 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) 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]?) { 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?) { fileprivate func logActionError(_ error: Error, _ actionType: String?, _ additionalData: [AnyHashable: Any]?, _ delegateObject: DelegateObject?) {

View File

@ -232,7 +232,7 @@
return; return;
} }
NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 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 #endif
// Standard condensed to send to the server. // Standard condensed to send to the server.
@ -309,15 +309,15 @@
return nil; return nil;
} }
MVMCoreLog(@"********************************* Cookie Sent *********************************"); MVMCoreNetworkLog(@"********************************* Cookie Sent *********************************");
[[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:request.URL] enumerateObjectsUsingBlock:^(NSHTTPCookie * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [[[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]; NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate];
NSURLSessionTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 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]; NSDate *startTimeDate = [NSDate dateWithTimeIntervalSinceReferenceDate:startTime];
@ -330,7 +330,7 @@
[trackInfo setObject:error.localizedDescription forKey:@"error"]; [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; id jsonObject = nil;
MVMCoreErrorObject *errorObject = nil; MVMCoreErrorObject *errorObject = nil;
@ -354,7 +354,7 @@
// Log the response pretty. // Log the response pretty.
NSData *prettyData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:&error]; NSData *prettyData = [NSJSONSerialization dataWithJSONObject:jsonObject options:NSJSONWritingPrettyPrinted error:&error];
NSString *responseString = [[NSString alloc] initWithData:prettyData encoding:NSUTF8StringEncoding]; 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 { } else {
// Empty response. // Empty response.

View File

@ -86,7 +86,7 @@
// stop any loading animation we may have started // stop any loading animation we may have started
[self stopLoadingAnimationIfNeeded]; [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]; [super markAsFinished];
} }
@ -107,7 +107,7 @@
} }
- (void)main { - (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]]; [self.requestParameters resolveURL:[MVMCoreSessionObject sharedGlobal]];
@ -139,10 +139,10 @@
// Log if loaded from cache. // Log if loaded from cache.
if (pageFromCache) { if (pageFromCache) {
MVMCoreLog(@"loaded from cache page %@",[MVMCoreActionUtility formatDictionaryAsJSONString:pageFromCache]); MVMCoreNetworkLog(@"loaded from cache page %@",[MVMCoreActionUtility formatDictionaryAsJSONString:pageFromCache]);
} }
if (modulesFromCache) { 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. // Create a load object from any data we fetched.
@ -822,7 +822,7 @@
return; 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) { if (showAlertForErrorIfApplicable && (!loadObject.operation.backgroundLoad || loadObject.requestParameters.allowAlertsIfBackgroundRequest) && !loadObject.requestParameters.handleErrorsSilently && !error.silentError && !error.errorScreenError) {

View File

@ -7,7 +7,7 @@
// //
public protocol ActionModelProtocol: ModelProtocol { public protocol ActionModelProtocol: ModelProtocol, CustomDebugStringConvertible {
var actionType: String { get } var actionType: String { get }
var extraParameters: JSONValueDictionary? { get set } var extraParameters: JSONValueDictionary? { get set }
@ -33,4 +33,8 @@ public extension ActionModelProtocol {
static var categoryName: String { static var categoryName: String {
return "\(ActionModelProtocol.self)" return "\(ActionModelProtocol.self)"
} }
var debugDescription: String {
return actionType
}
} }

View File

@ -50,7 +50,7 @@ import os
#if LOGGING #if LOGGING
guard let message = message else { return } guard let message = message else { return }
guard message.count < 1024 else { guard message.count < 1024 else {
logger.debug("\(message.prefix(100), privacy: .public)... <stdio>") // Send initial log to console. logger.debug("\(message.prefix(300), privacy: .public)... <stdio>") // Send initial log to console.
print(message) // Print the whole on stdout. print(message) // Print the whole on stdout.
return return
} }
@ -59,10 +59,10 @@ import os
#endif #endif
} }
open func handleDebugMessage(_ message: String, category: String?) { @objc open func handleDebugMessage(_ message: String, category: String?) {
#if LOGGING #if LOGGING
guard message.count < 1024 else { guard message.count < 1024 else {
getLogger(category: category).debug("\(message.prefix(100), privacy: .public)... <stdio>") // Send initial log to console. getLogger(category: category).debug("\(message.prefix(300), privacy: .public)... <stdio>") // Send initial log to console.
print(message) // Print the whole on stdout. print(message) // Print the whole on stdout.
return return
} }

View File

@ -8,7 +8,11 @@
#ifndef MVMCoreLoggingHandlerHelper_h #ifndef MVMCoreLoggingHandlerHelper_h
#define MVMCoreLoggingHandlerHelper_h #define MVMCoreLoggingHandlerHelper_h
#define MVMCoreLog(fmt, ...) \ #define MVMCoreLog(fmt, ...) \
[MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:(@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__]]; [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