From 21f66c799a17c6555e417a486dea769555295239 Mon Sep 17 00:00:00 2001 From: Jamie Quadri Date: Tue, 18 Jun 2024 14:52:21 -0500 Subject: [PATCH] [fix]: short circuit worker logging & require explicit opt-in --- WorkflowCombine/Sources/Logger.swift | 12 ++++++++++++ WorkflowConcurrency/Sources/Logger.swift | 12 ++++++++++++ WorkflowReactiveSwift/Sources/Logger.swift | 16 +++++++++++++++- WorkflowRxSwift/Sources/Logger.swift | 16 +++++++++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/WorkflowCombine/Sources/Logger.swift b/WorkflowCombine/Sources/Logger.swift index 6fa3279c1..4d1943784 100644 --- a/WorkflowCombine/Sources/Logger.swift +++ b/WorkflowCombine/Sources/Logger.swift @@ -14,8 +14,14 @@ * limitations under the License. */ +import Foundation import os.signpost +private let workerLoggingEnabled: Bool = { + let env = ProcessInfo.processInfo.environment + return env["com.squareup.workflow.workerLogging"] != nil +}() + private extension OSLog { static let worker = OSLog(subsystem: "com.squareup.WorkflowCombine", category: "Worker") } @@ -29,6 +35,8 @@ final class WorkerLogger { // MARK: - Workers func logStarted() { + guard workerLoggingEnabled else { return } + os_signpost( .begin, log: .worker, @@ -40,6 +48,8 @@ final class WorkerLogger { } func logFinished(status: StaticString) { + guard workerLoggingEnabled else { return } + os_signpost( .end, log: .worker, @@ -50,6 +60,8 @@ final class WorkerLogger { } func logOutput() { + guard workerLoggingEnabled else { return } + os_signpost( .event, log: .worker, diff --git a/WorkflowConcurrency/Sources/Logger.swift b/WorkflowConcurrency/Sources/Logger.swift index 5a9fa4e21..e6fc6a4c1 100644 --- a/WorkflowConcurrency/Sources/Logger.swift +++ b/WorkflowConcurrency/Sources/Logger.swift @@ -14,8 +14,14 @@ * limitations under the License. */ +import Foundation import os.signpost +private let workerLoggingEnabled: Bool = { + let env = ProcessInfo.processInfo.environment + return env["com.squareup.workflow.workerLogging"] != nil +}() + private extension OSLog { static let worker = OSLog(subsystem: "com.squareup.WorkflowConcurrency", category: "Worker") } @@ -29,6 +35,8 @@ final class WorkerLogger { // MARK: - Workers func logStarted() { + guard workerLoggingEnabled else { return } + os_signpost( .begin, log: .worker, @@ -40,6 +48,8 @@ final class WorkerLogger { } func logFinished(status: StaticString) { + guard workerLoggingEnabled else { return } + os_signpost( .end, log: .worker, @@ -50,6 +60,8 @@ final class WorkerLogger { } func logOutput() { + guard workerLoggingEnabled else { return } + os_signpost( .event, log: .worker, diff --git a/WorkflowReactiveSwift/Sources/Logger.swift b/WorkflowReactiveSwift/Sources/Logger.swift index 8921814a7..e2b3ddea7 100644 --- a/WorkflowReactiveSwift/Sources/Logger.swift +++ b/WorkflowReactiveSwift/Sources/Logger.swift @@ -14,11 +14,17 @@ * limitations under the License. */ +import Foundation import os.signpost // Namespace for Worker logging public enum WorkerLogging {} +private let workerLoggingEnabled: Bool = { + let env = ProcessInfo.processInfo.environment + return env["com.squareup.workflow.workerLogging"] != nil +}() + extension WorkerLogging { public static var enabled: Bool { get { OSLog.active === OSLog.worker } @@ -29,7 +35,9 @@ extension WorkerLogging { private extension OSLog { static let worker = OSLog(subsystem: "com.squareup.WorkflowReactiveSwift", category: "Worker") - static var active: OSLog = .disabled + static var active: OSLog = { + workerLoggingEnabled ? .worker : .disabled + }() } // MARK: - @@ -43,6 +51,8 @@ final class WorkerLogger { // MARK: - Workers func logStarted() { + guard WorkerLogging.enabled else { return } + os_signpost( .begin, log: .active, @@ -54,10 +64,14 @@ final class WorkerLogger { } func logFinished(status: StaticString) { + guard WorkerLogging.enabled else { return } + os_signpost(.end, log: .active, name: "Running", signpostID: signpostID, status) } func logOutput() { + guard WorkerLogging.enabled else { return } + os_signpost( .event, log: .active, diff --git a/WorkflowRxSwift/Sources/Logger.swift b/WorkflowRxSwift/Sources/Logger.swift index a3d2807e2..02706509d 100644 --- a/WorkflowRxSwift/Sources/Logger.swift +++ b/WorkflowRxSwift/Sources/Logger.swift @@ -14,11 +14,17 @@ * limitations under the License. */ +import Foundation import os.signpost // Namespace for Worker logging public enum WorkerLogging {} +private let workerLoggingEnabled: Bool = { + let env = ProcessInfo.processInfo.environment + return env["com.squareup.workflow.workerLogging"] != nil +}() + extension WorkerLogging { public static var enabled: Bool { get { OSLog.active === OSLog.worker } @@ -29,7 +35,9 @@ extension WorkerLogging { private extension OSLog { static let worker = OSLog(subsystem: "com.squareup.WorkflowRxSwift", category: "Worker") - static var active: OSLog = .disabled + static var active: OSLog = { + workerLoggingEnabled ? .worker : .disabled + }() } // MARK: - @@ -43,6 +51,8 @@ final class WorkerLogger { // MARK: - Workers func logStarted() { + guard WorkerLogging.enabled else { return } + os_signpost( .begin, log: .active, @@ -54,10 +64,14 @@ final class WorkerLogger { } func logFinished(status: StaticString) { + guard WorkerLogging.enabled else { return } + os_signpost(.end, log: .active, name: "Running", signpostID: signpostID, status) } func logOutput() { + guard WorkerLogging.enabled else { return } + os_signpost( .event, log: .active,