-
-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimization of log string generation #2292
base: master
Are you sure you want to change the base?
Conversation
Thank you for the pull request. I have a number of questions and requests:
Please note that I am aware of the fact that the PTVO implementation with dynamic states is an outlier as far as integration goes - an elevated logging good for the PTVO type devices will generate far too much data for 'standard' devices, but PTVO devices make less than 1% of the active devices. A. |
I think the bot has an issue with missing ;, especially in if then else constructs. But I am not sure about it. As it is not that easy for me to modify the files, I'd thought to ask you to look into this and fix it.
This is a misconception. The device debug was explicitly introduced to allow tracking data sent to and from a device without putting the entire adapter in debug mode. As such, it should generate as few messages as sensible, not as detailed as possible, in order for us to be able to document the expected message flow and pinpoint issues to people who have no experience with the entire process. Any detailed analysis still requires for the adapter to be run in debug mode.
My idea was to move the check, ensuring that the elevated messages only come when debug messages do not come. This removes the need to check for each message if to send it to the elevated warning or debug message, and the code can simply call the debug message function without any additional check. Now this does not mean that the existing check must be removed - but it is no longer required in such a scenario. A. |
- Change log level for "handleDeviceJoined" message
devStates.states.filter(statedesc => payload.hasOwnProperty(statedesc.prop || statedesc.id)) | ||
); | ||
if (!devStates) { | ||
if (has_debug) this.error(`ELEVATED IE2 (publishToState): no device states for device ${devId} type '${model}'`) |
Check notice
Code scanning / CodeQL
Semicolon insertion Note
the enclosing function
@@ -1090,7 +1108,12 @@ | |||
if (typeof data === 'string') { | |||
logger(`${msg}. ${data}`); | |||
} else { | |||
logger(`${msg}. ${safeJsonStringify(data)}`); | |||
if ((this.log.level==level) || | |||
((this.log.level='warn')&&(level='error')) || |
Check warning
Code scanning / CodeQL
Useless conditional Warning
This logical 'and' expression can be replaced with a comma expression.
@@ -1090,7 +1108,12 @@ | |||
if (typeof data === 'string') { | |||
logger(`${msg}. ${data}`); | |||
} else { | |||
logger(`${msg}. ${safeJsonStringify(data)}`); | |||
if ((this.log.level==level) || | |||
((this.log.level='warn')&&(level='error')) || |
Check warning
Code scanning / CodeQL
Useless conditional Warning
@@ -1090,7 +1108,12 @@ | |||
if (typeof data === 'string') { | |||
logger(`${msg}. ${data}`); | |||
} else { | |||
logger(`${msg}. ${safeJsonStringify(data)}`); | |||
if ((this.log.level==level) || | |||
((this.log.level='warn')&&(level='error')) || |
Check warning
Code scanning / CodeQL
Useless conditional Warning
logger(`${msg}. ${safeJsonStringify(data)}`); | ||
if ((this.log.level==level) || | ||
((this.log.level='warn')&&(level='error')) || | ||
((this.log.level='info')&&(level='error' || level=='warn')) |
Check warning
Code scanning / CodeQL
Useless conditional Warning
logger(`${msg}. ${safeJsonStringify(data)}`); | ||
if ((this.log.level==level) || | ||
((this.log.level='warn')&&(level='error')) || | ||
((this.log.level='info')&&(level='error' || level=='warn')) |
Check warning
Code scanning / CodeQL
Useless conditional Warning
((this.log.level='warn')&&(level='error')) || | ||
((this.log.level='info')&&(level='error' || level=='warn')) | ||
) | ||
logger(`${msg}. ${safeJsonStringify(data)}`) |
Check notice
Code scanning / CodeQL
Semicolon insertion Note
the enclosing function
In this form, I am unwilling to merge the PR: Please consider the following requests:
Note that work is in progress to generate a debug interface in the adapter which both displays these messages as well as allows interactive tagging of devices for debug in order to make this more accessible to end users. Also note that the ID's attached to the messages are (at this time) not fixed so you are free to reassign them as long as the general rule that messages should appear with increasing numbers in the log remains heeded. In the end, ALL elevated messages will be required to have a tag for easy identification. A. |
serialization of objects via JSON.stringify method may consume unnecessary resources.
This is especially noticed for the PIVO firmware, where the serialized "entity" object takes up to 90 kbytes. and it is called very often