diff --git a/package.json b/package.json index c913ef955..0ae7873c5 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "js-yaml": "^3.2.7", "json-rpc-peer": "^0.10.0", "julien-f-unzip": "^0.2.1", + "kindof": "^2.0.0", "lodash.assign": "^3.0.0", "lodash.bind": "^3.0.0", "lodash.difference": "^3.2.0", @@ -72,6 +73,7 @@ "lodash.sortby": "^3.1.4", "lodash.startswith": "^3.0.1", "make-error": "^1", + "ms": "^0.7.1", "multikey-hash": "^1.0.1", "proxy-http-request": "0.1.0", "redis": "^0.12.1", diff --git a/src/api.js b/src/api.js index 5cad3a358..f39441792 100644 --- a/src/api.js +++ b/src/api.js @@ -6,7 +6,9 @@ import Bluebird from 'bluebird' import forEach from 'lodash.foreach' import getKeys from 'lodash.keys' import isFunction from 'lodash.isfunction' +import kindOf from 'kindof' import map from 'lodash.map' +import ms from 'ms' import schemaInspector from 'schema-inspector' import { @@ -268,7 +270,7 @@ export default class Api { } async call (session, name, params) { - debug('%s(...)', name) + const startTime = Date.now() const method = this.getMethod(name) if (!method) { @@ -300,14 +302,25 @@ export default class Api { result = true } - debug('%s(...) → %s', name, typeof result) + debug( + '%s(...) [%s] ==> %s', + name, + ms(Date.now() - startTime), + kindOf(result) + ) return result } catch (error) { - if (error instanceof JsonRpcError) { - debug('Error: %s(...) → %s', name, error) - } else { - console.error(error && error.stack || error) + debug( + '%s(...) [%s] ==> %s', + name, + ms(Date.now() - startTime), + error + ) + + const stack = error && error.stack + if (stack) { + console.error(stack) } throw error