Skip to content

Commit

Permalink
[fix]: short circuit worker logging & require explicit opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieQ committed Jun 18, 2024
1 parent 15d7d29 commit 21f66c7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
12 changes: 12 additions & 0 deletions WorkflowCombine/Sources/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -29,6 +35,8 @@ final class WorkerLogger<WorkerType: Worker> {
// MARK: - Workers

func logStarted() {
guard workerLoggingEnabled else { return }

os_signpost(
.begin,
log: .worker,
Expand All @@ -40,6 +48,8 @@ final class WorkerLogger<WorkerType: Worker> {
}

func logFinished(status: StaticString) {
guard workerLoggingEnabled else { return }

os_signpost(
.end,
log: .worker,
Expand All @@ -50,6 +60,8 @@ final class WorkerLogger<WorkerType: Worker> {
}

func logOutput() {
guard workerLoggingEnabled else { return }

os_signpost(
.event,
log: .worker,
Expand Down
12 changes: 12 additions & 0 deletions WorkflowConcurrency/Sources/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -29,6 +35,8 @@ final class WorkerLogger<WorkerType: Worker> {
// MARK: - Workers

func logStarted() {
guard workerLoggingEnabled else { return }

os_signpost(
.begin,
log: .worker,
Expand All @@ -40,6 +48,8 @@ final class WorkerLogger<WorkerType: Worker> {
}

func logFinished(status: StaticString) {
guard workerLoggingEnabled else { return }

os_signpost(
.end,
log: .worker,
Expand All @@ -50,6 +60,8 @@ final class WorkerLogger<WorkerType: Worker> {
}

func logOutput() {
guard workerLoggingEnabled else { return }

os_signpost(
.event,
log: .worker,
Expand Down
16 changes: 15 additions & 1 deletion WorkflowReactiveSwift/Sources/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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: -
Expand All @@ -43,6 +51,8 @@ final class WorkerLogger<WorkerType: Worker> {
// MARK: - Workers

func logStarted() {
guard WorkerLogging.enabled else { return }

os_signpost(
.begin,
log: .active,
Expand All @@ -54,10 +64,14 @@ final class WorkerLogger<WorkerType: Worker> {
}

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,
Expand Down
16 changes: 15 additions & 1 deletion WorkflowRxSwift/Sources/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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: -
Expand All @@ -43,6 +51,8 @@ final class WorkerLogger<WorkerType: Worker> {
// MARK: - Workers

func logStarted() {
guard WorkerLogging.enabled else { return }

os_signpost(
.begin,
log: .active,
Expand All @@ -54,10 +64,14 @@ final class WorkerLogger<WorkerType: Worker> {
}

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,
Expand Down

0 comments on commit 21f66c7

Please sign in to comment.