14
14
* limitations under the License.
15
15
*/
16
16
17
+ import Foundation
17
18
import os. signpost
18
19
19
20
private extension OSLog {
20
21
/// Logging will use this log handle when enabled
21
22
static let workflow = OSLog ( subsystem: " com.squareup.Workflow " , category: " Workflow " )
22
23
23
- /// The active log handle to use when logging. Defaults to the shared `.disabled` handle.
24
- static var active : OSLog = . disabled
24
+ /// The active log handle to use when logging. If `WorkflowLogging.osLoggingSupported` is
25
+ /// `true`, defaults to the `workflow` handle, otherwise defaults to the shared `.disabled`
26
+ /// handle.
27
+ static var active : OSLog = {
28
+ WorkflowLogging . isOSLoggingAllowed ? . workflow : . disabled
29
+ } ( )
25
30
}
26
31
27
32
// MARK: -
28
33
29
34
/// Namespace for specifying logging configuration data.
30
35
public enum WorkflowLogging { }
31
36
37
+ extension WorkflowLogging {
38
+ /// Flag indicating whether `OSLog` logs may be recorded. Note, actual emission of
39
+ /// log statements in specific cases may depend on additional configuration options, so
40
+ /// this being `true` does not necessarily imply logging will occur.
41
+ public static let isOSLoggingAllowed : Bool = {
42
+ let env = ProcessInfo . processInfo. environment
43
+ guard let value = env [ " com.squareup.workflow.allowOSLogging " ] else {
44
+ return false
45
+ }
46
+ return ( value as NSString ) . boolValue
47
+ } ( )
48
+ }
49
+
32
50
extension WorkflowLogging {
33
51
public struct Config {
34
52
/// Configuration options to control logging during a render pass.
@@ -93,7 +111,10 @@ final class WorkflowLogger {
93
111
// MARK: Workflows
94
112
95
113
static func logWorkflowStarted< WorkflowType> ( ref: WorkflowNode < WorkflowType > ) {
96
- guard WorkflowLogging . config. logLifetimes else { return }
114
+ guard
115
+ WorkflowLogging . isOSLoggingAllowed,
116
+ WorkflowLogging . config. logLifetimes
117
+ else { return }
97
118
98
119
let signpostID = OSSignpostID ( log: . active, object: ref)
99
120
os_signpost (
@@ -107,14 +128,20 @@ final class WorkflowLogger {
107
128
}
108
129
109
130
static func logWorkflowFinished< WorkflowType> ( ref: WorkflowNode < WorkflowType > ) {
110
- guard WorkflowLogging . config. logLifetimes else { return }
131
+ guard
132
+ WorkflowLogging . isOSLoggingAllowed,
133
+ WorkflowLogging . config. logLifetimes
134
+ else { return }
111
135
112
136
let signpostID = OSSignpostID ( log: . active, object: ref)
113
137
os_signpost ( . end, log: . active, name: " Alive " , signpostID: signpostID)
114
138
}
115
139
116
140
static func logSinkEvent< Action: WorkflowAction > ( ref: AnyObject , action: Action ) {
117
- guard WorkflowLogging . config. logActions else { return }
141
+ guard
142
+ WorkflowLogging . isOSLoggingAllowed,
143
+ WorkflowLogging . config. logActions
144
+ else { return }
118
145
119
146
let signpostID = OSSignpostID ( log: . active, object: ref)
120
147
os_signpost (
@@ -165,6 +192,9 @@ final class WorkflowLogger {
165
192
private static func shouldLogRenderTimings(
166
193
isRootNode: Bool
167
194
) -> Bool {
195
+ guard WorkflowLogging . isOSLoggingAllowed else {
196
+ return false
197
+ }
168
198
switch WorkflowLogging . config. renderLoggingMode {
169
199
case . none:
170
200
return false
0 commit comments