Skip to content

Commit af5f975

Browse files
committed
add Mixpanel prefix to avoid namespace clashes
1 parent 4b58a6c commit af5f975

14 files changed

+99
-99
lines changed

Mixpanel.xcodeproj/project.pbxproj

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
17C6547B2BB1F16000C8A126 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */; };
1212
17C6547C2BB1F16400C8A126 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */; };
1313
17C6547D2BB1F16800C8A126 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */; };
14-
51DD567C1D306B740045D3DB /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56791D306B740045D3DB /* Logger.swift */; };
14+
51DD567C1D306B740045D3DB /* MixpanelLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56791D306B740045D3DB /* MixpanelLogger.swift */; };
1515
51DD56831D306B7B0045D3DB /* PrintLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56801D306B7B0045D3DB /* PrintLogging.swift */; };
1616
51DD56841D306B7B0045D3DB /* FileLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56811D306B7B0045D3DB /* FileLogging.swift */; };
1717
673ABE3A21360CBE00B1784B /* Group.swift in Sources */ = {isa = PBXBuildFile; fileRef = 673ABE3921360CBE00B1784B /* Group.swift */; };
@@ -28,7 +28,7 @@
2828
86F86EB7224439D300B69832 /* Mixpanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E115948A1CFF1538007F8B4F /* Mixpanel.swift */; };
2929
86F86EB8224439D300B69832 /* MixpanelInstance.swift in Sources */ = {isa = PBXBuildFile; fileRef = E115948D1D000709007F8B4F /* MixpanelInstance.swift */; };
3030
86F86EB9224439DC00B69832 /* AutomaticProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D335CF1D3059A800E68E12 /* AutomaticProperties.swift */; };
31-
86F86EBA224439E300B69832 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56791D306B740045D3DB /* Logger.swift */; };
31+
86F86EBA224439E300B69832 /* MixpanelLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56791D306B740045D3DB /* MixpanelLogger.swift */; };
3232
86F86EBB224439EB00B69832 /* FlushRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D335CB1D303A0D00E68E12 /* FlushRequest.swift */; };
3333
86F86EBC224439F100B69832 /* PrintLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56801D306B7B0045D3DB /* PrintLogging.swift */; };
3434
86F86EBD224439F500B69832 /* Flush.swift in Sources */ = {isa = PBXBuildFile; fileRef = E115949E1D01BE14007F8B4F /* Flush.swift */; };
@@ -55,7 +55,7 @@
5555
E11594A11D01C597007F8B4F /* Track.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11594A01D01C597007F8B4F /* Track.swift */; };
5656
E12782BB1D4AB5CB0025FB05 /* PrintLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56801D306B7B0045D3DB /* PrintLogging.swift */; };
5757
E12782BC1D4AB5CB0025FB05 /* FileLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56811D306B7B0045D3DB /* FileLogging.swift */; };
58-
E12782BD1D4AB5CB0025FB05 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56791D306B740045D3DB /* Logger.swift */; };
58+
E12782BD1D4AB5CB0025FB05 /* MixpanelLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56791D306B740045D3DB /* MixpanelLogger.swift */; };
5959
E12782BE1D4AB5CB0025FB05 /* Mixpanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E115948A1CFF1538007F8B4F /* Mixpanel.swift */; };
6060
E12782BF1D4AB5CB0025FB05 /* MixpanelInstance.swift in Sources */ = {isa = PBXBuildFile; fileRef = E115948D1D000709007F8B4F /* MixpanelInstance.swift */; };
6161
E12782C11D4AB5CB0025FB05 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11594961D006022007F8B4F /* Network.swift */; };
@@ -85,7 +85,7 @@
8585
E1F15FD61E64B5FC00391AE3 /* FlushRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D335CB1D303A0D00E68E12 /* FlushRequest.swift */; };
8686
E1F15FD71E64B60200391AE3 /* PrintLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56801D306B7B0045D3DB /* PrintLogging.swift */; };
8787
E1F15FD81E64B60200391AE3 /* FileLogging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56811D306B7B0045D3DB /* FileLogging.swift */; };
88-
E1F15FD91E64B60600391AE3 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56791D306B740045D3DB /* Logger.swift */; };
88+
E1F15FD91E64B60600391AE3 /* MixpanelLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51DD56791D306B740045D3DB /* MixpanelLogger.swift */; };
8989
E1F15FDA1E64B60A00391AE3 /* JSONHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = E11594981D01689F007F8B4F /* JSONHandler.swift */; };
9090
E1F15FDB1E64B60A00391AE3 /* Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1982BFE1D0AC2E2006B7330 /* Error.swift */; };
9191
E1F15FDC1E64B60A00391AE3 /* AutomaticProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D335CF1D3059A800E68E12 /* AutomaticProperties.swift */; };
@@ -100,7 +100,7 @@
100100

