agora-foundation 3.10.1-rc.2 → 3.10.2

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.
@@ -16,14 +16,21 @@ var InvocationEventTypeToString = (0, _defineProperty2["default"])((0, _definePr
16
16
 
17
17
  // 方法返回错误码时对应的描述
18
18
  var ReasonCodeToString = (0, _defineProperty2["default"])((0, _defineProperty2["default"])({}, -1, 'FAILED'), 0, 'SUCCESS');
19
- var formatLogHead = function formatLogHead(identifier, tag, args, argsNames) {
19
+ var formatLogHead = function formatLogHead(identifier, tag, args, argsNames, opts) {
20
20
  var elapsed = Date.now() - identifier.startTs;
21
- var parameters = '[parameters: []]';
22
- var duration = "[duration: ".concat(elapsed, "ms]");
23
- if (args !== null && args !== void 0 && args.length) {
24
- parameters = "[parameters: [".concat((0, _logSerializer.serializeArgs)(args, argsNames), "]]");
21
+ var parameters = '';
22
+ var duration = '';
23
+ if ((opts === null || opts === void 0 ? void 0 : opts.includeParameters) !== false) {
24
+ parameters = '[parameters: []]';
25
+ if (args !== null && args !== void 0 && args.length) {
26
+ parameters = "[parameters: [".concat((0, _logSerializer.serializeArgs)(args, argsNames), "]]");
27
+ }
28
+ parameters = " ".concat(parameters);
29
+ }
30
+ if ((opts === null || opts === void 0 ? void 0 : opts.includeDuration) !== false) {
31
+ duration = " [duration: ".concat(elapsed, "ms]");
25
32
  }
26
- return "".concat(identifier.methodName, ": ").concat(tag, " ").concat(parameters, " ").concat(duration);
33
+ return "".concat(identifier.methodName, ": ").concat(tag).concat(parameters).concat(duration);
27
34
  };
28
35
  var formatLogReturn = function formatLogReturn(returnValue) {
29
36
  return "[message: { return: ".concat((0, _logSerializer.serialize)(returnValue), " }]");
@@ -45,32 +52,34 @@ var printReturnOrReason = function printReturnOrReason(logger, returnValue, getM
45
52
  };
46
53
  var createLogHandler = exports.createLogHandler = function createLogHandler(holder, isErrorCodeByReturnValue) {
47
54
  return function (evt) {
48
- var _evt$arguments, _evt$argumentNames;
49
- var msgHead = formatLogHead({
50
- className: evt["class"],
51
- methodName: evt.method,
52
- startTs: evt.context.start,
53
- isThenable: evt.context.isThenable
54
- }, InvocationEventTypeToString[evt.type], (_evt$arguments = evt.arguments) !== null && _evt$arguments !== void 0 ? _evt$arguments : [], (_evt$argumentNames = evt.argumentNames) !== null && _evt$argumentNames !== void 0 ? _evt$argumentNames : []);
55
55
  var msgFoot = " [traceId: ".concat(evt.context.traceId, "]");
56
- var getMsg = function getMsg() {
57
- var msgBody = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
58
- return "".concat(msgHead).concat(msgBody).concat(msgFoot);
59
- };
60
56
  if (evt.type === _type.InvocationEventType.API_CALL) {
61
- if (evt.context.isThenable === true) {
62
- // 异步方法只打印调用信息, API_RETURN 时打印返回值等信息
63
- holder.logger.info(getMsg());
64
- } else {
65
- // 同步方法的打印内容包含返回值, 错误码等信息(如果有的话)
66
- printReturnOrReason(holder.logger, evt["return"], getMsg, isErrorCodeByReturnValue);
67
- }
57
+ var _evt$arguments, _evt$argumentNames;
58
+ var msgHead = formatLogHead({
59
+ className: evt["class"],
60
+ methodName: evt.method,
61
+ startTs: evt.context.start
62
+ }, InvocationEventTypeToString[evt.type], (_evt$arguments = evt.arguments) !== null && _evt$arguments !== void 0 ? _evt$arguments : [], (_evt$argumentNames = evt.argumentNames) !== null && _evt$argumentNames !== void 0 ? _evt$argumentNames : [], {
63
+ includeDuration: false
64
+ });
65
+ holder.logger.info("".concat(msgHead).concat(msgFoot));
68
66
  } else if (evt.type === _type.InvocationEventType.API_RETURN) {
67
+ var _evt$arguments2, _evt$argumentNames2;
68
+ var _msgHead = formatLogHead({
69
+ className: evt["class"],
70
+ methodName: evt.method,
71
+ startTs: evt.context.start
72
+ }, InvocationEventTypeToString[evt.type], (_evt$arguments2 = evt.arguments) !== null && _evt$arguments2 !== void 0 ? _evt$arguments2 : [], (_evt$argumentNames2 = evt.argumentNames) !== null && _evt$argumentNames2 !== void 0 ? _evt$argumentNames2 : [], {
73
+ includeParameters: false
74
+ });
75
+ var getMsg = function getMsg() {
76
+ var msgBody = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
77
+ return "".concat(_msgHead).concat(msgBody).concat(msgFoot);
78
+ };
69
79
  if (evt.error) {
70
80
  var msgBody = " ".concat(formatLogError(evt.error));
71
81
  holder.logger.error(getMsg(msgBody));
72
82
  } else {
73
- // 异步方法在此处打印返回值, 错误码等信息(如果有的话)
74
83
  printReturnOrReason(holder.logger, evt["return"], getMsg, isErrorCodeByReturnValue);
75
84
  }
76
85
  }
@@ -8,8 +8,8 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.trace = trace;
9
9
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
10
10
  require("core-js/modules/es.function.name.js");
11
- var _proxy = require("../proxy");
12
11
  var _handler = require("./handler");
12
+ var _proxy = require("../proxy");
13
13
  var _logger = require("../../logger");
14
14
  /**
15
15
  * Enables logging for invocation detail of the target method.
@@ -18,8 +18,6 @@ require("core-js/modules/es.object.get-own-property-names.js");
18
18
  require("core-js/modules/es.object.get-prototype-of.js");
19
19
  require("core-js/modules/es.object.keys.js");
20
20
  require("core-js/modules/es.object.to-string.js");
21
- require("core-js/modules/es.promise.js");
22
- require("core-js/modules/es.promise.finally.js");
23
21
  require("core-js/modules/esnext.iterator.constructor.js");
24
22
  require("core-js/modules/esnext.iterator.for-each.js");
25
23
  require("core-js/modules/web.dom-collections.for-each.js");
@@ -40,14 +38,11 @@ var failQuitely = function failQuitely(func, args) {
40
38
  } catch (e) {}
41
39
  };
42
40
  var invokeMethod = function invokeMethod(instance, method, proto, propertyName, args, hanlder, paramNames) {
43
- var context = {};
44
- context.start = Date.now();
45
- context.traceId = (0, _misc.randomString)(5);
46
-
47
- // provide a way for invoking method regardless it is async or sync function, attach the return value and the error(if it occurred) to the event object
48
- var returnVal = method.apply(instance, args);
49
- var isThenable = returnVal && !!returnVal.then;
50
- context.isThenable = isThenable;
41
+ var context = {
42
+ start: Date.now(),
43
+ traceId: (0, _misc.randomString)(5),
44
+ isThenable: false
45
+ };
51
46
  var post = function post(type, val, error) {
52
47
  failQuitely(hanlder, [{
53
48
  type: type,
@@ -61,20 +56,26 @@ var invokeMethod = function invokeMethod(instance, method, proto, propertyName,
61
56
  }]);
62
57
  };
63
58
 
64
- // 同步/异步函数调用结束时输出日志,(异步函数函数不等待异步结束)
65
- post(_type.InvocationEventType.API_CALL, returnVal);
66
- if (isThenable) {
67
- // capture async return and potential error
68
- var rtnTemp, errTemp;
69
- returnVal.then(function (r) {
70
- rtnTemp = r;
71
- })["catch"](function (e) {
72
- errTemp = e;
73
- })["finally"](function () {
74
- post(_type.InvocationEventType.API_RETURN, rtnTemp, errTemp);
75
- });
59
+ // 先记录调用信息,再在返回/抛错时补充结果。
60
+ post(_type.InvocationEventType.API_CALL, undefined);
61
+ try {
62
+ // provide a way for invoking method regardless it is async or sync function, attach the return value and the error(if it occurred) to the event object
63
+ var returnVal = method.apply(instance, args);
64
+ context.isThenable = !!(returnVal !== null && returnVal !== void 0 && returnVal.then);
65
+ if (context.isThenable) {
66
+ returnVal.then(function (result) {
67
+ post(_type.InvocationEventType.API_RETURN, result);
68
+ }, function (error) {
69
+ post(_type.InvocationEventType.API_RETURN, undefined, error);
70
+ });
71
+ } else {
72
+ post(_type.InvocationEventType.API_RETURN, returnVal);
73
+ }
74
+ return returnVal;
75
+ } catch (error) {
76
+ post(_type.InvocationEventType.API_RETURN, undefined, error);
77
+ throw error;
76
78
  }
77
- return returnVal;
78
79
  };
79
80
  var proxyMethod = exports.proxyMethod = function proxyMethod(method, proto, propertyName, handler, paramNames) {
80
81
  return function () {
@@ -8,14 +8,21 @@ var InvocationEventTypeToString = _defineProperty(_defineProperty({}, Invocation
8
8
 
9
9
  // 方法返回错误码时对应的描述
10
10
  var ReasonCodeToString = _defineProperty(_defineProperty({}, -1, 'FAILED'), 0, 'SUCCESS');
11
- var formatLogHead = function formatLogHead(identifier, tag, args, argsNames) {
11
+ var formatLogHead = function formatLogHead(identifier, tag, args, argsNames, opts) {
12
12
  var elapsed = Date.now() - identifier.startTs;
13
- var parameters = '[parameters: []]';
14
- var duration = "[duration: ".concat(elapsed, "ms]");
15
- if (args !== null && args !== void 0 && args.length) {
16
- parameters = "[parameters: [".concat(serializeArgs(args, argsNames), "]]");
13
+ var parameters = '';
14
+ var duration = '';
15
+ if ((opts === null || opts === void 0 ? void 0 : opts.includeParameters) !== false) {
16
+ parameters = '[parameters: []]';
17
+ if (args !== null && args !== void 0 && args.length) {
18
+ parameters = "[parameters: [".concat(serializeArgs(args, argsNames), "]]");
19
+ }
20
+ parameters = " ".concat(parameters);
21
+ }
22
+ if ((opts === null || opts === void 0 ? void 0 : opts.includeDuration) !== false) {
23
+ duration = " [duration: ".concat(elapsed, "ms]");
17
24
  }
18
- return "".concat(identifier.methodName, ": ").concat(tag, " ").concat(parameters, " ").concat(duration);
25
+ return "".concat(identifier.methodName, ": ").concat(tag).concat(parameters).concat(duration);
19
26
  };
20
27
  var formatLogReturn = function formatLogReturn(returnValue) {
21
28
  return "[message: { return: ".concat(serialize(returnValue), " }]");
@@ -37,32 +44,34 @@ var printReturnOrReason = function printReturnOrReason(logger, returnValue, getM
37
44
  };
38
45
  export var createLogHandler = function createLogHandler(holder, isErrorCodeByReturnValue) {
39
46
  return function (evt) {
40
- var _evt$arguments, _evt$argumentNames;
41
- var msgHead = formatLogHead({
42
- className: evt["class"],
43
- methodName: evt.method,
44
- startTs: evt.context.start,
45
- isThenable: evt.context.isThenable
46
- }, InvocationEventTypeToString[evt.type], (_evt$arguments = evt.arguments) !== null && _evt$arguments !== void 0 ? _evt$arguments : [], (_evt$argumentNames = evt.argumentNames) !== null && _evt$argumentNames !== void 0 ? _evt$argumentNames : []);
47
47
  var msgFoot = " [traceId: ".concat(evt.context.traceId, "]");
48
- var getMsg = function getMsg() {
49
- var msgBody = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
50
- return "".concat(msgHead).concat(msgBody).concat(msgFoot);
51
- };
52
48
  if (evt.type === InvocationEventType.API_CALL) {
53
- if (evt.context.isThenable === true) {
54
- // 异步方法只打印调用信息, API_RETURN 时打印返回值等信息
55
- holder.logger.info(getMsg());
56
- } else {
57
- // 同步方法的打印内容包含返回值, 错误码等信息(如果有的话)
58
- printReturnOrReason(holder.logger, evt["return"], getMsg, isErrorCodeByReturnValue);
59
- }
49
+ var _evt$arguments, _evt$argumentNames;
50
+ var msgHead = formatLogHead({
51
+ className: evt["class"],
52
+ methodName: evt.method,
53
+ startTs: evt.context.start
54
+ }, InvocationEventTypeToString[evt.type], (_evt$arguments = evt.arguments) !== null && _evt$arguments !== void 0 ? _evt$arguments : [], (_evt$argumentNames = evt.argumentNames) !== null && _evt$argumentNames !== void 0 ? _evt$argumentNames : [], {
55
+ includeDuration: false
56
+ });
57
+ holder.logger.info("".concat(msgHead).concat(msgFoot));
60
58
  } else if (evt.type === InvocationEventType.API_RETURN) {
59
+ var _evt$arguments2, _evt$argumentNames2;
60
+ var _msgHead = formatLogHead({
61
+ className: evt["class"],
62
+ methodName: evt.method,
63
+ startTs: evt.context.start
64
+ }, InvocationEventTypeToString[evt.type], (_evt$arguments2 = evt.arguments) !== null && _evt$arguments2 !== void 0 ? _evt$arguments2 : [], (_evt$argumentNames2 = evt.argumentNames) !== null && _evt$argumentNames2 !== void 0 ? _evt$argumentNames2 : [], {
65
+ includeParameters: false
66
+ });
67
+ var getMsg = function getMsg() {
68
+ var msgBody = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
69
+ return "".concat(_msgHead).concat(msgBody).concat(msgFoot);
70
+ };
61
71
  if (evt.error) {
62
72
  var msgBody = " ".concat(formatLogError(evt.error));
63
73
  holder.logger.error(getMsg(msgBody));
64
74
  } else {
65
- // 异步方法在此处打印返回值, 错误码等信息(如果有的话)
66
75
  printReturnOrReason(holder.logger, evt["return"], getMsg, isErrorCodeByReturnValue);
67
76
  }
68
77
  }
@@ -1,7 +1,7 @@
1
1
  import _typeof from "@babel/runtime/helpers/typeof";
2
2
  import "core-js/modules/es.function.name.js";
3
- import { proxyMethod } from '../proxy';
4
3
  import { createLogHandler } from './handler';
4
+ import { proxyMethod } from '../proxy';
5
5
  import { getLogger } from '../../logger';
6
6
 
7
7
  /**
@@ -19,8 +19,6 @@ import "core-js/modules/es.object.get-own-property-names.js";
19
19
  import "core-js/modules/es.object.get-prototype-of.js";
20
20
  import "core-js/modules/es.object.keys.js";
21
21
  import "core-js/modules/es.object.to-string.js";
22
- import "core-js/modules/es.promise.js";
23
- import "core-js/modules/es.promise.finally.js";
24
22
  import "core-js/modules/es.reflect.construct.js";
25
23
  import "core-js/modules/esnext.iterator.constructor.js";
26
24
  import "core-js/modules/esnext.iterator.for-each.js";
@@ -33,14 +31,11 @@ var failQuitely = function failQuitely(func, args) {
33
31
  } catch (e) {}
34
32
  };
35
33
  var invokeMethod = function invokeMethod(instance, method, proto, propertyName, args, hanlder, paramNames) {
36
- var context = {};
37
- context.start = Date.now();
38
- context.traceId = randomString(5);
39
-
40
- // provide a way for invoking method regardless it is async or sync function, attach the return value and the error(if it occurred) to the event object
41
- var returnVal = method.apply(instance, args);
42
- var isThenable = returnVal && !!returnVal.then;
43
- context.isThenable = isThenable;
34
+ var context = {
35
+ start: Date.now(),
36
+ traceId: randomString(5),
37
+ isThenable: false
38
+ };
44
39
  var post = function post(type, val, error) {
45
40
  failQuitely(hanlder, [{
46
41
  type: type,
@@ -54,20 +49,26 @@ var invokeMethod = function invokeMethod(instance, method, proto, propertyName,
54
49
  }]);
55
50
  };
56
51
 
57
- // 同步/异步函数调用结束时输出日志,(异步函数函数不等待异步结束)
58
- post(InvocationEventType.API_CALL, returnVal);
59
- if (isThenable) {
60
- // capture async return and potential error
61
- var rtnTemp, errTemp;
62
- returnVal.then(function (r) {
63
- rtnTemp = r;
64
- })["catch"](function (e) {
65
- errTemp = e;
66
- })["finally"](function () {
67
- post(InvocationEventType.API_RETURN, rtnTemp, errTemp);
68
- });
52
+ // 先记录调用信息,再在返回/抛错时补充结果。
53
+ post(InvocationEventType.API_CALL, undefined);
54
+ try {
55
+ // provide a way for invoking method regardless it is async or sync function, attach the return value and the error(if it occurred) to the event object
56
+ var returnVal = method.apply(instance, args);
57
+ context.isThenable = !!(returnVal !== null && returnVal !== void 0 && returnVal.then);
58
+ if (context.isThenable) {
59
+ returnVal.then(function (result) {
60
+ post(InvocationEventType.API_RETURN, result);
61
+ }, function (error) {
62
+ post(InvocationEventType.API_RETURN, undefined, error);
63
+ });
64
+ } else {
65
+ post(InvocationEventType.API_RETURN, returnVal);
66
+ }
67
+ return returnVal;
68
+ } catch (error) {
69
+ post(InvocationEventType.API_RETURN, undefined, error);
70
+ throw error;
69
71
  }
70
- return returnVal;
71
72
  };
72
73
  export var proxyMethod = function proxyMethod(method, proto, propertyName, handler, paramNames) {
73
74
  return function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agora-foundation",
3
- "version": "3.10.1-rc.2",
3
+ "version": "3.10.2",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-es/index.js",
@@ -24,7 +24,7 @@
24
24
  "@types/jasmine": "^5.1.4",
25
25
  "@types/lodash": "^4.14.168",
26
26
  "@types/node": "^20.11.30",
27
- "agora-toolchain": "3.10.1-rc.2",
27
+ "agora-toolchain": "3.10.2",
28
28
  "core-js": "^3.33.3",
29
29
  "tslib": "^2.6.2",
30
30
  "winston": "^3.16.0",