cordova-plugin-unvired-logger 0.0.9 → 0.0.11
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 +5 -5
- package/package.json +1 -1
- package/plugin.xml +11 -11
- package/src/android/{UnviredLogger.java → Logger.java} +5 -5
- package/src/browser/Logger.js +17 -17
- package/src/electron/Logger.js +95 -88
- package/src/electron/package.json +1 -1
- package/src/ios/{UnviredLogger.swift → Logger.swift} +5 -5
- package/www/logger.js +13 -13
package/README.md
CHANGED
|
@@ -128,7 +128,7 @@ Logger.getBackupLogFileContent("user123",
|
|
|
128
128
|
```javascript
|
|
129
129
|
function testLogger() {
|
|
130
130
|
if (window && Logger) {
|
|
131
|
-
console.log("Testing
|
|
131
|
+
console.log("Testing Logger plugin...");
|
|
132
132
|
|
|
133
133
|
// Test basic logging
|
|
134
134
|
Logger.logInfo("testuser", "AuthService", "login", "User login successful",
|
|
@@ -170,7 +170,7 @@ function testLogger() {
|
|
|
170
170
|
}
|
|
171
171
|
);
|
|
172
172
|
} else {
|
|
173
|
-
console.warn("
|
|
173
|
+
console.warn("Logger not available.");
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
|
|
@@ -256,9 +256,9 @@ Where:
|
|
|
256
256
|
- `logError(userId, sourceClass, sourceMethod, message, success, error)` - Log error message
|
|
257
257
|
|
|
258
258
|
### Constants
|
|
259
|
-
- `
|
|
260
|
-
- `
|
|
261
|
-
- `
|
|
259
|
+
- `Logger.LogLevel.Debug` - Debug log level
|
|
260
|
+
- `Logger.LogLevel.Info` - Info log level
|
|
261
|
+
- `Logger.LogLevel.Error` - Error log level
|
|
262
262
|
|
|
263
263
|
## Requirements
|
|
264
264
|
|
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.11",
|
|
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,12 +1,12 @@
|
|
|
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.11"
|
|
3
3
|
xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
4
4
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
5
5
|
|
|
6
|
-
<name>
|
|
6
|
+
<name>Logger</name>
|
|
7
7
|
<description>A logger plugin for Android, iOS, Electron, and Browser that appends logs to log.txt files organized by user ID.</description>
|
|
8
8
|
|
|
9
|
-
<js-module src="www/logger.js" name="
|
|
9
|
+
<js-module src="www/logger.js" name="Logger">
|
|
10
10
|
<clobbers target="Logger" />
|
|
11
11
|
</js-module>
|
|
12
12
|
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
|
|
17
17
|
<platform name="android">
|
|
18
18
|
<config-file target="res/xml/config.xml" parent="/*">
|
|
19
|
-
<feature name="
|
|
20
|
-
<param name="android-package" value="cordova.plugin.unvired.logger.
|
|
19
|
+
<feature name="Logger">
|
|
20
|
+
<param name="android-package" value="cordova.plugin.unvired.logger.Logger" />
|
|
21
21
|
</feature>
|
|
22
22
|
</config-file>
|
|
23
23
|
|
|
24
|
-
<source-file src="src/android/
|
|
24
|
+
<source-file src="src/android/Logger.java" target-dir="src/cordova/plugin/unvired/logger" />
|
|
25
25
|
|
|
26
26
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
|
27
27
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
@@ -30,20 +30,20 @@
|
|
|
30
30
|
|
|
31
31
|
<platform name="ios">
|
|
32
32
|
<config-file target="config.xml" parent="/*">
|
|
33
|
-
<feature name="
|
|
34
|
-
<param name="ios-package" value="
|
|
33
|
+
<feature name="Logger">
|
|
34
|
+
<param name="ios-package" value="Logger" />
|
|
35
35
|
</feature>
|
|
36
36
|
</config-file>
|
|
37
37
|
|
|
38
|
-
<source-file src="src/ios/
|
|
38
|
+
<source-file src="src/ios/Logger.swift" />
|
|
39
39
|
|
|
40
40
|
<framework src="Foundation.framework" />
|
|
41
41
|
<framework src="UIKit.framework" />
|
|
42
42
|
</platform>
|
|
43
43
|
|
|
44
44
|
<platform name="browser">
|
|
45
|
-
<js-module src="src/browser/Logger.js" name="
|
|
46
|
-
<
|
|
45
|
+
<js-module src="src/browser/Logger.js" name="LoggerProxy">
|
|
46
|
+
<runs />
|
|
47
47
|
</js-module>
|
|
48
48
|
</platform>
|
|
49
49
|
</plugin>
|
|
@@ -14,14 +14,14 @@ import java.text.SimpleDateFormat;
|
|
|
14
14
|
import java.util.Date;
|
|
15
15
|
import java.util.Locale;
|
|
16
16
|
|
|
17
|
-
public class
|
|
17
|
+
public class Logger extends CordovaPlugin {
|
|
18
18
|
|
|
19
19
|
private static final String LOG_FOLDER_NAME = "AppLogs";
|
|
20
20
|
private static final String LOG_FILE_NAME = "log.txt";
|
|
21
21
|
private static final String BACKUP_LOG_FILE_NAME = "log_backup.txt";
|
|
22
22
|
private static final long MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
|
|
23
23
|
|
|
24
|
-
private String defaultLogLevel = "
|
|
24
|
+
private String defaultLogLevel = "important";
|
|
25
25
|
|
|
26
26
|
@Override
|
|
27
27
|
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
|
|
@@ -111,8 +111,8 @@ public class UnviredLogger extends CordovaPlugin {
|
|
|
111
111
|
private boolean shouldSkipLog(String level) {
|
|
112
112
|
String normLevel = level.toLowerCase();
|
|
113
113
|
String normDefault = defaultLogLevel.toLowerCase();
|
|
114
|
-
if (normDefault.equals("error") && (normLevel.equals("debug") || normLevel.equals("
|
|
115
|
-
if (normDefault.equals("
|
|
114
|
+
if (normDefault.equals("error") && (normLevel.equals("debug") || normLevel.equals("important"))) return true;
|
|
115
|
+
if (normDefault.equals("important") && normLevel.equals("debug")) return true;
|
|
116
116
|
return false;
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -229,7 +229,7 @@ public class UnviredLogger extends CordovaPlugin {
|
|
|
229
229
|
|
|
230
230
|
private String getStringFromLevel(String level) {
|
|
231
231
|
switch (level.toLowerCase()) {
|
|
232
|
-
case "
|
|
232
|
+
case "important": return "IMPORTANT";
|
|
233
233
|
case "error": return "ERROR";
|
|
234
234
|
case "debug": return "DEBUG";
|
|
235
235
|
default: return "";
|
package/src/browser/Logger.js
CHANGED
|
@@ -6,7 +6,7 @@ const MAX_LOG_SIZE = 5 * 1024 * 1024; // 5MB
|
|
|
6
6
|
const LogLevel = {
|
|
7
7
|
Debug: 'debug',
|
|
8
8
|
Error: 'error',
|
|
9
|
-
Info: '
|
|
9
|
+
Info: 'important',
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
let defaultLogLevel = LogLevel.Info;
|
|
@@ -29,12 +29,12 @@ module.exports.logInfo = async function (successCallback, errorCallback, args) {
|
|
|
29
29
|
|
|
30
30
|
module.exports.setLogLevel = function(successCallback, errorCallback, level) {
|
|
31
31
|
// If level is an array (from Cordova), extract the first element
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
successCallback("")
|
|
32
|
+
let levelToSet = Array.isArray(level) ? level[0] : level;
|
|
33
|
+
|
|
34
|
+
// Normalize the level to lowercase for consistency
|
|
35
|
+
defaultLogLevel = (levelToSet || '').toLowerCase();
|
|
36
|
+
|
|
37
|
+
successCallback("");
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
module.exports.getLogLevel = function(successCallback, errorCallback) {
|
|
@@ -100,12 +100,12 @@ module.exports.loggerWithLevel = async function(successCallback, errorCallback,
|
|
|
100
100
|
await logWitLevel(successCallback, errorCallback, args)
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
function getStringFromLevel(level) {
|
|
104
104
|
switch (level) {
|
|
105
|
-
case LogLevel.Info:
|
|
106
|
-
case LogLevel.Error:
|
|
107
|
-
case LogLevel.Debug:
|
|
108
|
-
default:
|
|
105
|
+
case LogLevel.Info: return 'IMPORTANT';
|
|
106
|
+
case LogLevel.Error: return 'ERROR';
|
|
107
|
+
case LogLevel.Debug: return 'DEBUG';
|
|
108
|
+
default: return '';
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -117,9 +117,9 @@ async function logWitLevel(successCallback, errorCallback, args) {
|
|
|
117
117
|
|
|
118
118
|
const { userId, level, sourceClass, sourceMethod, message } = args[0];
|
|
119
119
|
|
|
120
|
-
if (!userId) return
|
|
121
|
-
if (!level) return
|
|
122
|
-
if (!message) return
|
|
120
|
+
if (!userId) return errorCallback(new Error("userId is required"));
|
|
121
|
+
if (!level) return errorCallback(new Error("level is required"));
|
|
122
|
+
if (!message) return errorCallback(new Error("message is required"));
|
|
123
123
|
|
|
124
124
|
// Normalize log levels for comparison
|
|
125
125
|
const normalizedDefaultLogLevel = (defaultLogLevel || '').toLowerCase();
|
|
@@ -177,7 +177,7 @@ async function logWitLevel(successCallback, errorCallback, args) {
|
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
async function checkAndRotateLogFile (
|
|
180
|
+
async function checkAndRotateLogFile (args) {
|
|
181
181
|
return new Promise((resolve, reject) => {
|
|
182
182
|
try {
|
|
183
183
|
const userId = args[0].userId;
|
|
@@ -196,4 +196,4 @@ async function checkAndRotateLogFile (successCallback, errorCallback, args) {
|
|
|
196
196
|
})
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
require('cordova/exec/proxy').add('
|
|
199
|
+
require('cordova/exec/proxy').add('Logger', module.exports);
|
package/src/electron/Logger.js
CHANGED
|
@@ -3,6 +3,35 @@ const path = require('path');
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const fsPromises = fs.promises;
|
|
5
5
|
|
|
6
|
+
// --- Proper async lock for log file operations ---
|
|
7
|
+
let logLockPromise = Promise.resolve();
|
|
8
|
+
let isLocked = false;
|
|
9
|
+
|
|
10
|
+
async function withLogLock(fn) {
|
|
11
|
+
// Wait for any existing lock to complete
|
|
12
|
+
await logLockPromise;
|
|
13
|
+
|
|
14
|
+
// Create a new promise for this operation
|
|
15
|
+
const operationPromise = (async () => {
|
|
16
|
+
try {
|
|
17
|
+
isLocked = true;
|
|
18
|
+
const result = await fn();
|
|
19
|
+
return result;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error('[Logger] Error in log operation:', error);
|
|
22
|
+
// Return error message instead of throwing to prevent unhandled promise rejections
|
|
23
|
+
return `Error in log operation: ${error.message}`;
|
|
24
|
+
} finally {
|
|
25
|
+
isLocked = false;
|
|
26
|
+
}
|
|
27
|
+
})();
|
|
28
|
+
|
|
29
|
+
// Update the lock promise to wait for this operation
|
|
30
|
+
logLockPromise = operationPromise;
|
|
31
|
+
|
|
32
|
+
return operationPromise;
|
|
33
|
+
}
|
|
34
|
+
|
|
6
35
|
const LOG_FOLDER_NAME = 'log';
|
|
7
36
|
const LOG_FILE_NAME = 'log.txt';
|
|
8
37
|
const BACKUP_LOG_FILE_NAME = 'log_backup.txt';
|
|
@@ -10,7 +39,7 @@ const BACKUP_LOG_FILE_NAME = 'log_backup.txt';
|
|
|
10
39
|
const LogLevel = {
|
|
11
40
|
Debug: 'debug',
|
|
12
41
|
Error: 'error',
|
|
13
|
-
Info: '
|
|
42
|
+
Info: 'important',
|
|
14
43
|
};
|
|
15
44
|
|
|
16
45
|
let defaultLogLevel = LogLevel.Info;
|
|
@@ -29,15 +58,11 @@ function logInfo(args) {
|
|
|
29
58
|
}
|
|
30
59
|
|
|
31
60
|
function setLogLevel(level) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
defaultLogLevel = level;
|
|
38
|
-
}
|
|
39
|
-
resolve();
|
|
40
|
-
});
|
|
61
|
+
// If level is an array (from Cordova), extract the first element
|
|
62
|
+
let levelToSet = Array.isArray(level) ? level[0] : level;
|
|
63
|
+
|
|
64
|
+
// Normalize the level to lowercase for consistency
|
|
65
|
+
defaultLogLevel = (levelToSet || '').toLowerCase();
|
|
41
66
|
}
|
|
42
67
|
|
|
43
68
|
function getLogLevel() {
|
|
@@ -68,14 +93,10 @@ function getLogFileContent(args) {
|
|
|
68
93
|
}
|
|
69
94
|
|
|
70
95
|
function clearLogFile(args) {
|
|
71
|
-
return
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
resolve();
|
|
76
|
-
} catch (err) {
|
|
77
|
-
reject(new Error(`Failed to clear log file: ${err.message}`));
|
|
78
|
-
}
|
|
96
|
+
return withLogLock(async () => {
|
|
97
|
+
const logPath = getLogFileURL(args);
|
|
98
|
+
await fsPromises.writeFile(logPath, '');
|
|
99
|
+
return 'Log file cleared successfully';
|
|
79
100
|
});
|
|
80
101
|
}
|
|
81
102
|
|
|
@@ -101,69 +122,58 @@ function getBackupLogFileContent(args) {
|
|
|
101
122
|
}
|
|
102
123
|
|
|
103
124
|
function copyLogToBackup(args) {
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
resolve();
|
|
110
|
-
} catch (err) {
|
|
111
|
-
reject(new Error(`Failed to copy log file to backup: ${err.message}`));
|
|
112
|
-
}
|
|
125
|
+
return withLogLock(async () => {
|
|
126
|
+
const logPath = getLogFileURL(args);
|
|
127
|
+
const backupPath = getBackupLogFileURL(args);
|
|
128
|
+
await fsPromises.copyFile(logPath, backupPath);
|
|
129
|
+
return 'Log file copied to backup successfully';
|
|
113
130
|
});
|
|
114
131
|
}
|
|
115
132
|
|
|
116
133
|
function loggerWithLevel(args) {
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
(normalizedDefaultLogLevel === LogLevel.Info && normalizedLevel === LogLevel.Debug)
|
|
136
|
-
) {
|
|
137
|
-
return resolve();
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
await checkAndRotateLogFile(args);
|
|
134
|
+
return withLogLock(async () => {
|
|
135
|
+
if (!args || !args[0]) throw new Error("Invalid arguments provided");
|
|
136
|
+
const { userId, level, sourceClass, sourceMethod, message } = args[0];
|
|
137
|
+
if (!userId) throw new Error("userId is required");
|
|
138
|
+
if (!level) throw new Error("level is required");
|
|
139
|
+
if (!message) throw new Error("message is required");
|
|
140
|
+
|
|
141
|
+
// Normalize log levels for comparison
|
|
142
|
+
const normalizedDefaultLogLevel = (defaultLogLevel || '').toLowerCase();
|
|
143
|
+
const normalizedLevel = (level || '').toLowerCase();
|
|
144
|
+
|
|
145
|
+
// Log level filtering using normalized values
|
|
146
|
+
if (
|
|
147
|
+
(normalizedDefaultLogLevel === LogLevel.Error && (normalizedLevel === LogLevel.Debug || normalizedLevel === LogLevel.Info)) ||
|
|
148
|
+
(normalizedDefaultLogLevel === LogLevel.Info && normalizedLevel === LogLevel.Debug)
|
|
149
|
+
) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
141
152
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
await fsPromises.appendFile(logPath, data, 'utf8');
|
|
163
|
-
resolve(`Logged to ${logPath}`);
|
|
164
|
-
} catch (err) {
|
|
165
|
-
reject(new Error(`Logging failed: ${err.message}`));
|
|
153
|
+
await checkAndRotateLogFile(args);
|
|
154
|
+
|
|
155
|
+
const logPath = getLogFileURL(args);
|
|
156
|
+
const currentDate = new Date();
|
|
157
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
158
|
+
day: '2-digit', month: '2-digit', year: 'numeric',
|
|
159
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit'
|
|
160
|
+
});
|
|
161
|
+
const localDateString = formatter.format(currentDate);
|
|
162
|
+
|
|
163
|
+
const dateUtc = new Date(currentDate.toUTCString());
|
|
164
|
+
const utcFormatter = new Intl.DateTimeFormat('en-US', {
|
|
165
|
+
day: '2-digit', month: '2-digit', year: 'numeric',
|
|
166
|
+
hour: '2-digit', minute: '2-digit', second: '2-digit', timeZone: 'UTC'
|
|
167
|
+
});
|
|
168
|
+
const utcDateString = utcFormatter.format(dateUtc);
|
|
169
|
+
|
|
170
|
+
let data = `${localDateString} | UTC:${utcDateString} | ${getStringFromLevel(level)} | ${sourceClass} | ${sourceMethod} | ${message}\n`;
|
|
171
|
+
if (level === LogLevel.Error) {
|
|
172
|
+
data = `⭕️⭕️⭕️ ${data}`;
|
|
166
173
|
}
|
|
174
|
+
console.log(data);
|
|
175
|
+
await fsPromises.appendFile(logPath, data, 'utf8');
|
|
176
|
+
return `Logged to ${logPath}`;
|
|
167
177
|
});
|
|
168
178
|
}
|
|
169
179
|
|
|
@@ -190,21 +200,18 @@ function getStringFromLevel(level) {
|
|
|
190
200
|
}
|
|
191
201
|
|
|
192
202
|
function checkAndRotateLogFile(args) {
|
|
193
|
-
return
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
+
return withLogLock(async () => {
|
|
204
|
+
const logPath = getLogFileURL(args);
|
|
205
|
+
if (fs.existsSync(logPath)) {
|
|
206
|
+
const stats = await fsPromises.stat(logPath);
|
|
207
|
+
if (stats.size > MAX_LOG_SIZE) {
|
|
208
|
+
const backupPath = getBackupLogFileURL(args);
|
|
209
|
+
await fsPromises.copyFile(logPath, backupPath);
|
|
210
|
+
await fsPromises.writeFile(logPath, '');
|
|
211
|
+
return 'Log file rotated due to size limit';
|
|
203
212
|
}
|
|
204
|
-
resolve();
|
|
205
|
-
} catch (err) {
|
|
206
|
-
reject(new Error(`Failed to rotate log file: ${err.message}`));
|
|
207
213
|
}
|
|
214
|
+
return 'Log file rotation check completed';
|
|
208
215
|
});
|
|
209
216
|
}
|
|
210
217
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import UIKit
|
|
3
3
|
|
|
4
|
-
@objc(
|
|
4
|
+
@objc(Logger) class Logger : CDVPlugin {
|
|
5
5
|
|
|
6
6
|
private let LOG_FOLDER_NAME = "AppLogs"
|
|
7
7
|
private let LOG_FILE_NAME = "log.txt"
|
|
8
8
|
private let BACKUP_LOG_FILE_NAME = "log_backup.txt"
|
|
9
9
|
private let MAX_LOG_SIZE: Int64 = 5 * 1024 * 1024 // 5MB
|
|
10
10
|
|
|
11
|
-
private var defaultLogLevel: String = "
|
|
11
|
+
private var defaultLogLevel: String = "important"
|
|
12
12
|
|
|
13
13
|
@objc(logDebug:)
|
|
14
14
|
func logDebug(_ command: CDVInvokedUrlCommand) {
|
|
@@ -193,10 +193,10 @@ import UIKit
|
|
|
193
193
|
let normLevel = level.lowercased()
|
|
194
194
|
let normDefault = defaultLogLevel.lowercased()
|
|
195
195
|
|
|
196
|
-
if normDefault == "error" && (normLevel == "debug" || normLevel == "
|
|
196
|
+
if normDefault == "error" && (normLevel == "debug" || normLevel == "important") {
|
|
197
197
|
return true
|
|
198
198
|
}
|
|
199
|
-
if normDefault == "
|
|
199
|
+
if normDefault == "important" && normLevel == "debug" {
|
|
200
200
|
return true
|
|
201
201
|
}
|
|
202
202
|
return false
|
|
@@ -251,7 +251,7 @@ import UIKit
|
|
|
251
251
|
|
|
252
252
|
private func getStringFromLevel(level: String) -> String {
|
|
253
253
|
switch level.lowercased() {
|
|
254
|
-
case "
|
|
254
|
+
case "important": return "IMPORTANT"
|
|
255
255
|
case "error": return "ERROR"
|
|
256
256
|
case "debug": return "DEBUG"
|
|
257
257
|
default: return ""
|
package/www/logger.js
CHANGED
|
@@ -4,7 +4,7 @@ var exec = require('cordova/exec');
|
|
|
4
4
|
exports.LogLevel = {
|
|
5
5
|
Debug: 'debug',
|
|
6
6
|
Error: 'error',
|
|
7
|
-
Info: '
|
|
7
|
+
Info: 'important'
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -20,7 +20,7 @@ exports.LogLevel = {
|
|
|
20
20
|
const logFolder = "LogFiles"
|
|
21
21
|
|
|
22
22
|
exports.loggerWithLevel = function (level, sourceClass, sourceMethod, message, success, error) {
|
|
23
|
-
exec(success, error, '
|
|
23
|
+
exec(success, error, 'Logger', 'loggerWithLevel', [{ userId: logFolder, level: level, sourceClass: sourceClass, sourceMethod: sourceMethod, message: message }]);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -34,7 +34,7 @@ exports.setLogLevel = function (level, success, error) {
|
|
|
34
34
|
if (error) error('Log level is required');
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
exec(success, error, '
|
|
37
|
+
exec(success, error, 'Logger', 'setLogLevel', [level]);
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -43,7 +43,7 @@ exports.setLogLevel = function (level, success, error) {
|
|
|
43
43
|
* @param {function} error - Error callback
|
|
44
44
|
*/
|
|
45
45
|
exports.getLogFileContent = function (success, error) {
|
|
46
|
-
exec(success, error, '
|
|
46
|
+
exec(success, error, 'Logger', 'getLogFileContent', [{ userId: logFolder }]);
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
/**
|
|
@@ -52,7 +52,7 @@ exports.getLogFileContent = function (success, error) {
|
|
|
52
52
|
* @param {function} error - Error callback
|
|
53
53
|
*/
|
|
54
54
|
exports.clearLogFile = function (success, error) {
|
|
55
|
-
exec(success, error, '
|
|
55
|
+
exec(success, error, 'Logger', 'clearLogFile', [{ userId: logFolder}]);
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
/**
|
|
@@ -61,7 +61,7 @@ exports.clearLogFile = function (success, error) {
|
|
|
61
61
|
* @param {function} error - Error callback
|
|
62
62
|
*/
|
|
63
63
|
exports.getBackupLogFileContent = function (success, error) {
|
|
64
|
-
exec(success, error, '
|
|
64
|
+
exec(success, error, 'Logger', 'getBackupLogFileContent', [{ userId: logFolder }]);
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
/**
|
|
@@ -70,7 +70,7 @@ exports.getBackupLogFileContent = function (success, error) {
|
|
|
70
70
|
* @param {function} error - Error callback
|
|
71
71
|
*/
|
|
72
72
|
exports.copyLogToBackup = function (success, error) {
|
|
73
|
-
exec(success, error, '
|
|
73
|
+
exec(success, error, 'Logger', 'copyLogToBackup', [{ userId: logFolder }]);
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
/**
|
|
@@ -81,7 +81,7 @@ exports.logDebug = function (sourceClass, sourceMethod, message, success, error)
|
|
|
81
81
|
if (error) error('Message is required');
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
|
-
exec(success, error, '
|
|
84
|
+
exec(success, error, 'Logger', 'logDebug', [{
|
|
85
85
|
userId: logFolder,
|
|
86
86
|
level: exports.LogLevel.Debug,
|
|
87
87
|
message: message,
|
|
@@ -95,7 +95,7 @@ exports.logInfo = function (sourceClass, sourceMethod, message, success, error)
|
|
|
95
95
|
if (error) error('Message is required');
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
|
-
exec(success, error, '
|
|
98
|
+
exec(success, error, 'Logger', 'logInfo', [{
|
|
99
99
|
userId: logFolder,
|
|
100
100
|
level: exports.LogLevel.Info,
|
|
101
101
|
message: message,
|
|
@@ -109,7 +109,7 @@ exports.logError = function (sourceClass, sourceMethod, message, success, error)
|
|
|
109
109
|
if (error) error('Message is required');
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
|
-
exec(success, error, '
|
|
112
|
+
exec(success, error, 'Logger', 'logError', [{
|
|
113
113
|
userId: logFolder,
|
|
114
114
|
level: exports.LogLevel.Error,
|
|
115
115
|
message: message,
|
|
@@ -119,13 +119,13 @@ exports.logError = function (sourceClass, sourceMethod, message, success, error)
|
|
|
119
119
|
};
|
|
120
120
|
|
|
121
121
|
exports.getLogFileURL = function (success, error) {
|
|
122
|
-
exec(success, error, '
|
|
122
|
+
exec(success, error, 'Logger', 'getLogFileURL', [{ userId: logFolder }]);
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
exports.getBackupLogFileURL = function (success, error) {
|
|
126
|
-
exec(success, error, '
|
|
126
|
+
exec(success, error, 'Logger', 'getBackupLogFileURL', [{ userId: logFolder }]);
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
exports.getLogLevel = function (success, error) {
|
|
130
|
-
exec(success, error, '
|
|
130
|
+
exec(success, error, 'Logger', 'getLogLevel', []);
|
|
131
131
|
};
|