Don't write full stack trace to system console on exceptions while trying to send messages to IoT Hub#44
Don't write full stack trace to system console on exceptions while trying to send messages to IoT Hub#44JMayrbaeurl wants to merge 10 commits intoAzure:masterfrom JMayrbaeurl:bosch-dev
Conversation
|
@JMayrbaeurl, It will cover your contributions to all Microsoft-managed open source projects. |
|
@JMayrbaeurl, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request. |
| for (StackTraceElement el : e.getStackTrace()) | ||
| { | ||
| // JMayrbaeurl 2017-03-10: Should be replaced with real logging setup | ||
| System.out.println(el); |
There was a problem hiding this comment.
I think we have logger use in this module and would recommend using logger here instead of println. So that interested users can debug it using log.
And if we go the route of logger you woudn't really need verboseErrMessaging anymore. By default you can always write fatal error message in this case.
|
Thanks for your PR. Can you please address my comment and then we pull it in. |
Merged changes from Release 2017-03-10
Merged latest release changes
added configuration for stack trace writting
|
Addressed your comment. Added slf4j logging to the classes that send and receive messages to and from the IoT Hub. Full stack traces are only written to the log when using debug level on logging |
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-api</artifactId> | ||
| </dependency> |
There was a problem hiding this comment.
Thank you for proving a sample. But for now we will investigate this option and add support to better logging in future. As of now if we let this change in then only part of the SDK will be supporting this method of logging and rest will still be dependent on log4j. So I will hold off on this change.
There was a problem hiding this comment.
This is no breaking change and I really don't like to make changes that introduce an old error once again. Transitioning to logging facades is no enhancement, but a bug fix and has to be done asap. It's probably better to change the CustomLogger or even better completely remove it/exchange it by using slf4j logging facades. This can be done in an hour! If you don't accept the PR this way, I will close it and will open an according issue for it.
There was a problem hiding this comment.
Sounds good. If you are willing to provide a PR then please do so. I will be happy to review it.
Just to let you know we expect the following from the PR-
- Please remove any occurrences of log4J from requirement docs (https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-client/devdoc/requirement_docs/com/microsoft/azure/iothub), unit tests(https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-client/src/test/java/tests/unit/com/microsoft/azure/sdk/iot/device) and code.
- Provide an implementation, requirements and unit tests for new logging method for the entire SDK and replace the occurrence of log4j logger with your approach.
- Update github documents (https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-samples#logging) and our send-receive sample (https://github.com/Azure/azure-iot-sdk-java/tree/master/device/iot-device-samples/send-receive-sample) with proper instructions for logging.
If you wish to it can be a separate PR as well.
There was a problem hiding this comment.
I have done this in a separate PR #57 . I tried to follow the three steps described above as good as possible.
| * Private logger for class | ||
| */ | ||
| final Logger logger = LoggerFactory.getLogger(IotHubReceiveTask.class); | ||
|
|
There was a problem hiding this comment.
Can this be changed to the logger (CustomLogger) in use currently until we address proper logging method.
There was a problem hiding this comment.
No. Can't be changed to CustomLogger. See comment above.
|
I'm very much interested in the original change that you mentioned is required by the customer related to printing stack trace and moving it to logger. If you can use custom logger at the moment until we address better logging across the SDK, I can pull this change in. |
|
Since this is a critical bug fix for our partner I have changed back the logger implementation to use the CustomLogger class instead of slf4j (still believe that this is the only way to do logging). |
Merged 1.0.22 release changes
|
|
||
| if (transport == null) | ||
| throw new IllegalArgumentException("Parameter 'transport' must not be null"); | ||
|
|
There was a problem hiding this comment.
Move this check to line 22
There was a problem hiding this comment.
@prmathur-microsoft : With current setup constructors of IotHubSendTask and IotHubReceiveTask will write a wrong log error message when parameter 'transport' is not null. If it's null, no log message will be written, since the code is no longer reachable
| this.transport = transport; | ||
|
|
||
| if (transport == null) | ||
| throw new IllegalArgumentException("Parameter 'transport' must not be null"); |
There was a problem hiding this comment.
Move this check to line 23
There was a problem hiding this comment.
@prmathur-microsoft : With current setup constructors of IotHubSendTask and IotHubReceiveTask will write a wrong log error message when parameter 'transport' is not null. If it's null, no log message will be written, since the code is no longer reachable
|
This PR did not have the following :
Addressed all the above, squashed all the commits, pushed changes to unblock customer @commit d9cebc3 |
|
Concerning @prmathur-microsoft latest comments:
|
Checklist
devdocfolder and added or modified requirements.masterbranch.Reference/Link to the issue solved with this PR (if any)
Description of the problem
Reported by Partner Bosch Rexroth: If there are exceptions on trying to send messages to IoT Hub with class IotHubSendTask, full stack traces will be written to the console. This causes problems on devices with few memory and disk space (when forwarding the console output to log files)
Description of the solution
Introduced new boolean class property 'verboseErrorMessaging' that defaults to false and is used in catch clause to determine if full stack traces should be written to the system console. This means that the default behavior of the class has been changed to NOT write full stack traces on exceptions.
