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 {
1616 internal var storage : Storage
1717
1818 /// 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+ }
2024
2125 public var timeline : Timeline
2226
Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ internal class SegmentLog: UtilityPlugin {
1616 let type = PluginType . utility
1717
1818 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
2022
2123 // For internal use only. Note: This will contain the last created instance
2224 // 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 {
3232 override func setUp( ) {
3333 analytics = Analytics ( configuration: Configuration ( writeKey: " test " ) )
3434 analytics? . add ( plugin: mockLogger)
35+
36+ // Enable logging for all tests
37+ SegmentLog . loggingEnabled = true
3538 }
3639
3740 override func tearDown( ) {
3841 analytics = nil
39- SegmentLog . loggingEnabled = true
42+
43+ // Reset to default state the system should be in from start
44+ SegmentLog . loggingEnabled = false
4045 }
4146
4247 func testMetric( ) {
@@ -142,6 +147,20 @@ final class LogTarget_Tests: XCTestCase {
142147 analytics? . history ( event: TrackEvent ( event: " Tester " , properties: nil ) , sender: self )
143148 }
144149
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+
146165}
147166
You can’t perform that action at this time.
0 commit comments