backend-manager 3.2.173 → 3.2.174
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/src/manager/helpers/assistant.js +51 -76
- package/src/manager/index.js +22 -1
package/package.json
CHANGED
|
@@ -4,6 +4,17 @@ const _ = require('lodash');
|
|
|
4
4
|
const uuid = require('uuid');
|
|
5
5
|
let JSON5;
|
|
6
6
|
|
|
7
|
+
const LOG_LEVELS = {
|
|
8
|
+
error: 'error',
|
|
9
|
+
warn: 'warn',
|
|
10
|
+
info: 'info',
|
|
11
|
+
debug: 'debug',
|
|
12
|
+
log: 'log',
|
|
13
|
+
notice: 'NOTICE',
|
|
14
|
+
critical: 'CRITICAL',
|
|
15
|
+
emergency: 'EMERGENCY'
|
|
16
|
+
};
|
|
17
|
+
|
|
7
18
|
function BackendAssistant() {
|
|
8
19
|
const self = this;
|
|
9
20
|
|
|
@@ -12,7 +23,24 @@ function BackendAssistant() {
|
|
|
12
23
|
self.initialized = false;
|
|
13
24
|
|
|
14
25
|
// Add log methods
|
|
15
|
-
|
|
26
|
+
Object.keys(LOG_LEVELS)
|
|
27
|
+
.forEach((level) => {
|
|
28
|
+
// Skip log because it is already a method
|
|
29
|
+
// if (level === 'log') {
|
|
30
|
+
// return;
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
// Add log method
|
|
34
|
+
BackendAssistant.prototype[level] = function() {
|
|
35
|
+
const self = this;
|
|
36
|
+
const args = Array.prototype.slice.call(arguments);
|
|
37
|
+
|
|
38
|
+
// Prepend level to args
|
|
39
|
+
args.unshift(level);
|
|
40
|
+
// self.log.apply(this, args);
|
|
41
|
+
self._log.apply(this, args);
|
|
42
|
+
};
|
|
43
|
+
});
|
|
16
44
|
|
|
17
45
|
return self;
|
|
18
46
|
}
|
|
@@ -33,12 +61,14 @@ function tryParse(input) {
|
|
|
33
61
|
BackendAssistant.prototype.init = function (ref, options) {
|
|
34
62
|
const self = this;
|
|
35
63
|
|
|
64
|
+
// Set options
|
|
36
65
|
options = options || {};
|
|
37
66
|
options.accept = options.accept || 'json';
|
|
38
67
|
options.showOptionsLog = typeof options.showOptionsLog !== 'undefined' ? options.showOptionsLog : false;
|
|
39
68
|
options.optionsLogString = typeof options.optionsLogString !== 'undefined' ? options.optionsLogString : '\n\n\n\n\n';
|
|
40
69
|
options.fileSavePath = options.fileSavePath || process.env.npm_package_name || '';
|
|
41
70
|
|
|
71
|
+
// Set now
|
|
42
72
|
const now = new Date();
|
|
43
73
|
|
|
44
74
|
// Attached libraries - used in .errorify()
|
|
@@ -236,96 +266,41 @@ BackendAssistant.prototype.logProd = function () {
|
|
|
236
266
|
self._log.apply(self, args);
|
|
237
267
|
};
|
|
238
268
|
|
|
239
|
-
BackendAssistant.prototype.
|
|
269
|
+
BackendAssistant.prototype._log = function () {
|
|
240
270
|
const self = this;
|
|
271
|
+
const logs = [...arguments];
|
|
272
|
+
const prefix = self.logPrefix ? ` ${self.logPrefix}:` : ':';
|
|
241
273
|
|
|
242
|
-
|
|
274
|
+
// Prepend log prefix log string
|
|
275
|
+
logs.unshift(`[${self.tag} @ ${new Date().toISOString()}]${prefix}`);
|
|
243
276
|
|
|
244
|
-
|
|
245
|
-
|
|
277
|
+
// Get the log level
|
|
278
|
+
const level = logs[1];
|
|
246
279
|
|
|
247
|
-
|
|
248
|
-
|
|
280
|
+
// Pass along arguments to console.log
|
|
281
|
+
if (LOG_LEVELS[level]) {
|
|
282
|
+
logs.splice(1, 1);
|
|
249
283
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const args = Array.prototype.slice.call(arguments);
|
|
255
|
-
|
|
256
|
-
// Prepend level to args
|
|
257
|
-
args.unshift(level);
|
|
258
|
-
self.log.apply(this, args);
|
|
259
|
-
};
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
BackendAssistant.prototype._log = function () {
|
|
264
|
-
const self = this;
|
|
265
|
-
|
|
266
|
-
// 1. Convert args to a normal array
|
|
267
|
-
const logs = [...Array.prototype.slice.call(arguments)];
|
|
268
|
-
|
|
269
|
-
// Add log prefix
|
|
270
|
-
const prefix = self.logPrefix
|
|
271
|
-
? ` ${self.logPrefix}:`
|
|
272
|
-
: ':';
|
|
273
|
-
|
|
274
|
-
// 2. Prepend log prefix log string
|
|
275
|
-
logs.unshift(
|
|
276
|
-
`[${self.tag} @ ${new Date().toISOString()}]${prefix}`
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
// 3. Pass along arguments to console.log
|
|
280
|
-
if (logs[1] === 'error') {
|
|
281
|
-
logs.splice(1,1)
|
|
282
|
-
console.error.apply(console, logs);
|
|
283
|
-
} else if (logs[1] === 'warn') {
|
|
284
|
-
logs.splice(1,1)
|
|
285
|
-
console.warn.apply(console, logs);
|
|
286
|
-
} else if (logs[1] === 'info') {
|
|
287
|
-
logs.splice(1,1)
|
|
288
|
-
console.info.apply(console, logs);
|
|
289
|
-
} else if (logs[1] === 'debug') {
|
|
290
|
-
logs.splice(1,1)
|
|
291
|
-
console.debug.apply(console, logs);
|
|
292
|
-
} else if (logs[1] === 'notice') {
|
|
293
|
-
logs.splice(1,1)
|
|
294
|
-
if (self.isDevelopment()) {
|
|
295
|
-
console.log.apply(console, logs);
|
|
296
|
-
} else {
|
|
297
|
-
self.ref.functions.logger.write({
|
|
298
|
-
severity: 'NOTICE',
|
|
299
|
-
message: logs,
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
} else if (logs[1] === 'critical') {
|
|
303
|
-
logs.splice(1,1)
|
|
304
|
-
if (isDevelopment) {
|
|
284
|
+
// Determine how to log
|
|
285
|
+
if (level in console) {
|
|
286
|
+
console[level].apply(console, logs);
|
|
287
|
+
} else if (self.isDevelopment()) {
|
|
305
288
|
console.log.apply(console, logs);
|
|
306
289
|
} else {
|
|
307
290
|
self.ref.functions.logger.write({
|
|
308
|
-
severity:
|
|
291
|
+
severity: LOG_LEVELS[level].toUpperCase(),
|
|
309
292
|
message: logs,
|
|
310
293
|
});
|
|
311
294
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
} else {
|
|
317
|
-
self.ref.functions.logger.write({
|
|
318
|
-
severity: 'EMERGENCY',
|
|
319
|
-
message: logs,
|
|
320
|
-
});
|
|
295
|
+
|
|
296
|
+
// Write with wonderful-log
|
|
297
|
+
if (self.Manager?.libraries?.logger?.[level]) {
|
|
298
|
+
self.Manager?.libraries?.logger?.[level](...logs)
|
|
321
299
|
}
|
|
322
|
-
} else if (logs[1] === 'log') {
|
|
323
|
-
logs.splice(1,1)
|
|
324
|
-
console.log.apply(console, logs);
|
|
325
300
|
} else {
|
|
326
301
|
console.log.apply(console, logs);
|
|
327
302
|
}
|
|
328
|
-
}
|
|
303
|
+
};
|
|
329
304
|
|
|
330
305
|
BackendAssistant.prototype.setLogPrefix = function (s) {
|
|
331
306
|
const self = this;
|
package/src/manager/index.js
CHANGED
|
@@ -70,6 +70,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
70
70
|
options.assistant = options.assistant || {};
|
|
71
71
|
options.cwd = typeof options.cwd === 'undefined' ? process.cwd() : options.cwd;
|
|
72
72
|
options.projectPackageDirectory = typeof options.projectPackageDirectory === 'undefined' ? undefined : options.projectPackageDirectory;
|
|
73
|
+
options.logSavePath = typeof options.logSavePath === 'undefined' ? false : options.logSavePath;
|
|
73
74
|
// options.assistant.optionsLogString = options.assistant.optionsLogString || undefined;
|
|
74
75
|
|
|
75
76
|
// Load libraries
|
|
@@ -87,6 +88,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
87
88
|
localDatabase: null,
|
|
88
89
|
User: null,
|
|
89
90
|
Analytics: null,
|
|
91
|
+
logger: null,
|
|
90
92
|
};
|
|
91
93
|
|
|
92
94
|
// Set properties
|
|
@@ -118,8 +120,27 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
118
120
|
// Get app ID
|
|
119
121
|
const appId = self.config?.app?.id;
|
|
120
122
|
|
|
123
|
+
// Set log
|
|
124
|
+
if (options.logSavePath) {
|
|
125
|
+
self.libraries.logger = new (require('wonderful-log'))({
|
|
126
|
+
console: {
|
|
127
|
+
enabled: false,
|
|
128
|
+
},
|
|
129
|
+
file: {
|
|
130
|
+
enabled: true,
|
|
131
|
+
path: options.logSavePath,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
121
136
|
// Init assistant
|
|
122
|
-
self.assistant = self.Assistant().init(
|
|
137
|
+
self.assistant = self.Assistant().init({
|
|
138
|
+
req: null,
|
|
139
|
+
res: null,
|
|
140
|
+
admin: self.libraries.admin,
|
|
141
|
+
functions: self.libraries.functions,
|
|
142
|
+
Manager: self,
|
|
143
|
+
}, options.assistant);
|
|
123
144
|
|
|
124
145
|
// Set more properties (need to wait for assistant to determine if DEV)
|
|
125
146
|
self.project.functionsUrl = self.assistant.isDevelopment()
|