backendless 6.7.1-dev.2 → 7.0.0

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/es/index.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports["default"] = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -160,13 +161,20 @@ var Backendless = /*#__PURE__*/function () {
160
161
  app.initConfig(config);
161
162
  app.resetRT();
162
163
  app.__removeService('LocalCache');
164
+ var loggingConfig = (0, _extends2["default"])({
165
+ loadLevels: true,
166
+ defaultLevel: 'all',
167
+ levels: {}
168
+ }, config.logging);
163
169
  if (app.__hasService('Logging')) {
164
170
  app.Logging.reset();
171
+ app.Logging.setConfig(loggingConfig);
165
172
  }
166
173
  if (app.__hasService('Users')) {
167
174
  app.Users.currentUser = null;
168
175
  }
169
176
  delete this.__device;
177
+ app.loggingConfig = loggingConfig;
170
178
  return app;
171
179
  }
172
180
  }, {
@@ -16,8 +16,17 @@ var Logging = /*#__PURE__*/function () {
16
16
  (0, _classCallCheck2["default"])(this, Logging);
17
17
  this.app = app;
18
18
  this.reset();
19
+ this.setConfig(app.loggingConfig);
19
20
  }
20
21
  (0, _createClass2["default"])(Logging, [{
22
+ key: "setConfig",
23
+ value: function setConfig(config) {
24
+ this.config = config;
25
+ if (config.loadLevels) {
26
+ this.loadLoggingLevels();
27
+ }
28
+ }
29
+ }, {
21
30
  key: "reset",
22
31
  value: function reset() {
23
32
  this.loggers = {};
@@ -26,6 +35,21 @@ var Logging = /*#__PURE__*/function () {
26
35
  this.timeFrequency = 1;
27
36
  this.messagesLimit = 100;
28
37
  }
38
+ }, {
39
+ key: "loadLoggingLevels",
40
+ value: function loadLoggingLevels() {
41
+ var _this = this;
42
+ this.app.request.get({
43
+ url: this.app.urls.loggingLevels()
44
+ }).then(function (loggers) {
45
+ loggers.forEach(function (logger) {
46
+ _this.config.levels[logger.name] = logger.level;
47
+ });
48
+ })["catch"](function (error) {
49
+ // eslint-disable-next-line no-console
50
+ console.error('Could not load logging levels: ', error);
51
+ });
52
+ }
29
53
  }, {
30
54
  key: "getLogger",
31
55
  value: function getLogger(loggerName) {
@@ -41,7 +65,7 @@ var Logging = /*#__PURE__*/function () {
41
65
  key: "flush",
42
66
  value: function () {
43
67
  var _flush = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
44
- var _this = this;
68
+ var _this2 = this;
45
69
  var messages;
46
70
  return _regenerator["default"].wrap(function _callee$(_context) {
47
71
  while (1) switch (_context.prev = _context.next) {
@@ -54,11 +78,11 @@ var Logging = /*#__PURE__*/function () {
54
78
  url: this.app.urls.logging(),
55
79
  data: messages
56
80
  })["catch"](function (error) {
57
- _this.messages = [].concat((0, _toConsumableArray2["default"])(messages), (0, _toConsumableArray2["default"])(_this.messages));
58
- _this.checkMessagesLimit();
81
+ _this2.messages = [].concat((0, _toConsumableArray2["default"])(messages), (0, _toConsumableArray2["default"])(_this2.messages));
82
+ _this2.checkMessagesLimit();
59
83
  throw error;
60
84
  })["finally"](function () {
61
- return delete _this.flushRequest;
85
+ return delete _this2.flushRequest;
62
86
  });
63
87
  }
64
88
  return _context.abrupt("return", this.flushRequest);
@@ -106,10 +130,10 @@ var Logging = /*#__PURE__*/function () {
106
130
  }, {
107
131
  key: "startFlushInterval",
108
132
  value: function startFlushInterval() {
109
- var _this2 = this;
133
+ var _this3 = this;
110
134
  if (!this.flushInterval) {
111
135
  this.flushInterval = setTimeout(function () {
112
- return _this2.flush();
136
+ return _this3.flush();
113
137
  }, this.timeFrequency * 1000);
114
138
  }
115
139
  }
@@ -7,6 +7,16 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var LogLevelPriorities = {
11
+ off: 0,
12
+ fatal: 1,
13
+ error: 2,
14
+ warn: 3,
15
+ info: 4,
16
+ debug: 5,
17
+ trace: 6,
18
+ all: 6
19
+ };
10
20
  var Logger = /*#__PURE__*/function () {
11
21
  function Logger(name, logging) {
12
22
  (0, _classCallCheck2["default"])(this, Logger);
@@ -16,32 +26,49 @@ var Logger = /*#__PURE__*/function () {
16
26
  (0, _createClass2["default"])(Logger, [{
17
27
  key: "debug",
18
28
  value: function debug(message) {
19
- return this.logging.push(this.name, 'DEBUG', message);
29
+ return this.log('DEBUG', message);
20
30
  }
21
31
  }, {
22
32
  key: "info",
23
33
  value: function info(message) {
24
- return this.logging.push(this.name, 'INFO', message);
34
+ return this.log('INFO', message);
25
35
  }
26
36
  }, {
27
37
  key: "warn",
28
38
  value: function warn(message, exception) {
29
- return this.logging.push(this.name, 'WARN', message, exception);
39
+ return this.log('WARN', message, exception);
30
40
  }
31
41
  }, {
32
42
  key: "error",
33
43
  value: function error(message, exception) {
34
- return this.logging.push(this.name, 'ERROR', message, exception);
44
+ return this.log('ERROR', message, exception);
35
45
  }
36
46
  }, {
37
47
  key: "fatal",
38
48
  value: function fatal(message, exception) {
39
- return this.logging.push(this.name, 'FATAL', message, exception);
49
+ return this.log('FATAL', message, exception);
40
50
  }
41
51
  }, {
42
52
  key: "trace",
43
53
  value: function trace(message) {
44
- return this.logging.push(this.name, 'TRACE', message);
54
+ return this.log('TRACE', message);
55
+ }
56
+ }, {
57
+ key: "log",
58
+ value: function log(level, message, exception) {
59
+ if (this.min(level)) {
60
+ return this.logging.push(this.name, level, message, exception);
61
+ }
62
+ }
63
+ }, {
64
+ key: "min",
65
+ value: function min(level) {
66
+ var configuredLevel = this.logging.config.levels[this.name];
67
+ if (!configuredLevel) {
68
+ var defaultLevel = this.logging.config.defaultLevel;
69
+ return LogLevelPriorities[defaultLevel.toLowerCase()] >= LogLevelPriorities[level.toLowerCase()];
70
+ }
71
+ return LogLevelPriorities[configuredLevel.toLowerCase()] >= LogLevelPriorities[level.toLowerCase()];
45
72
  }
46
73
  }]);
47
74
  return Logger;
package/es/urls.js CHANGED
@@ -41,6 +41,11 @@ var Urls = /*#__PURE__*/function () {
41
41
  value: function logging() {
42
42
  return "".concat(this.root(), "/log");
43
43
  }
44
+ }, {
45
+ key: "loggingLevels",
46
+ value: function loggingLevels() {
47
+ return "".concat(this.logging(), "/logger");
48
+ }
44
49
 
45
50
  //cache
46
51
  }, {
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports["default"] = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
@@ -160,13 +161,20 @@ var Backendless = /*#__PURE__*/function () {
160
161
  app.initConfig(config);
161
162
  app.resetRT();
162
163
  app.__removeService('LocalCache');
164
+ var loggingConfig = (0, _extends2["default"])({
165
+ loadLevels: true,
166
+ defaultLevel: 'all',
167
+ levels: {}
168
+ }, config.logging);
163
169
  if (app.__hasService('Logging')) {
164
170
  app.Logging.reset();
171
+ app.Logging.setConfig(loggingConfig);
165
172
  }
166
173
  if (app.__hasService('Users')) {
167
174
  app.Users.currentUser = null;
168
175
  }
169
176
  delete this.__device;
177
+ app.loggingConfig = loggingConfig;
170
178
  return app;
171
179
  }
172
180
  }, {
@@ -16,8 +16,17 @@ var Logging = /*#__PURE__*/function () {
16
16
  (0, _classCallCheck2["default"])(this, Logging);
17
17
  this.app = app;
18
18
  this.reset();
19
+ this.setConfig(app.loggingConfig);
19
20
  }
20
21
  (0, _createClass2["default"])(Logging, [{
22
+ key: "setConfig",
23
+ value: function setConfig(config) {
24
+ this.config = config;
25
+ if (config.loadLevels) {
26
+ this.loadLoggingLevels();
27
+ }
28
+ }
29
+ }, {
21
30
  key: "reset",
22
31
  value: function reset() {
23
32
  this.loggers = {};
@@ -26,6 +35,21 @@ var Logging = /*#__PURE__*/function () {
26
35
  this.timeFrequency = 1;
27
36
  this.messagesLimit = 100;
28
37
  }
38
+ }, {
39
+ key: "loadLoggingLevels",
40
+ value: function loadLoggingLevels() {
41
+ var _this = this;
42
+ this.app.request.get({
43
+ url: this.app.urls.loggingLevels()
44
+ }).then(function (loggers) {
45
+ loggers.forEach(function (logger) {
46
+ _this.config.levels[logger.name] = logger.level;
47
+ });
48
+ })["catch"](function (error) {
49
+ // eslint-disable-next-line no-console
50
+ console.error('Could not load logging levels: ', error);
51
+ });
52
+ }
29
53
  }, {
30
54
  key: "getLogger",
31
55
  value: function getLogger(loggerName) {
@@ -41,7 +65,7 @@ var Logging = /*#__PURE__*/function () {
41
65
  key: "flush",
42
66
  value: function () {
43
67
  var _flush = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
44
- var _this = this;
68
+ var _this2 = this;
45
69
  var messages;
46
70
  return _regenerator["default"].wrap(function _callee$(_context) {
47
71
  while (1) switch (_context.prev = _context.next) {
@@ -54,11 +78,11 @@ var Logging = /*#__PURE__*/function () {
54
78
  url: this.app.urls.logging(),
55
79
  data: messages
56
80
  })["catch"](function (error) {
57
- _this.messages = [].concat((0, _toConsumableArray2["default"])(messages), (0, _toConsumableArray2["default"])(_this.messages));
58
- _this.checkMessagesLimit();
81
+ _this2.messages = [].concat((0, _toConsumableArray2["default"])(messages), (0, _toConsumableArray2["default"])(_this2.messages));
82
+ _this2.checkMessagesLimit();
59
83
  throw error;
60
84
  })["finally"](function () {
61
- return delete _this.flushRequest;
85
+ return delete _this2.flushRequest;
62
86
  });
63
87
  }
64
88
  return _context.abrupt("return", this.flushRequest);
@@ -106,10 +130,10 @@ var Logging = /*#__PURE__*/function () {
106
130
  }, {
107
131
  key: "startFlushInterval",
108
132
  value: function startFlushInterval() {
109
- var _this2 = this;
133
+ var _this3 = this;
110
134
  if (!this.flushInterval) {
111
135
  this.flushInterval = setTimeout(function () {
112
- return _this2.flush();
136
+ return _this3.flush();
113
137
  }, this.timeFrequency * 1000);
114
138
  }
115
139
  }
@@ -7,6 +7,16 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports["default"] = void 0;
8
8
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
9
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var LogLevelPriorities = {
11
+ off: 0,
12
+ fatal: 1,
13
+ error: 2,
14
+ warn: 3,
15
+ info: 4,
16
+ debug: 5,
17
+ trace: 6,
18
+ all: 6
19
+ };
10
20
  var Logger = /*#__PURE__*/function () {
11
21
  function Logger(name, logging) {
12
22
  (0, _classCallCheck2["default"])(this, Logger);
@@ -16,32 +26,49 @@ var Logger = /*#__PURE__*/function () {
16
26
  (0, _createClass2["default"])(Logger, [{
17
27
  key: "debug",
18
28
  value: function debug(message) {
19
- return this.logging.push(this.name, 'DEBUG', message);
29
+ return this.log('DEBUG', message);
20
30
  }
21
31
  }, {
22
32
  key: "info",
23
33
  value: function info(message) {
24
- return this.logging.push(this.name, 'INFO', message);
34
+ return this.log('INFO', message);
25
35
  }
26
36
  }, {
27
37
  key: "warn",
28
38
  value: function warn(message, exception) {
29
- return this.logging.push(this.name, 'WARN', message, exception);
39
+ return this.log('WARN', message, exception);
30
40
  }
31
41
  }, {
32
42
  key: "error",
33
43
  value: function error(message, exception) {
34
- return this.logging.push(this.name, 'ERROR', message, exception);
44
+ return this.log('ERROR', message, exception);
35
45
  }
36
46
  }, {
37
47
  key: "fatal",
38
48
  value: function fatal(message, exception) {
39
- return this.logging.push(this.name, 'FATAL', message, exception);
49
+ return this.log('FATAL', message, exception);
40
50
  }
41
51
  }, {
42
52
  key: "trace",
43
53
  value: function trace(message) {
44
- return this.logging.push(this.name, 'TRACE', message);
54
+ return this.log('TRACE', message);
55
+ }
56
+ }, {
57
+ key: "log",
58
+ value: function log(level, message, exception) {
59
+ if (this.min(level)) {
60
+ return this.logging.push(this.name, level, message, exception);
61
+ }
62
+ }
63
+ }, {
64
+ key: "min",
65
+ value: function min(level) {
66
+ var configuredLevel = this.logging.config.levels[this.name];
67
+ if (!configuredLevel) {
68
+ var defaultLevel = this.logging.config.defaultLevel;
69
+ return LogLevelPriorities[defaultLevel.toLowerCase()] >= LogLevelPriorities[level.toLowerCase()];
70
+ }
71
+ return LogLevelPriorities[configuredLevel.toLowerCase()] >= LogLevelPriorities[level.toLowerCase()];
45
72
  }
46
73
  }]);
47
74
  return Logger;
package/lib/urls.js CHANGED
@@ -41,6 +41,11 @@ var Urls = /*#__PURE__*/function () {
41
41
  value: function logging() {
42
42
  return "".concat(this.root(), "/log");
43
43
  }
44
+ }, {
45
+ key: "loggingLevels",
46
+ value: function loggingLevels() {
47
+ return "".concat(this.logging(), "/logger");
48
+ }
44
49
 
45
50
  //cache
46
51
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backendless",
3
- "version": "6.7.1-dev.2",
3
+ "version": "7.0.0",
4
4
  "description": "Backendless JavaScript SDK for Node.js and the browser",
5
5
  "browser": "dist/backendless.js",
6
6
  "main": "lib/index.js",
package/src/index.js CHANGED
@@ -146,8 +146,11 @@ class Backendless {
146
146
 
147
147
  app.__removeService('LocalCache')
148
148
 
149
+ const loggingConfig = Object.assign({ loadLevels: true, defaultLevel: 'all', levels: {} }, config.logging)
150
+
149
151
  if (app.__hasService('Logging')) {
150
152
  app.Logging.reset()
153
+ app.Logging.setConfig(loggingConfig)
151
154
  }
152
155
 
153
156
  if (app.__hasService('Users')) {
@@ -156,6 +159,8 @@ class Backendless {
156
159
 
157
160
  delete this.__device
158
161
 
162
+ app.loggingConfig = loggingConfig
163
+
159
164
  return app
160
165
  }
161
166
 
@@ -6,6 +6,16 @@ export default class Logging {
6
6
  this.app = app
7
7
 
8
8
  this.reset()
9
+
10
+ this.setConfig(app.loggingConfig)
11
+ }
12
+
13
+ setConfig(config) {
14
+ this.config = config
15
+
16
+ if (config.loadLevels) {
17
+ this.loadLoggingLevels()
18
+ }
9
19
  }
10
20
 
11
21
  reset() {
@@ -16,6 +26,20 @@ export default class Logging {
16
26
  this.messagesLimit = 100
17
27
  }
18
28
 
29
+ loadLoggingLevels() {
30
+ this.app.request
31
+ .get({ url: this.app.urls.loggingLevels() })
32
+ .then(loggers => {
33
+ loggers.forEach(logger => {
34
+ this.config.levels[logger.name] = logger.level
35
+ })
36
+ })
37
+ .catch(error => {
38
+ // eslint-disable-next-line no-console
39
+ console.error('Could not load logging levels: ', error)
40
+ })
41
+ }
42
+
19
43
  getLogger(loggerName) {
20
44
  if (!loggerName || typeof loggerName !== 'string') {
21
45
  throw new Error('Logger Name must be provided and must be a string.')
@@ -1,3 +1,14 @@
1
+ const LogLevelPriorities = {
2
+ off : 0,
3
+ fatal: 1,
4
+ error: 2,
5
+ warn : 3,
6
+ info : 4,
7
+ debug: 5,
8
+ trace: 6,
9
+ all : 6,
10
+ }
11
+
1
12
  export default class Logger {
2
13
 
3
14
  constructor(name, logging) {
@@ -6,26 +17,44 @@ export default class Logger {
6
17
  }
7
18
 
8
19
  debug(message) {
9
- return this.logging.push(this.name, 'DEBUG', message)
20
+ return this.log('DEBUG', message)
10
21
  }
11
22
 
12
23
  info(message) {
13
- return this.logging.push(this.name, 'INFO', message)
24
+ return this.log('INFO', message)
14
25
  }
15
26
 
16
27
  warn(message, exception) {
17
- return this.logging.push(this.name, 'WARN', message, exception)
28
+ return this.log('WARN', message, exception)
18
29
  }
19
30
 
20
31
  error(message, exception) {
21
- return this.logging.push(this.name, 'ERROR', message, exception)
32
+ return this.log('ERROR', message, exception)
22
33
  }
23
34
 
24
35
  fatal(message, exception) {
25
- return this.logging.push(this.name, 'FATAL', message, exception)
36
+ return this.log('FATAL', message, exception)
26
37
  }
27
38
 
28
39
  trace(message) {
29
- return this.logging.push(this.name, 'TRACE', message)
40
+ return this.log('TRACE', message)
41
+ }
42
+
43
+ log(level, message, exception) {
44
+ if (this.min(level)) {
45
+ return this.logging.push(this.name, level, message, exception)
46
+ }
47
+ }
48
+
49
+ min(level) {
50
+ const configuredLevel = this.logging.config.levels[this.name]
51
+
52
+ if (!configuredLevel) {
53
+ const { defaultLevel } = this.logging.config
54
+
55
+ return LogLevelPriorities[defaultLevel.toLowerCase()] >= LogLevelPriorities[level.toLowerCase()]
56
+ }
57
+
58
+ return LogLevelPriorities[configuredLevel.toLowerCase()] >= LogLevelPriorities[level.toLowerCase()]
30
59
  }
31
60
  }
package/src/urls.js CHANGED
@@ -27,6 +27,10 @@ export default class Urls {
27
27
  return `${this.root()}/log`
28
28
  }
29
29
 
30
+ loggingLevels() {
31
+ return `${this.logging()}/logger`
32
+ }
33
+
30
34
  //cache
31
35
 
32
36
  cache() {