From 2f1cad89fac3360822ed69bdcaeeeafaa5ba96db Mon Sep 17 00:00:00 2001 From: zetxx Date: Tue, 19 Nov 2019 18:00:37 +0200 Subject: [PATCH] fix: logging --- lib/base.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/base.js b/lib/base.js index 2ad18b6..5e90721 100644 --- a/lib/base.js +++ b/lib/base.js @@ -11,11 +11,11 @@ class Brid { } async start() { - this.log('debug', {in: 'base.start'}); + this.log('info', {in: 'base.start'}); } async stop() { - this.log('debug', {in: 'base.stop'}); + this.log('info', {in: 'base.stop'}); } getApiRequestId() { @@ -28,7 +28,7 @@ class Brid { } findMethod({method, channel, direction = 'out'} = {}) { - this.log('debug', {in: 'base.findMethod', description: `try find method ${channel}.${method}.${direction || ''}`, method, channel, direction}); + this.log('info', {in: 'base.findMethod', description: `try find method ${channel}.${method}.${direction || ''}`, method, channel, direction}); let found = ((direction && [`${method}.${direction}`, direction, method]) || [method]).find((v) => this.apiMethods[channel] && this.apiMethods[channel][v]); if (!found) { @@ -48,7 +48,7 @@ class Brid { } registerMethod({method, channel, fn, meta}) { - this.log('debug', {in: 'base.registerMethod', description: `register method: ${channel}.${method}`, method, channel, meta}); + this.log('info', {in: 'base.registerMethod', description: `register method: ${channel}.${method}`, method, channel, meta}); !this.apiMethods[channel] && (this.apiMethods[channel] = {}); this.apiMethods[channel][method] = async(ctx, ...args) => { let [message, meta] = args; @@ -58,12 +58,12 @@ class Brid { } registerApiMethod({method, fn, meta = {}}) { - this.log('debug', {in: 'base.registerApiMethod', method, meta}); + this.log('info', {in: 'base.registerApiMethod', method, meta}); this.registerMethod({method, fn, channel: 'api', meta}); } registerExternalMethod({method, fn, meta = {}}) { - this.log('debug', {in: 'base.registerExternalMethod', method, meta}); + this.log('info', {in: 'base.registerExternalMethod', method, meta}); this.registerMethod({method, fn, channel: 'external', meta}); } @@ -143,7 +143,7 @@ class Brid { // when someone hits api method apiRequestReceived({message, meta}) { - this.log('debug', {in: 'base.apiRequestReceived', count: 1, message, meta}); + this.log('info', {in: 'base.apiRequestReceived', count: 1, message, meta}); return new Promise(async(resolve, reject) => { // create meta const m = Object.assign({}, meta, {resolve, reject, apiRequestId: this.getApiRequestId()}); @@ -194,7 +194,7 @@ class Brid { // when external response received, response to previously api request, its is called when response from external are matched async apiResponseReceived({result, error, meta: {apiRequestId = -1}} = {}) { const message = (result && {result}) || (error && {error}) || undefined; - this.log('debug', {in: 'base.apiResponseReceived', result, error, apiRequestId}); + this.log('info', {in: 'base.apiResponseReceived', result, error, apiRequestId}); if (this.isApiRequest(apiRequestId) >= 0) { // request exists var {meta} = this.findApiRequest(apiRequestId); // find request if (meta.timeoutId) { // clear timeout if any @@ -208,7 +208,7 @@ class Brid { try { let fn = this.findApiMethod({method: meta.method, direction: 'out'}); // find api method let fnResult = await fn(this.getInternalCommunicationContext(meta), message, Object.assign({}, meta)); // execute api method - this.log('debug', {in: 'base.apiResponseReceived', description: 'resolve request', result, error, apiRequestId}); + this.log('info', {in: 'base.apiResponseReceived', description: 'resolve request', result, error, apiRequestId}); return meta.resolve(fnResult); } catch (e) { this.log('error', {in: 'base.apiResponseReceived', result, error, apiRequestId}); @@ -219,7 +219,7 @@ class Brid { } // when someone hits external async externalIn({result, error, meta = {}} = {}) { - this.log('debug', {in: 'base.externalIn', result, error, meta}); + this.log('info', {in: 'base.externalIn', result, error, meta}); var {method, apiRequestId, isNotification} = meta; const message = (result && {result}) || (error && {error}) || undefined; // find if there is api request pending by id @@ -255,10 +255,10 @@ class Brid { let fnExt = this.findExternalMethod({method}); let transformedMsg = await fnExt(this.getInternalCommunicationContext(meta), message, Object.assign({}, meta)); if (transformedMsg) { // respond to external if result from transform function is not false. - this.log('debug', {in: 'base.externalIn', description: 'external request is NOT response of api request > send response to external', result, error, meta}); + this.log('info', {in: 'base.externalIn', description: 'external request is NOT response of api request > send response to external', result, error, meta}); return this.externalOut({result: transformedMsg, meta}); } - this.log('debug', {in: 'base.externalIn', description: 'external request is NOT response of api request > don\'t send response to external because user transform function returned false', result, error, meta, transformedMsg}); + this.log('info', {in: 'base.externalIn', description: 'external request is NOT response of api request > don\'t send response to external because user transform function returned false', result, error, meta, transformedMsg}); return {...message, meta: Object.assign({deadIn: 1}, meta)}; } catch (e) { this.log('error', {in: 'base.externalIn', result, error, meta});