cordova-plugin-unvired-logger 0.0.11 → 0.0.13

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/README.md CHANGED
@@ -200,12 +200,12 @@ testLogger();
200
200
  ## Platform-Specific Details
201
201
 
202
202
  ### Android
203
- - Logs are stored in the app's internal storage: `/data/data/[package]/files/[userId]/AppLogs/`
203
+ - Logs are stored in the app's internal storage: `/data/data/[package]/files/[userId]/`
204
204
  - Requires storage permissions for external storage access
205
205
  - Automatic log rotation when file size exceeds 5MB
206
206
 
207
207
  ### iOS
208
- - Logs are stored in the app's Documents directory: `Documents/[userId]/AppLogs/`
208
+ - Logs are stored in the app's Documents directory: `Documents/[userId]/`
209
209
  - Uses native Swift implementation for optimal performance
210
210
  - Automatic log rotation when file size exceeds 5MB
211
211
 
@@ -230,14 +230,13 @@ testLogger();
230
230
 
231
231
  Logs are stored in the following structure:
232
232
  ```
233
- {userDataPath}/{userId}/AppLogs/log.txt
234
- {userDataPath}/{userId}/AppLogs/log_backup.txt
233
+ {userDataPath}/{userId}/log.txt
234
+ {userDataPath}/{userId}/log_backup.txt
235
235
  ```
236
236
 
237
237
  Where:
238
238
  - `userDataPath` is the Electron app's user data directory
239
- - `userId` is the user identifier you provide
240
- - `AppLogs` is the log folder name
239
+ - `userId` is the log folder name
241
240
  - `log.txt` is the current log file
242
241
  - `log_backup.txt` is the backup file (created during rotation)
243
242
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-unvired-logger",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
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.11"
2
+ <plugin id="cordova-plugin-unvired-logger" version="0.0.13"
3
3
  xmlns="http://apache.org/cordova/ns/plugins/1.0"
4
4
  xmlns:android="http://schemas.android.com/apk/res/android">
5
5
 
@@ -16,7 +16,6 @@ import java.util.Locale;
16
16
 
17
17
  public class Logger extends CordovaPlugin {
18
18
 
19
- private static final String LOG_FOLDER_NAME = "AppLogs";
20
19
  private static final String LOG_FILE_NAME = "log.txt";
21
20
  private static final String BACKUP_LOG_FILE_NAME = "log_backup.txt";
22
21
  private static final long MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
@@ -203,7 +202,7 @@ public class Logger extends CordovaPlugin {
203
202
 
204
203
  private File getUserLogDir(String userId) {
205
204
  Context ctx = cordova.getActivity().getApplicationContext();
206
- File userDir = new File(ctx.getFilesDir(), userId + File.separator + LOG_FOLDER_NAME);
205
+ File userDir = new File(ctx.getFilesDir(), userId);
207
206
  if (!userDir.exists()) userDir.mkdirs();
208
207
  return userDir;
209
208
  }
@@ -1,4 +1,3 @@
1
- const LOG_FOLDER_NAME = 'AppLogs';
2
1
  const LOG_FILE_NAME = 'log.txt';
3
2
  const BACKUP_LOG_FILE_NAME = 'log_backup.txt';
4
3
  const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
@@ -32,7 +32,6 @@ async function withLogLock(fn) {
32
32
  return operationPromise;
33
33
  }
34
34
 
35
- const LOG_FOLDER_NAME = 'log';
36
35
  const LOG_FILE_NAME = 'log.txt';
37
36
  const BACKUP_LOG_FILE_NAME = 'log_backup.txt';
38
37
 
@@ -183,7 +182,7 @@ function getLogDirectory(args) {
183
182
  }
184
183
  const userId = args[0].userId;
185
184
  const userDataPath = app.getPath('userData');
186
- const userPath = path.join(userDataPath, userId, LOG_FOLDER_NAME);
185
+ const userPath = path.join(userDataPath, userId);
187
186
  if (!fs.existsSync(userPath)) {
188
187
  fs.mkdirSync(userPath, { recursive: true });
189
188
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-unvired-logger",
3
- "version": "@PACKAGE_NUMBER@",
3
+ "version": "0.0.13",
4
4
  "description": "Electron platform package for cordova-plugin-unvired-logger",
5
5
  "main": "Logger.js",
6
6
  "scripts": {
@@ -3,7 +3,6 @@ import UIKit
3
3
 
4
4
  @objc(Logger) class Logger : CDVPlugin {
5
5
 
6
- private let LOG_FOLDER_NAME = "AppLogs"
7
6
  private let LOG_FILE_NAME = "log.txt"
8
7
  private let BACKUP_LOG_FILE_NAME = "log_backup.txt"
9
8
  private let MAX_LOG_SIZE: Int64 = 5 * 1024 * 1024 // 5MB
@@ -214,7 +213,7 @@ import UIKit
214
213
 
215
214
  private func getUserLogDir(userId: String) throws -> URL {
216
215
  let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
217
- let userDir = documentsPath.appendingPathComponent(userId).appendingPathComponent(LOG_FOLDER_NAME)
216
+ let userDir = documentsPath.appendingPathComponent(userId)
218
217
 
219
218
  if !FileManager.default.fileExists(atPath: userDir.path) {
220
219
  try FileManager.default.createDirectory(at: userDir, withIntermediateDirectories: true, attributes: nil)
@@ -259,6 +258,11 @@ import UIKit
259
258
  }
260
259
 
261
260
  private func appendToFile(file: URL, data: String) throws {
261
+ let fileManager = FileManager.default
262
+ if !fileManager.fileExists(atPath: file.path) {
263
+ // Create the file if it doesn't exist
264
+ fileManager.createFile(atPath: file.path, contents: nil, attributes: nil)
265
+ }
262
266
  let fileHandle = try FileHandle(forWritingTo: file)
263
267
  fileHandle.seekToEndOfFile()
264
268
  fileHandle.write(data.data(using: .utf8)!)