101101
/* Begin PBXFileReference section */
102102
1728208D2BA8BDE4002CD973 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = Sources/Mixpanel/PrivacyInfo.xcprivacy; sourceTree = SOURCE_ROOT; };
103-
51DD56791D306B740045D3DB /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
103+
51DD56791D306B740045D3DB /* MixpanelLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MixpanelLogger.swift; sourceTree = "<group>"; };
104104
51DD56801D306B7B0045D3DB /* PrintLogging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintLogging.swift; sourceTree = "<group>"; };
105105
51DD56811D306B7B0045D3DB /* FileLogging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileLogging.swift; sourceTree = "<group>"; };
106106
673ABE3921360CBE00B1784B /* Group.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Group.swift; sourceTree = "<group>"; };
@@ -174,7 +174,7 @@
174174
isa = PBXGroup;
175175
children = (
176176
51DD56781D306B6B0045D3DB /* Logging */,
177-
51DD56791D306B740045D3DB /* Logger.swift */,
177+
51DD56791D306B740045D3DB /* MixpanelLogger.swift */,
178178
);
179179
name = Log;
180180
sourceTree = "<group>";
@@ -492,7 +492,7 @@
492492
86F86EBC224439F100B69832 /* PrintLogging.swift in Sources */,
493493
868550AF2699096F001FCDDC /* MixpanelPersistence.swift in Sources */,
494494
86F86EBB224439EB00B69832 /* FlushRequest.swift in Sources */,
495-
86F86EBA224439E300B69832 /* Logger.swift in Sources */,
495+
86F86EBA224439E300B69832 /* MixpanelLogger.swift in Sources */,
496496
86F86EB9224439DC00B69832 /* AutomaticProperties.swift in Sources */,
497497
86F86F3722497F2900B69832 /* AutomaticEvents.swift in Sources */,
498498
86F86EB7224439D300B69832 /* Mixpanel.swift in Sources */,
@@ -515,7 +515,7 @@
515515
E11594A11D01C597007F8B4F /* Track.swift in Sources */,
516516
E11594991D01689F007F8B4F /* JSONHandler.swift in Sources */,
517517
E1D335D01D3059A800E68E12 /* AutomaticProperties.swift in Sources */,
518-
51DD567C1D306B740045D3DB /* Logger.swift in Sources */,
518+
51DD567C1D306B740045D3DB /* MixpanelLogger.swift in Sources */,
519519
E165228F1D6781DF000D5949 /* MixpanelType.swift in Sources */,
520520
BB9614171F3BB87700C3EF3E /* ReadWriteLock.swift in Sources */,
521521
E190522D1F9FC1BC00900E5D /* SessionMetadata.swift in Sources */,
@@ -535,7 +535,7 @@
535535
67FF65E521878416005161FA /* Group.swift in Sources */,
536536
E12782BB1D4AB5CB0025FB05 /* PrintLogging.swift in Sources */,
537537
E12782BC1D4AB5CB0025FB05 /* FileLogging.swift in Sources */,
538-
E12782BD1D4AB5CB0025FB05 /* Logger.swift in Sources */,
538+
E12782BD1D4AB5CB0025FB05 /* MixpanelLogger.swift in Sources */,
539539
E12782BE1D4AB5CB0025FB05 /* Mixpanel.swift in Sources */,
540540
E12782BF1D4AB5CB0025FB05 /* MixpanelInstance.swift in Sources */,
541541
E12782C11D4AB5CB0025FB05 /* Network.swift in Sources */,
@@ -564,7 +564,7 @@
564564
E1F15FE01E64B60D00391AE3 /* MixpanelInstance.swift in Sources */,
565565
E1F15FDF1E64B60D00391AE3 /* Mixpanel.swift in Sources */,
566566
E1F15FDC1E64B60A00391AE3 /* AutomaticProperties.swift in Sources */,
567-
E1F15FD91E64B60600391AE3 /* Logger.swift in Sources */,
567+
E1F15FD91E64B60600391AE3 /* MixpanelLogger.swift in Sources */,
568568
E1F15FD61E64B5FC00391AE3 /* FlushRequest.swift in Sources */,
569569
E1F15FD71E64B60200391AE3 /* PrintLogging.swift in Sources */,
570570
8625BEBD26D045CE0009BAA9 /* MPDB.swift in Sources */,

