Skip to content

Commit

Permalink
remove placeholder from logs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Oct 18, 2023
1 parent 1346a3c commit a29ef3d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 44 deletions.
4 changes: 2 additions & 2 deletions lib/bindings/AMQPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType,
.getLogger()
.debug(
context,
'Sending command execution to device [%s] with apikey [%s] and payload [%s] ',
'Sending command execution to device %s with apikey %s and payload %s ',
apiKey,
device.id,
serializedPayload
Expand All @@ -61,7 +61,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType,
}

function queueListener(msg) {
config.getLogger().debug(context, 'Received [%j]', msg);
config.getLogger().debug(context, 'Received %j', msg);
commons.amqpMessageHandler(msg.fields.routingKey.replace(/\./g, '/'), msg.content.toString());
}

Expand Down
40 changes: 20 additions & 20 deletions lib/bindings/HTTPBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ function parseData(req, res, next) {
let payload;

if (req.body) {
config.getLogger().debug(context, 'Using body [%s]', req.body);
config.getLogger().debug(context, 'Using body %s', req.body);
data = req.body;
regenerateTransid(data);
} else {
payload = req.query.d;
regenerateTransid(payload);
config.getLogger().debug(context, 'Parsing payload [%s]', payload);
config.getLogger().debug(context, 'Parsing payload %s', payload);

try {
if (payload) {
Expand All @@ -129,10 +129,10 @@ function parseData(req, res, next) {
} else {
req.jsonPayload = data;
// This is just for log data
if (req.body !== undefined ) {
if (req.body !== undefined) {
data = data.toString('hex');
}
config.getLogger().debug(context, 'Parsed data: [%j]', data);
config.getLogger().debug(context, 'Parsed data: %j', data);
next();
}
}
Expand All @@ -144,7 +144,7 @@ function parseDataMultipleMeasure(req, res, next) {
let dataArray;
dataArray = [];
if (req.body) {
config.getLogger().debug(context, 'Using body [%s]', req.body);
config.getLogger().debug(context, 'Using body %s', req.body);
if (!Array.isArray(req.body)) {
dataArray.push(req.body);
} else {
Expand All @@ -154,7 +154,7 @@ function parseDataMultipleMeasure(req, res, next) {
} else {
payload = req.query.d;
regenerateTransid(payload);
config.getLogger().debug(context, 'Parsing payload [%s]', payload);
config.getLogger().debug(context, 'Parsing payload %s', payload);
try {
if (payload) {
data = JSON.parse(payload);
Expand All @@ -168,7 +168,7 @@ function parseDataMultipleMeasure(req, res, next) {
next(error);
} else {
req.jsonPayload = dataArray;
config.getLogger().debug(context, 'Parsed data array: [%j]', dataArray);
config.getLogger().debug(context, 'Parsed data array: %j', dataArray);
next();
}
}
Expand All @@ -190,7 +190,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType,
let attrList = iotAgentLib.dataPlugins.utils.getIdTypeServSubServiceFromDevice(device);
attrList = device.staticAttributes ? attrList.concat(device.staticAttributes) : attrList.concat([]);
const ctxt = parser.extractContext(attrList, device);
config.getLogger().debug(context, 'attrList [%j] for device %j', attrList, device);
config.getLogger().debug(context, 'attrList %j for device %j', attrList, device);
// expression result will be the full command payload
let endpointRes = null;
try {
Expand All @@ -207,7 +207,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType,
.getLogger()
.debug(
context,
'Sending command [%s] with payload [%s] and with http options [%j]',
'Sending command %s with payload %s and with http options %j',
cmdName,
serializedPayload,
options
Expand Down Expand Up @@ -259,7 +259,7 @@ function handleIncomingMeasure(req, res, next) {
context = fillService(context, { service: 'n/a', subservice: 'n/a' });
config
.getLogger()
.debug(context, 'Processing multiple HTTP measures for device [%s] with apiKey [%s]', req.deviceId, req.apiKey);
.debug(context, 'Processing multiple HTTP measures for device %s with apiKey %s', req.deviceId, req.apiKey);

function updateCommandHandler(error) {
if (error) {
Expand All @@ -276,7 +276,7 @@ function handleIncomingMeasure(req, res, next) {
.getLogger()
.info(
context,
'Multiple measures for device [%s] with apiKey [%s] successfully updated',
'Multiple measures for device %s with apiKey %s successfully updated',
req.deviceId,
req.apiKey
);
Expand All @@ -293,7 +293,7 @@ function handleIncomingMeasure(req, res, next) {
payloadDataArr = [];

if (req.attr && req.jsonPayload) {
config.getLogger().debug(context, 'Parsing attr [%s] with value [%s]', req.attr, req.jsonPayload);
config.getLogger().debug(context, 'Parsing attr %s with value %s', req.attr, req.jsonPayload);
req.jsonPayload = req.jsonPayload.toString('hex');
const theAttr = [{ name: req.attr, value: req.jsonPayload, type: 'None' }];
attributeArr.push(theAttr);
Expand Down Expand Up @@ -322,7 +322,7 @@ function handleIncomingMeasure(req, res, next) {
.getLogger()
.debug(
context,
'Processing measure device [%s] with attributeArr [%j] attributeValues [%j]',
'Processing measure device %s with attributeArr %j attributeValues %j',
device.name,
attributeArr,
attributeValues
Expand Down Expand Up @@ -444,7 +444,7 @@ function handleConfigurationRequest(req, res, next) {
function handleError(error, req, res, next) {
let code = 500;

config.getLogger().debug(context, 'Error [%s] handling request: %s', error.name, error.message);
config.getLogger().debug(context, 'Error %s handling request: %s', error.name, error.message);

if (error.code && String(error.code).match(/^[2345]\d\d$/)) {
code = error.code;
Expand Down Expand Up @@ -483,7 +483,7 @@ function setPollingAndDefaultTransport(device, callback) {
* @param {Object} device Device object containing all the information about the provisioned device.
*/
function deviceProvisioningHandler(device, callback) {
config.getLogger().debug(context, 'httpbinding.deviceProvisioningHandler [%j]', device);
config.getLogger().debug(context, 'httpbinding.deviceProvisioningHandler %j', device);
setPollingAndDefaultTransport(device, callback);
}

Expand All @@ -493,7 +493,7 @@ function deviceProvisioningHandler(device, callback) {
* @param {Object} device Device object containing all the information about the updated device.
*/
function deviceUpdatingHandler(device, callback) {
config.getLogger().debug(context, 'httpbinding.deviceUpdatingHandler [%j]', device);
config.getLogger().debug(context, 'httpbinding.deviceUpdatingHandler %j', device);
setPollingAndDefaultTransport(device, callback);
}

Expand Down Expand Up @@ -530,15 +530,15 @@ function returnCommands(req, res, next) {
.getLogger()
.error(
context,
'Error updating command status after delivering commands for device [%s]',
'Error updating command status after delivering commands for device %s',
device.id
);
} else {
config
.getLogger()
.debug(
context,
'Command status updated successfully after delivering command list to device [%s]',
'Command status updated successfully after delivering command list to device %s',
device.id
);
}
Expand Down Expand Up @@ -665,10 +665,10 @@ function start(callback) {
const certificate = fs.readFileSync(config.getConfig().http.cert, 'utf8');
const credentials = { key: privateKey, cert: certificate };

config.getLogger().info(context, 'HTTPS Binding listening on port [%s]', config.getConfig().http.port);
config.getLogger().info(context, 'HTTPS Binding listening on port %s', config.getConfig().http.port);
httpBindingServer.server = https.createServer(credentials, httpBindingServer.app);
} else {
config.getLogger().info(context, 'HTTP Binding listening on port [%s]', config.getConfig().http.port);
config.getLogger().info(context, 'HTTP Binding listening on port %s', config.getConfig().http.port);
httpBindingServer.server = http.createServer(httpBindingServer.app);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/bindings/MQTTBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ function executeCommand(apiKey, device, cmdName, serializedPayload, contentType,
.getLogger()
.debug(
context,
'Sending command execution to [%s] with payload [%s] and with mqtt options [%j]',
'Sending command execution to %s with payload %s and with mqtt options %j',
commandTopic,
serializedPayload,
options
Expand Down
30 changes: 9 additions & 21 deletions lib/commonBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function parseMessage(message) {
} catch (e) {
parsedMessage = message.toString('hex');
}
config.getLogger().debug(context, 'stringMessage: [%s] parsedMessage: [%s]', stringMessage, parsedMessage);
config.getLogger().debug(context, 'stringMessage: %s parsedMessage: %s', stringMessage, parsedMessage);
messageArray = [];
if (Array.isArray(parsedMessage)) {
messageArray = parsedMessage;
Expand Down Expand Up @@ -141,12 +141,7 @@ function manageConfigurationRequest(apiKey, deviceId, device, objMessage) {
iotAgentLib.alarms.release(constants.MQTTB_ALARM);
config
.getLogger()
.debug(
ctxt,
'Configuration request finished for APIKey [%s] and Device [%s]',
apiKey,
deviceId
);
.debug(ctxt, 'Configuration request finished for APIKey %s and Device %s', apiKey, deviceId);
}
finishSouthBoundTransaction(null);
}
Expand All @@ -166,7 +161,7 @@ function manageConfigurationRequest(apiKey, deviceId, device, objMessage) {
*/
function singleMeasure(apiKey, deviceId, attribute, device, parsedMessage) {
context = fillService(context, device);
config.getLogger().debug(context, 'Processing single measure for device [%s] with apiKey [%s]', deviceId, apiKey);
config.getLogger().debug(context, 'Processing single measure for device %s with apiKey %s', deviceId, apiKey);

const values = [
{
Expand All @@ -175,7 +170,7 @@ function singleMeasure(apiKey, deviceId, attribute, device, parsedMessage) {
value: parsedMessage[0]
}
];
config.getLogger().debug(context, 'values updates [%s]', JSON.stringify(values));
config.getLogger().debug(context, 'values updates %s', JSON.stringify(values));
iotAgentLib.update(device.name, device.type, '', values, device, function (error) {
if (error) {
config.getLogger().error(
Expand All @@ -188,12 +183,7 @@ function singleMeasure(apiKey, deviceId, attribute, device, parsedMessage) {
} else {
config
.getLogger()
.debug(
context,
'Single measure for device [%s] with apiKey [%s] successfully updated',
deviceId,
apiKey
);
.debug(context, 'Single measure for device %s with apiKey %s successfully updated', deviceId, apiKey);
}
finishSouthBoundTransaction(null);
});
Expand All @@ -211,9 +201,7 @@ function singleMeasure(apiKey, deviceId, attribute, device, parsedMessage) {
function multipleMeasures(apiKey, deviceId, device, messageObj) {
let measure;
const ctxt = fillService(context, device);
config
.getLogger()
.debug(context, 'Processing multiple measures for device [%s] with apiKey [%s]', deviceId, apiKey);
config.getLogger().debug(context, 'Processing multiple measures for device %s with apiKey %s', deviceId, apiKey);

for (let j = 0; j < messageObj.length; j++) {
measure = messageObj[j];
Expand Down Expand Up @@ -242,7 +230,7 @@ function multipleMeasures(apiKey, deviceId, device, messageObj) {
.getLogger()
.info(
ctxt,
'Multiple measures for device [%s] with apiKey [%s] successfully updated',
'Multiple measures for device %s with apiKey %s successfully updated',
deviceId,
apiKey
);
Expand Down Expand Up @@ -288,7 +276,7 @@ function messageHandler(topic, message, protocol) {
config.getLogger().error(
context,
/*jshint quotmark: double */
"Couldn't process message [%s] for device [%j] due to format issues.",
"Couldn't process message %s for device %j due to format issues.",
/*jshint quotmark: single */
message,
device
Expand All @@ -299,7 +287,7 @@ function messageHandler(topic, message, protocol) {
function processDeviceMeasure(error, device) {
if (error) {
context = fillService(context, { service: 'n/a', subservice: 'n/a' });
config.getLogger().warn(context, 'MEASURES-004: Device not found for topic [%s]', topic);
config.getLogger().warn(context, 'MEASURES-004: Device not found for topic %s', topic);
} else {
const localContext = _.clone(context);

Expand Down

0 comments on commit a29ef3d

Please sign in to comment.