Skip to content

Commit

Permalink
Merge pull request #772 from telefonicaid/task/remove_placeholders_logs
Browse files Browse the repository at this point in the history
remove placeholders in logs and \n
  • Loading branch information
fgalan committed Oct 20, 2023
2 parents f58c562 + 11c142f commit 70399b7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 35 deletions.
4 changes: 2 additions & 2 deletions lib/bindings/HTTPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/bindings/MQTTBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 =
Expand All @@ -199,17 +199,17 @@ 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,
options
);
}
});
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();
}
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
22 changes: 5 additions & 17 deletions lib/commandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -207,20 +200,15 @@ 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
);
} 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);
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions lib/iotaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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
);
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/transportSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down

0 comments on commit 70399b7

Please sign in to comment.