     }
     
     func writeLogs() {
-        
-        self.logDispatchQueue.addOperation{ [weak self, weak socketManager] in
-            guard let logsToShip = self?.logsToShip else { return }
-            guard let dataToShip = self?.dataToShip else { return }
+        logDispatchQueue.addOperation{ [weak socketManager, logsToShip] in
             guard let socketManager = socketManager else { return }
 
             for log in logsToShip.sorted(by: { $0.0 < $1.0 }) {
-                let logData = dataToShip(log.1)
+                let logData: Data = { dict in
+                    var data = Data()
+                    do {
+                        data = try JSONSerialization.data(withJSONObject:dict, options:[])
+                        if let encodedData = "\n".data(using: String.Encoding.utf8) {
+                            data.append(encodedData)
+                        }
+                    } catch {
+                        print(error.localizedDescription)
+                    }
+                    return data
+                }(log.value)
                 socketManager.write(logData, withTimeout: socketManager.timeout, tag: log.0)
             }
             


    public func forceSend(_ completionHandler: @escaping (_ error: Error?) -> Void  = {_ in }) {
        
        if self.logsToShip.count == 0 || self.socketManager.isConnected() {
            completionHandler(nil)
            return
        }

        let logTag = Int(truncatingBitPattern: time)
        logsToShip[logTag] = dict
    }
}

// MARK: - GCDAsyncSocketManager Delegate
