From 11c142f6e8b267e6261d72a5161109efedfe9f23 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Fri, 20 Oct 2023 09:55:07 +0200 Subject: [PATCH] remove placeholders in logs and \n --- lib/bindings/HTTPBinding.js | 4 ++-- lib/bindings/MQTTBinding.js | 14 +++++++------- lib/commandHandler.js | 22 +++++----------------- lib/iotaUtils.js | 8 ++++---- lib/transportSelector.js | 10 +++++----- 5 files changed, 23 insertions(+), 35 deletions(-) diff --git a/lib/bindings/HTTPBinding.js b/lib/bindings/HTTPBinding.js index d907a238a..0ef86551e 100644 --- a/lib/bindings/HTTPBinding.js +++ b/lib/bindings/HTTPBinding.js @@ -224,7 +224,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType, .getLogger() .info( context, - 'Cmd:\n %j was sent to the device %s with http options %j', + 'Cmd: %j was sent to the device %s with http options %j', serializedPayload, cmdName, options @@ -236,7 +236,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType, .getLogger() .info( context, - 'Cmd:\n %j was sent to the device %s with http options %j', + 'Cmd: %j was sent to the device %s with http options %j', serializedPayload, cmdName, options diff --git a/lib/bindings/MQTTBinding.js b/lib/bindings/MQTTBinding.js index 547b64ef7..b512d5bf3 100644 --- a/lib/bindings/MQTTBinding.js +++ b/lib/bindings/MQTTBinding.js @@ -146,7 +146,7 @@ function recreateSubscriptions(callback) { callback(error); } else { iotAgentLib.alarms.release(constants.MQTTB_ALARM); - config.getLogger().info(context, 'Successfully subscribed to the following topics:\n%j\n', topics); + config.getLogger().info(context, 'Successfully subscribed to the following topics: %j', topics); if (callback) { callback(null); } @@ -175,7 +175,7 @@ function sendConfigurationToDevice(apiKey, deviceId, results, callback) { if (config.getConfig().mqtt.retain === true) { options.retain = config.getConfig().mqtt.retain; } - config.getLogger().debug(context, 'Sending requested configuration to the device:\n %j', configurations); + config.getLogger().debug(context, 'Sending requested configuration to the device: %j', configurations); const leadingSlash = config.getConfig().mqtt.avoidLeadingSlash ? '' : '/'; const commandTopic = @@ -199,7 +199,7 @@ function sendConfigurationToDevice(apiKey, deviceId, results, callback) { .getLogger() .error( context, - 'Error %j in Configuration:\n %j sent to the device %s with mqtt options %j', + 'Error %j in Configuration: %j sent to the device %s with mqtt options %j', error, JSON.stringify(configurations), commandTopic, @@ -207,9 +207,9 @@ function sendConfigurationToDevice(apiKey, deviceId, results, callback) { ); } }); - config.getLogger().info(context, 'Configuration:\n %j was sent to the device: %s', configurations, commandTopic); + config.getLogger().info(context, 'Configuration: %j was sent to the device: %s', configurations, commandTopic); } else { - config.getLogger().error(context, 'Configuration:\n %j was not set to the device: %s due to not connected', configurations, commandTopic); + config.getLogger().error(context, 'Configuration: %j was not set to the device: %s due to not connected', configurations, commandTopic); } callback(); } @@ -407,7 +407,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType, .getLogger() .error( context, - 'Error %j in Cmd:\n %j sent to the device %s with mqtt options %j', + 'Error %j in Cmd: %j sent to the device %s with mqtt options %j', error, serializedPayload, commandTopic, @@ -419,7 +419,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType, .getLogger() .info( context, - 'Cmd:\n %j was sent to the device %s with mqtt options %j', + 'Cmd: %j was sent to the device %s with mqtt options %j', serializedPayload, commandTopic, options diff --git a/lib/commandHandler.js b/lib/commandHandler.js index e2b86925f..d9830effc 100644 --- a/lib/commandHandler.js +++ b/lib/commandHandler.js @@ -104,7 +104,7 @@ function generateCommandExecution(apiKey, device, attribute) { .getLogger() .debug( context, - 'Sending command execution to device [%s] with apikey [%s] and payload [%j] ', + 'Sending command execution to device %s with apikey %s and payload %j ', device.id, apiKey, payload @@ -134,14 +134,7 @@ function generateCommandExecution(apiKey, device, attribute) { function commandHandler(id, type, service, subservice, attributes, callback) { config .getLogger() - .debug( - context, - 'Handling command %j for device [%s] in service [%s - %s]', - attributes, - id, - service, - subservice - ); + .debug(context, 'Handling command %j for device %s in service %s - %s', attributes, id, service, subservice); function concat(previous, current) { previous = previous.concat(current); @@ -153,7 +146,7 @@ function commandHandler(id, type, service, subservice, attributes, callback) { config.getLogger().error( context, - "COMMAND-001: Command execution could not be handled, as device for entity [%s] [%s] wasn't found", + "COMMAND-001: Command execution could not be handled, as device for entity %s %s wasn't found", id, type @@ -207,7 +200,7 @@ function updateCommand(apiKey, deviceId, device, messageObj) { context, "COMMANDS-002: Couldn't update command status in the Context broker " + - 'for device [%s] with apiKey [%s]: %s', + 'for device %s with apiKey %s: %s', device.id, apiKey, error @@ -215,12 +208,7 @@ function updateCommand(apiKey, deviceId, device, messageObj) { } else { config .getLogger() - .debug( - context, - 'Single measure for device [%s] with apiKey [%s] successfully updated', - device.id, - apiKey - ); + .debug(context, 'Single measure for device %s with apiKey %s successfully updated', device.id, apiKey); } }); } diff --git a/lib/iotaUtils.js b/lib/iotaUtils.js index 601f81856..ff1f1c0bf 100644 --- a/lib/iotaUtils.js +++ b/lib/iotaUtils.js @@ -97,7 +97,7 @@ function manageConfiguration(apiKey, deviceId, device, objMessage, sendFunction, .getLogger() .error( context, - 'CONFIG-002: There was an error subscribing device [%s] to attributes [%j]', + 'CONFIG-002: There was an error subscribing device %s to attributes %j', device.name, objMessage.fields ); @@ -106,7 +106,7 @@ function manageConfiguration(apiKey, deviceId, device, objMessage, sendFunction, .getLogger() .debug( context, - 'Successfully subscribed device [%s] to attributes[%j]', + 'Successfully subscribed device %s to attributes %j', device.name, objMessage.fields ); @@ -115,7 +115,7 @@ function manageConfiguration(apiKey, deviceId, device, objMessage, sendFunction, callback(error); }); } else { - config.getLogger().error(context, 'CONFIG-003: Unknown command type from device [%s]', device.name); + config.getLogger().error(context, 'CONFIG-003: Unknown command type from device %s', device.name); callback(); } } @@ -228,7 +228,7 @@ function retrieveDevice(deviceId, apiKey, transport, callback) { config.getLogger().error( context, - "MEASURES-001: Couldn't find device data for APIKey [%s] and DeviceId[%s]", + "MEASURES-001: Couldn't find device data for APIKey %s and DeviceId %s", apiKey, deviceId diff --git a/lib/transportSelector.js b/lib/transportSelector.js index cdc1b3988..c4652f348 100644 --- a/lib/transportSelector.js +++ b/lib/transportSelector.js @@ -41,25 +41,25 @@ function startTransportBindings(newConfig, callback) { const bindings = fs.readdirSync(path.join(__dirname, './bindings')); - transportBindings = bindings.map(function(item) { + transportBindings = bindings.map(function (item) { return require('./bindings/' + item); }); /* eslint-disable no-unused-vars */ - async.map(transportBindings, invokeBinding, function(error) { + async.map(transportBindings, invokeBinding, function (error) { callback(); }); } function createExecutionsForBinding(argument, functionName, protocol) { - config.getLogger().debug('Creating execution for function [%s] and protocol [%s]', functionName, protocol); + config.getLogger().debug('Creating execution for function %s and protocol %s', functionName, protocol); function addHandler(current, binding) { if (binding[functionName] && (!protocol || binding.protocol === protocol)) { const args = [binding[functionName]].concat(argument); const boundFunction = binding[functionName].bind.apply(binding[functionName], args); - config.getLogger().debug('Binding found for function [%s] and protocol [%s]', functionName, protocol); + config.getLogger().debug('Binding found for function %s and protocol %s', functionName, protocol); current.push(boundFunction); } @@ -79,7 +79,7 @@ function createExecutionsForBinding(argument, functionName, protocol) { * @param {String} protocol Transport protocol where the function must be executed. */ function applyFunctionFromBinding(argument, functionName, protocol, callback) { - config.getLogger().debug('Looking for bindings for the function [%s] and protocol [%s]', functionName, protocol); + config.getLogger().debug('Looking for bindings for the function %s and protocol %s', functionName, protocol); async.series(createExecutionsForBinding(argument, functionName, protocol), callback); }