cordova-plugin-unvired-logger 0.0.7 → 0.0.8
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/browser/Logger.js +32 -26
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.8",
|
|
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.8"
|
|
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/browser/Logger.js
CHANGED
|
@@ -16,15 +16,15 @@ const getStorageKey = (userId, fileName) => `unvired_logger_${userId}_${fileName
|
|
|
16
16
|
const getLogLevelKey = (userId) => `unvired_logger_${userId}_level`;
|
|
17
17
|
|
|
18
18
|
module.exports.logDebug = async function (successCallback, errorCallback, args) {
|
|
19
|
-
|
|
19
|
+
await logWitLevel(successCallback, errorCallback, args);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
module.exports.logError = async function (successCallback, errorCallback, args) {
|
|
23
|
-
|
|
23
|
+
await logWitLevel(successCallback, errorCallback, args);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
module.exports.logInfo = async function (successCallback, errorCallback, args) {
|
|
27
|
-
|
|
27
|
+
await logWitLevel(successCallback, errorCallback, args);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
module.exports.setLogLevel = function(successCallback, errorCallback, level) {
|
|
@@ -97,6 +97,19 @@ module.exports.copyLogToBackup = async function(successCallback, errorCallback,
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
module.exports.loggerWithLevel = async function(successCallback, errorCallback, args) {
|
|
100
|
+
await logWitLevel(successCallback, errorCallback, args)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports.getStringFromLevel = async function (successCallback, errorCallback, level) {
|
|
104
|
+
switch (level) {
|
|
105
|
+
case LogLevel.Info: successCallback('IMPORTANT');return;
|
|
106
|
+
case LogLevel.Error: successCallback('ERROR');return;
|
|
107
|
+
case LogLevel.Debug: successCallback('DEBUG');return;
|
|
108
|
+
default: successCallback('');return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
async function logWitLevel(successCallback, errorCallback, args) {
|
|
100
113
|
try {
|
|
101
114
|
if (!args || !args[0]) {
|
|
102
115
|
return errorCallback(new Error("Invalid arguments provided"));
|
|
@@ -164,30 +177,23 @@ module.exports.loggerWithLevel = async function(successCallback, errorCallback,
|
|
|
164
177
|
}
|
|
165
178
|
}
|
|
166
179
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (content.length > MAX_LOG_SIZE) {
|
|
183
|
-
const backupStorageKey = getStorageKey(userId, BACKUP_LOG_FILE_NAME);
|
|
184
|
-
localStorage.setItem(backupStorageKey, content);
|
|
185
|
-
localStorage.setItem(storageKey, '');
|
|
180
|
+
async function checkAndRotateLogFile (successCallback, errorCallback, args) {
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
try {
|
|
183
|
+
const userId = args[0].userId;
|
|
184
|
+
const storageKey = getStorageKey(userId, LOG_FILE_NAME);
|
|
185
|
+
const content = localStorage.getItem(storageKey) || '';
|
|
186
|
+
|
|
187
|
+
if (content.length > MAX_LOG_SIZE) {
|
|
188
|
+
const backupStorageKey = getStorageKey(userId, BACKUP_LOG_FILE_NAME);
|
|
189
|
+
localStorage.setItem(backupStorageKey, content);
|
|
190
|
+
localStorage.setItem(storageKey, '');
|
|
191
|
+
}
|
|
192
|
+
resolve();
|
|
193
|
+
} catch (err) {
|
|
194
|
+
reject(new Error(`Failed to rotate log file: ${err.message}`));
|
|
186
195
|
}
|
|
187
|
-
|
|
188
|
-
} catch (err) {
|
|
189
|
-
errorCallback(new Error(`Failed to rotate log file: ${err.message}`));
|
|
190
|
-
}
|
|
196
|
+
})
|
|
191
197
|
}
|
|
192
198
|
|
|
193
199
|
require('cordova/exec/proxy').add('Logger', module.exports);
|