cordova-plugin-unvired-logger 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/electron/package.json +1 -1
- package/src/ios/Logger.swift +32 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cordova-plugin-unvired-logger",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "A logger plugin for Electron, Android, Browser, and iOS that appends logs to log.txt files organized by user ID.",
|
|
5
5
|
"cordova": {
|
|
6
6
|
"id": "cordova-plugin-unvired-logger",
|
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<plugin id="cordova-plugin-unvired-logger" version="0.0.
|
|
2
|
+
<plugin id="cordova-plugin-unvired-logger" version="0.0.14"
|
|
3
3
|
xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
4
4
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
5
5
|
|
package/src/ios/Logger.swift
CHANGED
|
@@ -8,6 +8,7 @@ import UIKit
|
|
|
8
8
|
private let MAX_LOG_SIZE: Int64 = 5 * 1024 * 1024 // 5MB
|
|
9
9
|
|
|
10
10
|
private var defaultLogLevel: String = "important"
|
|
11
|
+
private let fileWriteQueue = DispatchQueue(label: "com.logger.filewrite", qos: .background)
|
|
11
12
|
|
|
12
13
|
@objc(logDebug:)
|
|
13
14
|
func logDebug(_ command: CDVInvokedUrlCommand) {
|
|
@@ -60,9 +61,16 @@ import UIKit
|
|
|
60
61
|
try checkAndRotateLogFile(logFile: logFile, userId: userId)
|
|
61
62
|
|
|
62
63
|
let logEntry = formatLogEntry(level: level, sourceClass: sourceClass, sourceMethod: sourceMethod, message: message)
|
|
63
|
-
try appendToFile(file: logFile, data: logEntry)
|
|
64
64
|
|
|
65
|
+
// Send success result immediately without waiting for file write
|
|
65
66
|
sendSuccessResult(command.callbackId, message: "Logged to \(logFile.path)")
|
|
67
|
+
|
|
68
|
+
// Perform file write in background with silent error handling
|
|
69
|
+
appendToFile(file: logFile, data: logEntry) { error in
|
|
70
|
+
if let error = error {
|
|
71
|
+
print("Background logging error: \(error.localizedDescription)")
|
|
72
|
+
}
|
|
73
|
+
}
|
|
66
74
|
} catch {
|
|
67
75
|
sendErrorResult(command.callbackId, message: "Logging failed: \(error.localizedDescription)")
|
|
68
76
|
}
|
|
@@ -257,16 +265,30 @@ import UIKit
|
|
|
257
265
|
}
|
|
258
266
|
}
|
|
259
267
|
|
|
260
|
-
private func appendToFile(file: URL, data: String)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
268
|
+
private func appendToFile(file: URL, data: String, completion: @escaping (Error?) -> Void = { _ in }) {
|
|
269
|
+
fileWriteQueue.async {
|
|
270
|
+
do {
|
|
271
|
+
let fileManager = FileManager.default
|
|
272
|
+
if !fileManager.fileExists(atPath: file.path) {
|
|
273
|
+
// Create the file if it doesn't exist
|
|
274
|
+
fileManager.createFile(atPath: file.path, contents: nil, attributes: nil)
|
|
275
|
+
}
|
|
276
|
+
let fileHandle = try FileHandle(forWritingTo: file)
|
|
277
|
+
fileHandle.seekToEndOfFile()
|
|
278
|
+
fileHandle.write(data.data(using: .utf8)!)
|
|
279
|
+
fileHandle.closeFile()
|
|
280
|
+
|
|
281
|
+
// Notify success on main thread
|
|
282
|
+
DispatchQueue.main.async {
|
|
283
|
+
completion(nil)
|
|
284
|
+
}
|
|
285
|
+
} catch {
|
|
286
|
+
// Notify error on main thread
|
|
287
|
+
DispatchQueue.main.async {
|
|
288
|
+
completion(error)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
265
291
|
}
|
|
266
|
-
let fileHandle = try FileHandle(forWritingTo: file)
|
|
267
|
-
fileHandle.seekToEndOfFile()
|
|
268
|
-
fileHandle.write(data.data(using: .utf8)!)
|
|
269
|
-
fileHandle.closeFile()
|
|
270
292
|
}
|
|
271
293
|
|
|
272
294
|
private func readFile(file: URL) throws -> String {
|