From 39a84513147281c165f71379b04375c9758471a0 Mon Sep 17 00:00:00 2001 From: "Hedden, Kyle Matthew" Date: Tue, 30 Apr 2024 13:42:33 -0400 Subject: [PATCH] Digital PCT265 story ONEAPP-7249 - CoreLogging protocol for easier logging. --- .../ActionHandling/ActionOpenPageModel.swift | 10 ++++++++ .../MVMCoreLoggingHandler+Extension.swift | 25 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/MVMCore/MVMCore/ActionHandling/ActionOpenPageModel.swift b/MVMCore/MVMCore/ActionHandling/ActionOpenPageModel.swift index c8362a8..ac7ee02 100644 --- a/MVMCore/MVMCore/ActionHandling/ActionOpenPageModel.swift +++ b/MVMCore/MVMCore/ActionHandling/ActionOpenPageModel.swift @@ -116,3 +116,13 @@ public struct ActionOpenPageModel: ActionModelProtocol, ActionOpenPageProtocol, try container.encodeIfPresent(fallbackResponse, forKey: .fallbackResponse) } } + +extension ActionOpenPageModel: CustomDebugStringConvertible { + public var debugDescription: String { + if let requestURL { + return "\(Self.self) for \(pageType) @ \(requestURL)" + } else { + return "\(Self.self) for \(pageType)" + } + } +} diff --git a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler+Extension.swift b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler+Extension.swift index d74201e..cc80a81 100644 --- a/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler+Extension.swift +++ b/MVMCore/MVMCore/OtherHandlers/MVMCoreLoggingHandler+Extension.swift @@ -13,3 +13,28 @@ import Foundation Swift.print(message) } } + +public protocol CoreLogging { + func debugLog(_ string: String) + + var loggingPrefix: String { get } +} + +public extension CoreLogging { + + var loggingPrefix: String { + return String(describing: self) + } + + static func debugLog(_ string: String) { + #if LOGGING + MVMCoreLoggingHandler.shared()?.handleDebugMessage("\(String(describing: Self.self)) \(string)") + #endif + } + + func debugLog(_ string: String) { + #if LOGGING + MVMCoreLoggingHandler.shared()?.handleDebugMessage("\(loggingPrefix) " + string) + #endif + } +}