Sources/Error.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ErrorHandler {
3636

3737
class func logError(_ error: Error) {
3838
let stackSymbols = Thread.callStackSymbols
39-
Logger.error(message: "Error: \(error) \n Stack Symbols: \(stackSymbols)")
39+
MixpanelLogger.error(message: "Error: \(error) \n Stack Symbols: \(stackSymbols)")
4040
}
4141

4242
}

Sources/FileLogging.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111
/// Logs all messages to a file
12-
class FileLogging: Logging {
12+
class FileLogging: MixpanelLogging {
1313
private let fileHandle: FileHandle
1414

1515
init(path: String) {
@@ -28,7 +28,7 @@ class FileLogging: Logging {
2828
fileHandle.closeFile()
2929
}
3030

31-
func addMessage(message: LogMessage) {
31+
func addMessage(message: MixpanelLogMessage) {
3232
let string = "File: \(message.file) - Func: \(message.function) - " +
3333
"Level: \(message.level.rawValue) - Message: \(message.text)"
3434
if let data = string.data(using: String.Encoding.utf8) {

Sources/Flush.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ class Flush: AppLifecycle {
122122
(entity["id"] as? Int32) ?? 0
123123
}
124124
// Log data payload sent
125-
Logger.debug(message: "Sending batch of data")
126-
Logger.debug(message: batch as Any)
125+
MixpanelLogger.debug(message: "Sending batch of data")
126+
MixpanelLogger.debug(message: batch as Any)
127127
let requestData = JSONHandler.encodeAPIData(batch)
128128
if let requestData = requestData {
129129
#if os(iOS)

Sources/FlushRequest.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ class FlushRequest: Network {
6565
failure: { (reason, _, response) in
6666
self.networkConsecutiveFailures += 1
6767
self.updateRetryDelay(response)
68-
Logger.warn(message: "API request to \(resource.path) has failed with reason \(reason)")
68+
MixpanelLogger.warn(message: "API request to \(resource.path) has failed with reason \(reason)")
6969
completion(false)
7070
}, success: { (result, response) in
7171
self.networkConsecutiveFailures = 0
7272
self.updateRetryDelay(response)
7373
if result == 0 {
74-
Logger.info(message: "\(base) api rejected some items")
74+
MixpanelLogger.info(message: "\(base) api rejected some items")
7575
}
7676
completion(true)
7777
})

Sources/JSONHandler.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class JSONHandler {
1616
let data: Data? = serializeJSONObject(obj)
1717

1818
guard let d = data else {
19-
Logger.warn(message: "couldn't serialize object")
19+
MixpanelLogger.warn(message: "couldn't serialize object")
2020
return nil
2121
}
2222

@@ -28,7 +28,7 @@ class JSONHandler {
2828
do {
2929
object = try JSONSerialization.jsonObject(with: data, options: [])
3030
} catch {
31-
Logger.warn(message: "exception decoding object data")
31+
MixpanelLogger.warn(message: "exception decoding object data")
3232
}
3333
return object
3434
}
@@ -44,7 +44,7 @@ class JSONHandler {
4444
}
4545

4646
guard JSONSerialization.isValidJSONObject(serializableJSONObject) else {
47-
Logger.warn(message: "object isn't valid and can't be serialzed to JSON")
47+
MixpanelLogger.warn(message: "object isn't valid and can't be serialzed to JSON")
4848
return nil
4949
}
5050

@@ -53,7 +53,7 @@ class JSONHandler {
5353
serializedObject = try JSONSerialization
5454
.data(withJSONObject: serializableJSONObject, options: [])
5555
} catch {
56-
Logger.warn(message: "exception encoding api data")
56+
MixpanelLogger.warn(message: "exception encoding api data")
5757
}
5858
return serializedObject
5959
}
@@ -110,7 +110,7 @@ class JSONHandler {
110110
// all nil properties outside of Arrays are converted to NSNull()
111111
return NSNull()
112112
} else {
113-
Logger.info(message: "enforcing string on object")
113+
MixpanelLogger.info(message: "enforcing string on object")
114114
return objString
115115
}
116116
}

Sources/MPDB.swift

+15-15
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,28 @@ class MPDB {
4545
}
4646

4747
private func reconnect() {
48-
Logger.warn(message: "No database connection found. Calling MPDB.open()")
48+
MixpanelLogger.warn(message: "No database connection found. Calling MPDB.open()")
4949
open()
5050
}
5151

5252
func open() {
5353
if apiToken.isEmpty {
54-
Logger.error(message: "Project token must not be empty. Database cannot be opened.")
54+
MixpanelLogger.error(message: "Project token must not be empty. Database cannot be opened.")
5555
return
5656
}
5757
if let dbPath = pathToDb() {
5858
if sqlite3_open_v2(dbPath, &connection, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nil) != SQLITE_OK {
5959
logSqlError(message: "Error opening or creating database at path: \(dbPath)")
6060
close()
6161
} else {
62-
Logger.info(message: "Successfully opened connection to database at path: \(dbPath)")
62+
MixpanelLogger.info(message: "Successfully opened connection to database at path: \(dbPath)")
6363
if let db = connection {
6464
let pragmaString = "PRAGMA journal_mode=WAL;"
6565
var pragmaStatement: OpaquePointer?
6666
if sqlite3_prepare_v2(db, pragmaString, -1, &pragmaStatement, nil) == SQLITE_OK {
6767
if sqlite3_step(pragmaStatement) == SQLITE_ROW {
6868
let res = String(cString: sqlite3_column_text(pragmaStatement, 0))
69-
Logger.info(message: "SQLite journal mode set to \(res)")
69+
MixpanelLogger.info(message: "SQLite journal mode set to \(res)")
7070
} else {
7171
logSqlError(message: "Failed to enable journal_mode=WAL")
7272
}
@@ -85,7 +85,7 @@ class MPDB {
8585
func close() {
8686
sqlite3_close(connection)
8787
connection = nil
88-
Logger.info(message: "Connection to database closed.")
88+
MixpanelLogger.info(message: "Connection to database closed.")
8989
}
9090

9191
private func recreate() {
@@ -95,10 +95,10 @@ class MPDB {
9595
let manager = FileManager.default
9696
if manager.fileExists(atPath: dbPath) {
9797
try manager.removeItem(atPath: dbPath)
98-
Logger.info(message: "Deleted database file at path: \(dbPath)")
98+
MixpanelLogger.info(message: "Deleted database file at path: \(dbPath)")
9999
}
100100
} catch let error {
101-
Logger.error(message: "Unable to remove database file at path: \(dbPath), error: \(error)")
101+
MixpanelLogger.error(message: "Unable to remove database file at path: \(dbPath), error: \(error)")
102102
}
103103
}
104104
reconnect()
@@ -112,7 +112,7 @@ class MPDB {
112112
var createTableStatement: OpaquePointer?
113113
if sqlite3_prepare_v2(db, createTableString, -1, &createTableStatement, nil) == SQLITE_OK {
114114
if sqlite3_step(createTableStatement) == SQLITE_DONE {
115-
Logger.info(message: "\(tableName) table created")
115+
MixpanelLogger.info(message: "\(tableName) table created")
116116
} else {
117117
logSqlError(message: "\(tableName) table create failed")
118118
}
@@ -133,7 +133,7 @@ class MPDB {
133133
var createIndexStatement: OpaquePointer?
134134
if sqlite3_prepare_v2(db, createIndexString, -1, &createIndexStatement, nil) == SQLITE_OK {
135135
if sqlite3_step(createIndexStatement) == SQLITE_DONE {
136-
Logger.info(message: "\(indexName) index created")
136+
MixpanelLogger.info(message: "\(indexName) index created")
137137
} else {
138138
logSqlError(message: "\(indexName) index creation failed")
139139
}
@@ -167,7 +167,7 @@ class MPDB {
167167
sqlite3_bind_int(insertStatement, 2, flag ? 1 : 0)
168168
sqlite3_bind_double(insertStatement, 3, Date().timeIntervalSince1970)
169169
if sqlite3_step(insertStatement) == SQLITE_DONE {
170-
Logger.info(message: "Successfully inserted row into table \(tableName)")
170+
MixpanelLogger.info(message: "Successfully inserted row into table \(tableName)")
171171
} else {
172172
logSqlError(message: "Failed to insert row into table \(tableName)")
173173
recreate()
@@ -191,7 +191,7 @@ class MPDB {
191191
var deleteStatement: OpaquePointer?
192192
if sqlite3_prepare_v2(db, deleteString, -1, &deleteStatement, nil) == SQLITE_OK {
193193
if sqlite3_step(deleteStatement) == SQLITE_DONE {
194-
Logger.info(message: "Successfully deleted rows from table \(tableName)")
194+
MixpanelLogger.info(message: "Successfully deleted rows from table \(tableName)")
195195
} else {
196196
logSqlError(message: "Failed to delete rows from table \(tableName)")
197197
recreate()
@@ -223,7 +223,7 @@ class MPDB {
223223
var updateStatement: OpaquePointer?
224224
if sqlite3_prepare_v2(db, updateString, -1, &updateStatement, nil) == SQLITE_OK {
225225
if sqlite3_step(updateStatement) == SQLITE_DONE {
226-
Logger.info(message: "Successfully updated rows from table \(tableName)")
226+
MixpanelLogger.info(message: "Successfully updated rows from table \(tableName)")
227227
} else {
228228
logSqlError(message: "Failed to update rows from table \(tableName)")
229229
recreate()
@@ -266,7 +266,7 @@ class MPDB {
266266
}
267267
}
268268
if rowsRead > 0 {
269-
Logger.info(message: "Successfully read \(rowsRead) from table \(tableName)")
269+
MixpanelLogger.info(message: "Successfully read \(rowsRead) from table \(tableName)")
270270
}
271271
} else {
272272
logSqlError(message: "SELECT statement for table \(tableName) could not be prepared")
@@ -281,10 +281,10 @@ class MPDB {
281281
private func logSqlError(message: String? = nil) {
282282
if let db = connection {
283283
if let msg = message {
284-
Logger.error(message: msg)
284+
MixpanelLogger.error(message: msg)
285285
}
286286
let sqlError = String(cString: sqlite3_errmsg(db)!)
287-
Logger.error(message: sqlError)
287+
MixpanelLogger.error(message: sqlError)
288288
} else {
289289
reconnect()
290290
}

Sources/Mixpanel.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ final class MixpanelManager {
248248

249249
init() {
250250
instances = [String: MixpanelInstance]()
251-
Logger.addLogging(PrintLogging())
251+
MixpanelLogger.addLogging(PrintLogging())
252252
readWriteLock = ReadWriteLock(label: "com.mixpanel.instance.manager.lock")
253253
instanceQueue = DispatchQueue(label: "com.mixpanel.instance.manager.instance", qos: .utility, autoreleaseFrequency: .workItem)
254254
}
@@ -318,7 +318,7 @@ final class MixpanelManager {
318318
instance = instances[instanceName]
319319
}
320320
if instance == nil {
321-
Logger.warn(message: "no such instance: \(instanceName)")
321+
MixpanelLogger.warn(message: "no such instance: \(instanceName)")
322322
return nil
323323
}
324324
return instance

0 commit comments

Comments
 (0)