diff --git a/MixpanelDemo/MixpanelDemoTests/LoggerTests.swift b/MixpanelDemo/MixpanelDemoTests/LoggerTests.swift index 62867bf4..3b2c86e9 100644 --- a/MixpanelDemo/MixpanelDemoTests/LoggerTests.swift +++ b/MixpanelDemo/MixpanelDemoTests/LoggerTests.swift @@ -15,63 +15,63 @@ class LoggerTests: XCTestCase { func testEnableDebug() { let counter = CounterLogging() - Logger.addLogging(counter) - Logger.enableLevel(.debug) + MPLogger.addLogging(counter) + MPLogger.enableLevel(.debug) - Logger.debug(message: "logged") + MPLogger.debug(message: "logged") XCTAssertEqual(1, counter.count) } func testEnableInfo() { let counter = CounterLogging() - Logger.addLogging(counter) - Logger.enableLevel(.info) - Logger.info(message: "logged") + MPLogger.addLogging(counter) + MPLogger.enableLevel(.info) + MPLogger.info(message: "logged") XCTAssertEqual(1, counter.count) } func testEnableWarning() { let counter = CounterLogging() - Logger.addLogging(counter) - Logger.enableLevel(.warning) - Logger.warn(message: "logged") + MPLogger.addLogging(counter) + MPLogger.enableLevel(.warning) + MPLogger.warn(message: "logged") XCTAssertEqual(1, counter.count) } func testEnableError() { let counter = CounterLogging() - Logger.addLogging(counter) - Logger.enableLevel(.error) - Logger.error(message: "logged") + MPLogger.addLogging(counter) + MPLogger.enableLevel(.error) + MPLogger.error(message: "logged") XCTAssertEqual(1, counter.count) } func testDisabledLogging() { let counter = CounterLogging() - Logger.addLogging(counter) - Logger.disableLevel(.debug) - Logger.debug(message: "not logged") + MPLogger.addLogging(counter) + MPLogger.disableLevel(.debug) + MPLogger.debug(message: "not logged") XCTAssertEqual(0, counter.count) - Logger.disableLevel(.error) - Logger.error(message: "not logged") + MPLogger.disableLevel(.error) + MPLogger.error(message: "not logged") XCTAssertEqual(0, counter.count) - Logger.disableLevel(.info) - Logger.info(message: "not logged") + MPLogger.disableLevel(.info) + MPLogger.info(message: "not logged") XCTAssertEqual(0, counter.count) - Logger.disableLevel(.warning) - Logger.warn(message: "not logged") + MPLogger.disableLevel(.warning) + MPLogger.warn(message: "not logged") XCTAssertEqual(0, counter.count) } } /// This is a stub that implements `Logging` to be passed to our `Logger` instance for testing -class CounterLogging: Logging { +class CounterLogging: MPLogging { var count = 0 - func addMessage(message: LogMessage) { + func addMessage(message: MPLogMessage) { count = count + 1 } } diff --git a/Sources/Error.swift b/Sources/Error.swift index 1a5d6f1b..8046c44b 100644 --- a/Sources/Error.swift +++ b/Sources/Error.swift @@ -36,7 +36,7 @@ class ErrorHandler { class func logError(_ error: Error) { let stackSymbols = Thread.callStackSymbols - Logger.error(message: "Error: \(error) \n Stack Symbols: \(stackSymbols)") + MPLogger.error(message: "Error: \(error) \n Stack Symbols: \(stackSymbols)") } } diff --git a/Sources/FileLogging.swift b/Sources/FileLogging.swift index 868a521d..46e3d722 100644 --- a/Sources/FileLogging.swift +++ b/Sources/FileLogging.swift @@ -9,7 +9,7 @@ import Foundation /// Logs all messages to a file -class FileLogging: Logging { +class FileLogging: MPLogging { private let fileHandle: FileHandle init(path: String) { @@ -28,7 +28,7 @@ class FileLogging: Logging { fileHandle.closeFile() } - func addMessage(message: LogMessage) { + func addMessage(message: MPLogMessage) { let string = "File: \(message.file) - Func: \(message.function) - " + "Level: \(message.level.rawValue) - Message: \(message.text)" if let data = string.data(using: String.Encoding.utf8) { diff --git a/Sources/Flush.swift b/Sources/Flush.swift index a11618bb..10026095 100644 --- a/Sources/Flush.swift +++ b/Sources/Flush.swift @@ -122,8 +122,8 @@ class Flush: AppLifecycle { (entity["id"] as? Int32) ?? 0 } // Log data payload sent - Logger.debug(message: "Sending batch of data") - Logger.debug(message: batch as Any) + MPLogger.debug(message: "Sending batch of data") + MPLogger.debug(message: batch as Any) let requestData = JSONHandler.encodeAPIData(batch) if let requestData = requestData { #if os(iOS) diff --git a/Sources/FlushRequest.swift b/Sources/FlushRequest.swift index bf260364..7d8b1d5d 100644 --- a/Sources/FlushRequest.swift +++ b/Sources/FlushRequest.swift @@ -65,13 +65,13 @@ class FlushRequest: Network { failure: { (reason, _, response) in self.networkConsecutiveFailures += 1 self.updateRetryDelay(response) - Logger.warn(message: "API request to \(resource.path) has failed with reason \(reason)") + MPLogger.warn(message: "API request to \(resource.path) has failed with reason \(reason)") completion(false) }, success: { (result, response) in self.networkConsecutiveFailures = 0 self.updateRetryDelay(response) if result == 0 { - Logger.info(message: "\(base) api rejected some items") + MPLogger.info(message: "\(base) api rejected some items") } completion(true) }) diff --git a/Sources/JSONHandler.swift b/Sources/JSONHandler.swift index 78b61fc6..28dc5746 100644 --- a/Sources/JSONHandler.swift +++ b/Sources/JSONHandler.swift @@ -16,7 +16,7 @@ class JSONHandler { let data: Data? = serializeJSONObject(obj) guard let d = data else { - Logger.warn(message: "couldn't serialize object") + MPLogger.warn(message: "couldn't serialize object") return nil } @@ -28,7 +28,7 @@ class JSONHandler { do { object = try JSONSerialization.jsonObject(with: data, options: []) } catch { - Logger.warn(message: "exception decoding object data") + MPLogger.warn(message: "exception decoding object data") } return object } @@ -44,7 +44,7 @@ class JSONHandler { } guard JSONSerialization.isValidJSONObject(serializableJSONObject) else { - Logger.warn(message: "object isn't valid and can't be serialzed to JSON") + MPLogger.warn(message: "object isn't valid and can't be serialzed to JSON") return nil } @@ -53,7 +53,7 @@ class JSONHandler { serializedObject = try JSONSerialization .data(withJSONObject: serializableJSONObject, options: []) } catch { - Logger.warn(message: "exception encoding api data") + MPLogger.warn(message: "exception encoding api data") } return serializedObject } @@ -110,7 +110,7 @@ class JSONHandler { // all nil properties outside of Arrays are converted to NSNull() return NSNull() } else { - Logger.info(message: "enforcing string on object") + MPLogger.info(message: "enforcing string on object") return objString } } diff --git a/Sources/MPDB.swift b/Sources/MPDB.swift index e5ab9e65..aea93578 100644 --- a/Sources/MPDB.swift +++ b/Sources/MPDB.swift @@ -45,13 +45,13 @@ class MPDB { } private func reconnect() { - Logger.warn(message: "No database connection found. Calling MPDB.open()") + MPLogger.warn(message: "No database connection found. Calling MPDB.open()") open() } func open() { if apiToken.isEmpty { - Logger.error(message: "Project token must not be empty. Database cannot be opened.") + MPLogger.error(message: "Project token must not be empty. Database cannot be opened.") return } if let dbPath = pathToDb() { @@ -59,14 +59,14 @@ class MPDB { logSqlError(message: "Error opening or creating database at path: \(dbPath)") close() } else { - Logger.info(message: "Successfully opened connection to database at path: \(dbPath)") + MPLogger.info(message: "Successfully opened connection to database at path: \(dbPath)") if let db = connection { let pragmaString = "PRAGMA journal_mode=WAL;" var pragmaStatement: OpaquePointer? if sqlite3_prepare_v2(db, pragmaString, -1, &pragmaStatement, nil) == SQLITE_OK { if sqlite3_step(pragmaStatement) == SQLITE_ROW { let res = String(cString: sqlite3_column_text(pragmaStatement, 0)) - Logger.info(message: "SQLite journal mode set to \(res)") + MPLogger.info(message: "SQLite journal mode set to \(res)") } else { logSqlError(message: "Failed to enable journal_mode=WAL") } @@ -85,7 +85,7 @@ class MPDB { func close() { sqlite3_close(connection) connection = nil - Logger.info(message: "Connection to database closed.") + MPLogger.info(message: "Connection to database closed.") } private func recreate() { @@ -95,10 +95,10 @@ class MPDB { let manager = FileManager.default if manager.fileExists(atPath: dbPath) { try manager.removeItem(atPath: dbPath) - Logger.info(message: "Deleted database file at path: \(dbPath)") + MPLogger.info(message: "Deleted database file at path: \(dbPath)") } } catch let error { - Logger.error(message: "Unable to remove database file at path: \(dbPath), error: \(error)") + MPLogger.error(message: "Unable to remove database file at path: \(dbPath), error: \(error)") } } reconnect() @@ -112,7 +112,7 @@ class MPDB { var createTableStatement: OpaquePointer? if sqlite3_prepare_v2(db, createTableString, -1, &createTableStatement, nil) == SQLITE_OK { if sqlite3_step(createTableStatement) == SQLITE_DONE { - Logger.info(message: "\(tableName) table created") + MPLogger.info(message: "\(tableName) table created") } else { logSqlError(message: "\(tableName) table create failed") } @@ -133,7 +133,7 @@ class MPDB { var createIndexStatement: OpaquePointer? if sqlite3_prepare_v2(db, createIndexString, -1, &createIndexStatement, nil) == SQLITE_OK { if sqlite3_step(createIndexStatement) == SQLITE_DONE { - Logger.info(message: "\(indexName) index created") + MPLogger.info(message: "\(indexName) index created") } else { logSqlError(message: "\(indexName) index creation failed") } @@ -167,7 +167,7 @@ class MPDB { sqlite3_bind_int(insertStatement, 2, flag ? 1 : 0) sqlite3_bind_double(insertStatement, 3, Date().timeIntervalSince1970) if sqlite3_step(insertStatement) == SQLITE_DONE { - Logger.info(message: "Successfully inserted row into table \(tableName)") + MPLogger.info(message: "Successfully inserted row into table \(tableName)") } else { logSqlError(message: "Failed to insert row into table \(tableName)") recreate() @@ -191,7 +191,7 @@ class MPDB { var deleteStatement: OpaquePointer? if sqlite3_prepare_v2(db, deleteString, -1, &deleteStatement, nil) == SQLITE_OK { if sqlite3_step(deleteStatement) == SQLITE_DONE { - Logger.info(message: "Successfully deleted rows from table \(tableName)") + MPLogger.info(message: "Successfully deleted rows from table \(tableName)") } else { logSqlError(message: "Failed to delete rows from table \(tableName)") recreate() @@ -223,7 +223,7 @@ class MPDB { var updateStatement: OpaquePointer? if sqlite3_prepare_v2(db, updateString, -1, &updateStatement, nil) == SQLITE_OK { if sqlite3_step(updateStatement) == SQLITE_DONE { - Logger.info(message: "Successfully updated rows from table \(tableName)") + MPLogger.info(message: "Successfully updated rows from table \(tableName)") } else { logSqlError(message: "Failed to update rows from table \(tableName)") recreate() @@ -266,7 +266,7 @@ class MPDB { } } if rowsRead > 0 { - Logger.info(message: "Successfully read \(rowsRead) from table \(tableName)") + MPLogger.info(message: "Successfully read \(rowsRead) from table \(tableName)") } } else { logSqlError(message: "SELECT statement for table \(tableName) could not be prepared") @@ -281,10 +281,10 @@ class MPDB { private func logSqlError(message: String? = nil) { if let db = connection { if let msg = message { - Logger.error(message: msg) + MPLogger.error(message: msg) } let sqlError = String(cString: sqlite3_errmsg(db)!) - Logger.error(message: sqlError) + MPLogger.error(message: sqlError) } else { reconnect() } diff --git a/Sources/Logger.swift b/Sources/MPLogger.swift similarity index 76% rename from Sources/Logger.swift rename to Sources/MPLogger.swift index 3c974ad0..32cecfc1 100644 --- a/Sources/Logger.swift +++ b/Sources/MPLogger.swift @@ -1,5 +1,5 @@ // -// Logger.swift +// MPLogger.swift // Logger // // Created by Sam Green on 7/8/16. @@ -10,7 +10,7 @@ import Foundation /// This defines the various levels of logging that a message may be tagged with. This allows hiding and /// showing different logging levels at run time depending on the environment -public enum LogLevel: String { +public enum MPLogLevel: String { /// Logging displays *all* logs and additional debug information that may be useful to a developer case debug @@ -26,7 +26,7 @@ public enum LogLevel: String { /// This holds all the data for each log message, since the formatting is up to each /// logging object. It is a simple bag of data -public struct LogMessage { +public struct MPLogMessage { /// The file where this log message was created public let file: String @@ -37,9 +37,9 @@ public struct LogMessage { public let text: String /// The level of the log message - public let level: LogLevel + public let level: MPLogLevel - init(path: String, function: String, text: String, level: LogLevel) { + init(path: String, function: String, text: String, level: MPLogLevel) { if let file = path.components(separatedBy: "/").last { self.file = file } else { @@ -52,31 +52,31 @@ public struct LogMessage { } /// Any object that conforms to this protocol may log messages -public protocol Logging { - func addMessage(message: LogMessage) +public protocol MPLogging { + func addMessage(message: MPLogMessage) } -public class Logger { - private static var loggers = [Logging]() - private static var enabledLevels = Set() - private static let readWriteLock: ReadWriteLock = ReadWriteLock(label: "loggerLock") +public class MPLogger { + private static var loggers = [MPLogging]() + private static var enabledLevels = Set() + private static let readWriteLock: ReadWriteLock = ReadWriteLock(label: "mpLoggerLock") /// Add a `Logging` object to receive all log messages - public class func addLogging(_ logging: Logging) { + public class func addLogging(_ logging: MPLogging) { readWriteLock.write { loggers.append(logging) } } /// Enable log messages of a specific `LogLevel` to be added to the log - class func enableLevel(_ level: LogLevel) { + class func enableLevel(_ level: MPLogLevel) { readWriteLock.write { enabledLevels.insert(level) } } /// Disable log messages of a specific `LogLevel` to prevent them from being logged - class func disableLevel(_ level: LogLevel) { + class func disableLevel(_ level: MPLogLevel) { readWriteLock.write { enabledLevels.remove(level) } @@ -85,55 +85,55 @@ public class Logger { /// debug: Adds a debug message to the Mixpanel log /// - Parameter message: The message to be added to the log class func debug(message: @autoclosure() -> Any, _ path: String = #file, _ function: String = #function) { - var enabledLevels = Set() + var enabledLevels = Set() readWriteLock.read { enabledLevels = self.enabledLevels } guard enabledLevels.contains(.debug) else { return } - forwardLogMessage(LogMessage(path: path, function: function, text: "\(message())", + forwardLogMessage(MPLogMessage(path: path, function: function, text: "\(message())", level: .debug)) } /// info: Adds an informational message to the Mixpanel log /// - Parameter message: The message to be added to the log class func info(message: @autoclosure() -> Any, _ path: String = #file, _ function: String = #function) { - var enabledLevels = Set() + var enabledLevels = Set() readWriteLock.read { enabledLevels = self.enabledLevels } guard enabledLevels.contains(.info) else { return } - forwardLogMessage(LogMessage(path: path, function: function, text: "\(message())", + forwardLogMessage(MPLogMessage(path: path, function: function, text: "\(message())", level: .info)) } /// warn: Adds a warning message to the Mixpanel log /// - Parameter message: The message to be added to the log class func warn(message: @autoclosure() -> Any, _ path: String = #file, _ function: String = #function) { - var enabledLevels = Set() + var enabledLevels = Set() readWriteLock.read { enabledLevels = self.enabledLevels } guard enabledLevels.contains(.warning) else { return } - forwardLogMessage(LogMessage(path: path, function: function, text: "\(message())", + forwardLogMessage(MPLogMessage(path: path, function: function, text: "\(message())", level: .warning)) } /// error: Adds an error message to the Mixpanel log /// - Parameter message: The message to be added to the log class func error(message: @autoclosure() -> Any, _ path: String = #file, _ function: String = #function) { - var enabledLevels = Set() + var enabledLevels = Set() readWriteLock.read { enabledLevels = self.enabledLevels } guard enabledLevels.contains(.error) else { return } - forwardLogMessage(LogMessage(path: path, function: function, text: "\(message())", + forwardLogMessage(MPLogMessage(path: path, function: function, text: "\(message())", level: .error)) } /// This forwards a `LogMessage` to each logger that has been added - class private func forwardLogMessage(_ message: LogMessage) { + class private func forwardLogMessage(_ message: MPLogMessage) { // Forward the log message to every registered Logging instance - var loggers = [Logging]() + var loggers = [MPLogging]() readWriteLock.read { loggers = self.loggers } diff --git a/Sources/Mixpanel.swift b/Sources/Mixpanel.swift index 0c5f4766..e5e3b674 100644 --- a/Sources/Mixpanel.swift +++ b/Sources/Mixpanel.swift @@ -248,7 +248,7 @@ final class MixpanelManager { init() { instances = [String: MixpanelInstance]() - Logger.addLogging(PrintLogging()) + MPLogger.addLogging(PrintLogging()) readWriteLock = ReadWriteLock(label: "com.mixpanel.instance.manager.lock") instanceQueue = DispatchQueue(label: "com.mixpanel.instance.manager.instance", qos: .utility, autoreleaseFrequency: .workItem) } @@ -318,7 +318,7 @@ final class MixpanelManager { instance = instances[instanceName] } if instance == nil { - Logger.warn(message: "no such instance: \(instanceName)") + MPLogger.warn(message: "no such instance: \(instanceName)") return nil } return instance diff --git a/Sources/MixpanelInstance.swift b/Sources/MixpanelInstance.swift index bda85a8f..cf3acf4f 100644 --- a/Sources/MixpanelInstance.swift +++ b/Sources/MixpanelInstance.swift @@ -188,17 +188,17 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele open var loggingEnabled: Bool = false { didSet { if loggingEnabled { - Logger.enableLevel(.debug) - Logger.enableLevel(.info) - Logger.enableLevel(.warning) - Logger.enableLevel(.error) - Logger.info(message: "Logging Enabled") + MPLogger.enableLevel(.debug) + MPLogger.enableLevel(.info) + MPLogger.enableLevel(.warning) + MPLogger.enableLevel(.error) + MPLogger.info(message: "Logging Enabled") } else { - Logger.info(message: "Logging Disabled") - Logger.disableLevel(.debug) - Logger.disableLevel(.info) - Logger.disableLevel(.warning) - Logger.disableLevel(.error) + MPLogger.info(message: "Logging Disabled") + MPLogger.disableLevel(.debug) + MPLogger.disableLevel(.info) + MPLogger.disableLevel(.warning) + MPLogger.disableLevel(.error) } #if DEBUG var trackProps: Properties = ["Logging Enabled": loggingEnabled] @@ -351,7 +351,7 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele AutomaticProperties.automaticPropertiesLock.write { AutomaticProperties.properties["$wifi"] = wifi } - Logger.info(message: "reachability changed, wifi=\(wifi)") + MPLogger.info(message: "reachability changed, wifi=\(wifi)") } if SCNetworkReachabilitySetCallback(reachability, reachabilityCallback, &context) { if !SCNetworkReachabilitySetDispatchQueue(reachability, trackingQueue) { @@ -456,10 +456,10 @@ open class MixpanelInstance: CustomDebugStringConvertible, FlushDelegate, AEDele #if os(iOS) && !os(watchOS) && !targetEnvironment(macCatalyst) if let reachability = MixpanelInstance.reachability { if !SCNetworkReachabilitySetCallback(reachability, nil, nil) { - Logger.error(message: "\(self) error unsetting reachability callback") + MPLogger.error(message: "\(self) error unsetting reachability callback") } if !SCNetworkReachabilitySetDispatchQueue(reachability, nil) { - Logger.error(message: "\(self) error unsetting reachability dispatch queue") + MPLogger.error(message: "\(self) error unsetting reachability dispatch queue") } } #endif @@ -701,7 +701,7 @@ extension MixpanelInstance { return } if distinctId.isEmpty { - Logger.error(message: "\(self) cannot identify blank distinct id") + MPLogger.error(message: "\(self) cannot identify blank distinct id") if let completion = completion { DispatchQueue.main.async(execute: completion) } @@ -791,7 +791,7 @@ extension MixpanelInstance { } if distinctId.isEmpty { - Logger.error(message: "\(self) cannot identify blank distinct id") + MPLogger.error(message: "\(self) cannot identify blank distinct id") if let completion = completion { DispatchQueue.main.async(execute: completion) } @@ -799,7 +799,7 @@ extension MixpanelInstance { } if alias.isEmpty { - Logger.error(message: "\(self) create alias called with empty alias") + MPLogger.error(message: "\(self) create alias called with empty alias") if let completion = completion { DispatchQueue.main.async(execute: completion) } @@ -850,7 +850,7 @@ extension MixpanelInstance { } flush(completion: completion) } else { - Logger.error(message: "alias: \(alias) matches distinctId: \(distinctId) - skipping api call.") + MPLogger.error(message: "alias: \(alias) matches distinctId: \(distinctId) - skipping api call.") if let completion = completion { DispatchQueue.main.async(execute: completion) } @@ -1159,7 +1159,7 @@ extension MixpanelInstance { if !(group.groupKey == groupKey && group.groupID.equals(rhs: groupID)) { // we somehow hit a collision on the map key, return a new group with the correct key and ID - Logger.info(message: "groups dictionary key collision: \(key)") + MPLogger.info(message: "groups dictionary key collision: \(key)") let newGroup = Group(apiToken: apiToken, serialQueue: trackingQueue, lock: self.readWriteLock, diff --git a/Sources/MixpanelPersistence.swift b/Sources/MixpanelPersistence.swift index c6a6a1b0..61a081a2 100644 --- a/Sources/MixpanelPersistence.swift +++ b/Sources/MixpanelPersistence.swift @@ -139,7 +139,7 @@ class MixpanelPersistence { defaults.set(timedEventsData, forKey: "\(prefix)\(MixpanelUserDefaultsKeys.timedEvents)") defaults.synchronize() } catch { - Logger.warn(message: "Failed to archive timed events") + MPLogger.warn(message: "Failed to archive timed events") } } @@ -154,7 +154,7 @@ class MixpanelPersistence { do { return try NSKeyedUnarchiver.unarchivedObject(ofClasses: archivedClasses, from: timedEventsData) as? InternalProperties ?? InternalProperties() } catch { - Logger.warn(message: "Failed to unarchive timed events") + MPLogger.warn(message: "Failed to unarchive timed events") return InternalProperties() } } @@ -169,7 +169,7 @@ class MixpanelPersistence { defaults.set(superPropertiesData, forKey: "\(prefix)\(MixpanelUserDefaultsKeys.superProperties)") defaults.synchronize() } catch { - Logger.warn(message: "Failed to archive super properties") + MPLogger.warn(message: "Failed to archive super properties") } } @@ -184,7 +184,7 @@ class MixpanelPersistence { do { return try NSKeyedUnarchiver.unarchivedObject(ofClasses: archivedClasses, from: superPropertiesData) as? InternalProperties ?? InternalProperties() } catch { - Logger.warn(message: "Failed to unarchive super properties") + MPLogger.warn(message: "Failed to unarchive super properties") return InternalProperties() } } @@ -355,14 +355,14 @@ class MixpanelPersistence { if #available(iOS 11.0, macOS 10.13, watchOS 4.0, tvOS 11.0, *) { guard let data = try? Data(contentsOf: URL(fileURLWithPath: filePath)), let unarchivedData = try? NSKeyedUnarchiver.unarchivedObject(ofClasses: MixpanelPersistence.archivedClasses, from: data) else { - Logger.info(message: "Unable to read file at path: \(filePath)") + MPLogger.info(message: "Unable to read file at path: \(filePath)") removeArchivedFile(atPath: filePath) return nil } return unarchivedData } else { guard let unarchivedData = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) else { - Logger.info(message: "Unable to read file at path: \(filePath)") + MPLogger.info(message: "Unable to read file at path: \(filePath)") removeArchivedFile(atPath: filePath) return nil } @@ -374,7 +374,7 @@ class MixpanelPersistence { do { try FileManager.default.removeItem(atPath: filePath) } catch let err { - Logger.info(message: "Unable to remove file at path: \(filePath), error: \(err)") + MPLogger.info(message: "Unable to remove file at path: \(filePath), error: \(err)") } } @@ -440,12 +440,12 @@ class MixpanelPersistence { private func unarchiveWithType(_ type: String) -> Any? { let filePath = filePathWithType(type) guard let path = filePath else { - Logger.info(message: "bad file path, cant fetch file") + MPLogger.info(message: "bad file path, cant fetch file") return nil } guard let unarchivedData = unarchiveWithFilePath(path) else { - Logger.info(message: "can't unarchive file") + MPLogger.info(message: "can't unarchive file") return nil } diff --git a/Sources/Network.swift b/Sources/Network.swift index f4620144..3d5fba0f 100644 --- a/Sources/Network.swift +++ b/Sources/Network.swift @@ -107,8 +107,8 @@ class Network { return nil } - Logger.debug(message: "Fetching URL") - Logger.debug(message: url.absoluteURL) + MPLogger.debug(message: "Fetching URL") + MPLogger.debug(message: url.absoluteURL) var request = URLRequest(url: url) request.httpMethod = resource.method.rawValue request.httpBody = resource.requestBody diff --git a/Sources/PrintLogging.swift b/Sources/PrintLogging.swift index b1c8d4a9..732c27d5 100644 --- a/Sources/PrintLogging.swift +++ b/Sources/PrintLogging.swift @@ -9,16 +9,16 @@ import Foundation /// Simply formats and prints the object by calling `print` -class PrintLogging: Logging { - func addMessage(message: LogMessage) { +class PrintLogging: MPLogging { + func addMessage(message: MPLogMessage) { print("[Mixpanel - \(message.file) - func \(message.function)] (\(message.level.rawValue)) - \(message.text)") } } /// Simply formats and prints the object by calling `debugPrint`, this makes things a bit easier if you /// need to print data that may be quoted for instance. -class PrintDebugLogging: Logging { - func addMessage(message: LogMessage) { +class PrintDebugLogging: MPLogging { + func addMessage(message: MPLogMessage) { debugPrint("[Mixpanel - \(message.file) - func \(message.function)] (\(message.level.rawValue)) - \(message.text)") } } diff --git a/Sources/Track.swift b/Sources/Track.swift index ffc64143..eeb445eb 100644 --- a/Sources/Track.swift +++ b/Sources/Track.swift @@ -41,7 +41,7 @@ class Track { if let event = event { ev = event } else { - Logger.info(message: "mixpanel track called with empty event parameter. using 'mp_event'") + MPLogger.info(message: "mixpanel track called with empty event parameter. using 'mp_event'") } if !(mixpanelInstance?.trackAutomaticEventsEnabled ?? false) && ev.hasPrefix("$ae_") { return timedEvents @@ -140,7 +140,7 @@ class Track { } var updatedTimedEvents = timedEvents guard let event = event, !event.isEmpty else { - Logger.error(message: "mixpanel cannot time an empty event") + MPLogger.error(message: "mixpanel cannot time an empty event") return updatedTimedEvents } updatedTimedEvents[event] = startTime @@ -156,7 +156,7 @@ class Track { func clearTimedEvent(event: String?, timedEvents: InternalProperties) -> InternalProperties { var updatedTimedEvents = timedEvents guard let event = event, !event.isEmpty else { - Logger.error(message: "mixpanel cannot clear an empty timed event") + MPLogger.error(message: "mixpanel cannot clear an empty timed event") return updatedTimedEvents } updatedTimedEvents.removeValue(forKey: event)