Skip to content

Commit

Permalink
Merge pull request #858 from ptcrealitylab/logCleanup
Browse files Browse the repository at this point in the history
Cleaned up logging
  • Loading branch information
dangond-ptc authored Aug 2, 2023
2 parents ded5f85 + f44aaef commit 04721be
Show file tree
Hide file tree
Showing 36 changed files with 171 additions and 775 deletions.
1 change: 0 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ if (!fs.existsSync(objectsPath) &&

// create objects folder at objectsPath if necessary
if (!fs.existsSync(objectsPath)) {
console.log('created objects directory at ' + objectsPath);
fs.mkdirSync(objectsPath);
}

Expand Down
12 changes: 2 additions & 10 deletions controllers/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ const addNewBlock = function (objectID, frameID, nodeID, blockID, body) {
});
utilities.writeObjectToFile(objects, objectID, globalVariables.saveToDisk);

console.log('added block: ' + blockID);
updateStatus = 'added';
}
return updateStatus;
Expand All @@ -91,7 +90,6 @@ const deleteBlock = function (objectID, frameID, nodeID, blockID, lastEditor) {
if (foundNode) {

delete foundNode.blocks[blockID];
console.log('deleted block: ' + blockID);

var thisLinks = foundNode.links;
// Make sure that no links are connected to deleted blocks
Expand Down Expand Up @@ -123,9 +121,7 @@ const deleteBlock = function (objectID, frameID, nodeID, blockID, lastEditor) {
*/
const postBlockPosition = function (objectID, frameID, nodeID, blockID, body) {
var updateStatus = 'nothing happened';

console.log('changing Position for :' + objectID + ' : ' + nodeID + ' : ' + blockID);


Check warning on line 124 in controllers/block.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed
var foundNode = utilities.getNode(objects, objectID, frameID, nodeID);

if (foundNode) {
Expand Down Expand Up @@ -171,13 +167,9 @@ const triggerBlockSearch = function (blockID, body, callback) {
};

const triggerBlock = function (objectID, frameID, nodeID, blockID, body) {
console.log('triggerBlock', objectID, frameID, nodeID, blockID, body);
var foundNode = utilities.getNode(objects, objectID, frameID, nodeID);
if (foundNode) {
var block = foundNode.blocks[blockID];
console.log('block', block);
console.log('set block ' + block.type + ' (' + blockID + ') to ' + body.value);

block.data[0].value = body.value;
engine.blockTrigger(objectID, frameID, nodeID, blockID, 0, block);
}
Expand Down Expand Up @@ -225,4 +217,4 @@ module.exports = {
triggerBlock: triggerBlock,
getLogicBlockList: getLogicBlockList,
setup: setup
};
};
2 changes: 0 additions & 2 deletions controllers/blockLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const addLogicLink = function (objectID, frameID, nodeID, linkID, body) {
// write the object state to the permanent storage.
utilities.writeObjectToFile(objects, objectID, globalVariables.saveToDisk);

console.log('added link: ' + linkID);
updateStatus = 'added';
} else {
updateStatus = 'found endless Loop';
Expand All @@ -61,7 +60,6 @@ const deleteLogicLink = function (objectID, frameID, nodeID, linkID, lastEditor)
});
utilities.writeObjectToFile(objects, objectID, globalVariables.saveToDisk);

console.log('deleted link: ' + linkID);
updateStatus = 'deleted: ' + linkID + ' in logic ' + nodeID + ' in frame: ' + frameID + ' from object: ' + objectID;
}
return updateStatus;
Expand Down
15 changes: 1 addition & 14 deletions controllers/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const addFrameToObject = function (objectKey, frameKey, frame, callback) {
object.frames = {};
}

utilities.createFrameFolder(object.name, frame.name, dirname, globalVariables.debug, frame.location);
utilities.createFrameFolder(object.name, frame.name, dirname, frame.location);

var newFrame = new Frame(frame.objectId, frameKey);
newFrame.name = frame.name;
Expand Down Expand Up @@ -164,8 +164,6 @@ const addPublicData = function(objectID, frameID, body, callback) {
};

const copyFrame = function(objectID, frameID, body, callback) {
console.log('making a copy of frame', frameID);

utilities.getFrameAsync(objects, objectID, frameID, function (error, object, frame) {
if (error) {
callback(404, error);
Expand Down Expand Up @@ -274,8 +272,6 @@ const updateFrame = function(objectID, frameID, body, callback) {
};

const deleteFrame = function(objectId, frameId, body, callback) {
console.log('delete frame from server', objectId, frameId);

var object = utilities.getObject(objects, objectId);
if (!object) {
callback(404, {failure: true, error: 'object ' + objectId + ' not found'});
Expand Down Expand Up @@ -303,7 +299,6 @@ const deleteFrame = function(objectId, frameId, body, callback) {
}).map(function (publicData) {
return publicData.data;
});
console.log('frame being deleted contains these video paths: ', videoPaths);
videoPaths.forEach(function (videoPath) {
// convert videoPath into path on local filesystem // TODO: make this independent on OS path-extensions
var urlArray = videoPath.split('/');
Expand Down Expand Up @@ -412,8 +407,6 @@ const setPinned = function(objectID, frameID, body, callback) {
* @todo this function is a mess, fix it up
*/
const changeSize = function (objectID, frameID, nodeID, body, callback) { // eslint-disable-line no-inner-declarations
console.log('changing Size for :' + objectID + ' : ' + frameID + ' : ' + nodeID);

utilities.getFrameOrNode(objects, objectID, frameID, nodeID, function (error, object, frame, node) {
if (error) {
callback(404, error);
Expand All @@ -422,9 +415,6 @@ const changeSize = function (objectID, frameID, nodeID, body, callback) { // esl

var activeVehicle = node || frame; // use node if it found one, frame otherwise

// console.log('really changing size for ... ' + activeVehicle.uuid, body);

// console.log("post 2");
var updateStatus = 'nothing happened';

// the reality editor will overwrite all properties from the new frame except these.
Expand Down Expand Up @@ -463,7 +453,6 @@ const changeSize = function (objectID, frameID, nodeID, body, callback) { // esl
frame.ar.y = body.arY;
}

// console.log(req.body);
// ask the devices to reload the objects
didUpdate = true;
}
Expand Down Expand Up @@ -501,8 +490,6 @@ const changeSize = function (objectID, frameID, nodeID, body, callback) { // esl
* @param callback
*/
const changeVisualization = function(objectKey, frameKey, body, callback) {
console.log('change visualization');

var newVisualization = body.visualization;
var oldVisualizationPositionData = body.oldVisualizationPositionData;

Expand Down
10 changes: 1 addition & 9 deletions controllers/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ function getLinkData(fullEntry, wasAdded) {
var linkAddedData = null;

if (fullEntry) {
// console.log('getLinkData', fullEntry);

var linkObjectA = fullEntry['objectA'];
var linkObjectB = fullEntry['objectB'];
var linkFrameA = fullEntry['frameA'];
Expand Down Expand Up @@ -50,9 +48,8 @@ function getLinkData(fullEntry, wasAdded) {
nameNodeA: nodeAName,
nameNodeB: nodeBName
};

} else {
console.log('thisObject does not exist');
console.error('thisObject does not exist');
}
return linkAddedData;
}
Expand All @@ -70,8 +67,6 @@ const newLink = function (objectID, frameID, linkID, body) {

var foundFrame = utilities.getFrame(objects, objectID, frameID);
if (foundFrame) {
console.log('found frame to add link to');

// todo the first link in a chain should carry a UUID that propagates through the entire chain each time a change is done to the chain.
// todo endless loops should be checked by the time of creation of a new loop and not in the Engine
body.loop = (body.objectA === body.objectB &&
Expand All @@ -80,7 +75,6 @@ const newLink = function (objectID, frameID, linkID, body) {

utilities.forEachLinkInFrame(utilities.getFrame(objects, body.objectA, body.frameA), function (thisLink) {
if (!body.loop) {
console.log('link already exists');
body.loop = (body.objectA === thisLink.objectA &&
body.objectB === thisLink.objectB &&
body.frameA === thisLink.frameA &&
Expand All @@ -94,7 +88,6 @@ const newLink = function (objectID, frameID, linkID, body) {

if (!body.loop) {
foundFrame.links[linkID] = body;
console.log('added link: ' + linkID);
// write the object state to the permanent storage.
utilities.writeObjectToFile(objects, objectID, globalVariables.saveToDisk);

Expand Down Expand Up @@ -179,7 +172,6 @@ const deleteLink = function (objectKey, frameKey, linkKey, editorID) {
delete socketArray[destinationIp];
}

console.log('deleted link: ' + linkKey);
updateStatus = 'deleted: ' + linkKey + ' in object: ' + objectKey + ' frame: ' + frameKey;
}
return updateStatus;
Expand Down
28 changes: 4 additions & 24 deletions controllers/logicNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const addLogicNode = function (objectID, frameID, nodeID, body) {
lastEditor: body.lastEditor
});

console.log('added logic node: ' + nodeID);
updateStatus = 'added';
}
return updateStatus;
Expand All @@ -74,7 +73,6 @@ const deleteLogicNode = function (objectID, frameID, nodeID, lastEditor) {
console.warn('(Logic) Node exists without proper prototype: ' + nodeID);
}
delete foundFrame.nodes[nodeID];
console.log('deleted node: ' + nodeID);

//todo check all links as well in object
// Make sure that no links are connected to deleted objects
Expand Down Expand Up @@ -109,9 +107,7 @@ const deleteLogicNode = function (objectID, frameID, nodeID, lastEditor) {
*/
function changeNodeSize(objectID, frameID, nodeID, body, callback) {
var updateStatus = 'nothing happened';

console.log('changing Size for :' + objectID + ' : ' + nodeID);


Check warning on line 110 in controllers/logicNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed
utilities.getNodeAsync(objects, objectID, frameID, nodeID, function (error, object, frame, node) {
if (error) {
callback(404, error);
Expand Down Expand Up @@ -145,8 +141,6 @@ function changeNodeSize(objectID, frameID, nodeID, body, callback) {
}

function rename(objectID, frameID, nodeID, body, callback) {
console.log('received name for', objectID, frameID, nodeID);

utilities.getNodeAsync(objects, objectID, frameID, nodeID, function (error, object, frame, node) {
if (error) {
callback(404, error);
Expand All @@ -162,8 +156,6 @@ function rename(objectID, frameID, nodeID, body, callback) {
}

function uploadIconImage(objectID, frameID, nodeID, req, callback) {
console.log('received icon image for', objectID, frameID, nodeID);

utilities.getNodeAsync(objects, objectID, frameID, nodeID, function (error, object, frame, node) {
if (error) {
callback(404, error);
Expand All @@ -180,9 +172,7 @@ function uploadIconImage(objectID, frameID, nodeID, req, callback) {
keepExtensions: true,
accept: 'image/jpeg'
});

console.log('created form');


Check warning on line 175 in controllers/logicNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed
form.on('error', function (err) {
callback(500, err);
return;
Expand All @@ -191,25 +181,17 @@ function uploadIconImage(objectID, frameID, nodeID, req, callback) {
var rawFilepath = form.uploadDir + '/' + nodeID + '_fullSize.jpg';

if (fs.existsSync(rawFilepath)) {
console.log('deleted old raw file');
fs.unlinkSync(rawFilepath);
}

form.on('fileBegin', function (name, file) {
console.log('fileBegin loading', name, file);
file.path = rawFilepath;
});

console.log('about to parse');


Check warning on line 190 in controllers/logicNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Trailing spaces not allowed
form.parse(req, function (err, fields) {

Check warning on line 191 in controllers/logicNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'err' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 191 in controllers/logicNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'fields' is defined but never used. Allowed unused args must match /^_/u
console.log('successfully created icon image', err, fields);

var resizedFilepath = form.uploadDir + '/' + nodeID + '.jpg';
console.log('attempting to write file to ' + resizedFilepath);

if (fs.existsSync(resizedFilepath)) {
console.log('deleted old resized file');
fs.unlinkSync(resizedFilepath);
}

Expand All @@ -220,8 +202,6 @@ function uploadIconImage(objectID, frameID, nodeID, req, callback) {
Jimp.read(rawFilepath).then(image => {
return image.resize(200, 200).write(resizedFilepath);
}).then(() => {
console.log('done resizing');

if (node) {
node.iconImage = 'custom'; //'http://' + object.ip + ':' + serverPort + '/logicNodeIcon/' + object.name + '/' + nodeID + '.jpg';
utilities.writeObjectToFile(objects, objectID, globalVariables.saveToDisk);
Expand All @@ -237,7 +217,7 @@ function uploadIconImage(objectID, frameID, nodeID, req, callback) {
}
callback(200, {success: true});
}).catch(err => {

Check warning on line 219 in controllers/logicNode.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'err' is already declared in the upper scope on line 191 column 35
console.log('error resizing', err);
console.error('Error resizing image', err);
callback(500, err);
});
}
Expand Down
6 changes: 0 additions & 6 deletions controllers/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const addNodeToFrame = function (objectKey, frameKey, nodeKey, body, callback) {
for (let key in body) {
if (node.hasOwnProperty(key)) {
node[key] = body[key];
// console.log(`addNodeToFrame copied over value ${key}=${body[key]}`);
}
}

Expand Down Expand Up @@ -135,7 +134,6 @@ const deleteNodeLock = function (objectKey, frameKey, nodeKey, password) {
* @todo this function is a mess, fix it up
*/
const changeSize = function (objectID, frameID, nodeID, body, callback) { // eslint-disable-line no-inner-declarations
console.log('changing Size for :' + objectID + ' : ' + frameID + ' : ' + nodeID);
if (nodeID === 'null') { nodeID = null; }

utilities.getFrameOrNode(objects, objectID, frameID, nodeID, function (error, object, frame, node) {
Expand All @@ -146,9 +144,6 @@ const changeSize = function (objectID, frameID, nodeID, body, callback) { // esl

var activeVehicle = node || frame; // use node if it found one, frame otherwise

// console.log('really changing size for ... ' + activeVehicle.uuid, body);

// console.log("post 2");
var updateStatus = 'nothing happened';

// the reality editor will overwrite all properties from the new frame except these.
Expand Down Expand Up @@ -185,7 +180,6 @@ const changeSize = function (objectID, frameID, nodeID, body, callback) { // esl
frame.ar.y = body.arY;
}

// console.log(req.body);
// ask the devices to reload the objects
didUpdate = true;
}
Expand Down
Loading

0 comments on commit 04721be

Please sign in to comment.