File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,11 @@ public class Analytics {
16
16
internal var storage : Storage
17
17
18
18
/// Enabled/disables debug logging to trace your data going through the SDK.
19
- public var debugLogsEnabled = false
19
+ public static var debugLogsEnabled = false {
20
+ didSet {
21
+ SegmentLog . loggingEnabled = debugLogsEnabled
22
+ }
23
+ }
20
24
21
25
public var timeline : Timeline
22
26
Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ internal class SegmentLog: UtilityPlugin {
16
16
let type = PluginType . utility
17
17
18
18
fileprivate var loggingMediator = [ LoggingType: LogTarget] ( )
19
- internal static var loggingEnabled = true
19
+
20
+ // Default to no, enable to see local logs
21
+ internal static var loggingEnabled = false
20
22
21
23
// For internal use only. Note: This will contain the last created instance
22
24
// of analytics when used in a multi-analytics environment.
Original file line number Diff line number Diff line change @@ -32,11 +32,16 @@ final class LogTarget_Tests: XCTestCase {
32
32
override func setUp( ) {
33
33
analytics = Analytics ( configuration: Configuration ( writeKey: " test " ) )
34
34
analytics? . add ( plugin: mockLogger)
35
+
36
+ // Enable logging for all tests
37
+ SegmentLog . loggingEnabled = true
35
38
}
36
39
37
40
override func tearDown( ) {
38
41
analytics = nil
39
- SegmentLog . loggingEnabled = true
42
+
43
+ // Reset to default state the system should be in from start
44
+ SegmentLog . loggingEnabled = false
40
45
}
41
46
42
47
func testMetric( ) {
@@ -142,6 +147,20 @@ final class LogTarget_Tests: XCTestCase {
142
147
analytics? . history ( event: TrackEvent ( event: " Tester " , properties: nil ) , sender: self )
143
148
}
144
149
145
-
150
+ func testLoggingDisabledByDefault( ) {
151
+ SegmentLog . loggingEnabled = false
152
+ XCTAssertFalse ( SegmentLog . loggingEnabled, " Logging should not default to enabled " )
153
+ }
154
+
155
+ func testLoggingEnabledFromAnalytics( ) {
156
+ SegmentLog . loggingEnabled = false
157
+
158
+ Analytics . debugLogsEnabled = true
159
+ XCTAssertTrue ( SegmentLog . loggingEnabled, " Logging should change to enabled " )
160
+
161
+ Analytics . debugLogsEnabled = false
162
+ XCTAssertFalse ( SegmentLog . loggingEnabled, " Logging should reset to disabled " )
163
+ }
164
+
146
165
}
147
166
You can’t perform that action at this time.
0 commit comments