-
Notifications
You must be signed in to change notification settings - Fork 609
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
Logging features for 1.1.x #169
Comments
Feedback from @skalldri
|
Feedback from @xthexder.
|
Feedback from @yijiew
|
@skalldri thanks for the feedback, I will plan to allow runtime changing of logging level. @xthexder I like the idea of calling this @yijiew You should consider implementing the same |
I love this. As an FYI for getting started, spdlog has an idea of sinks. We may want to do this by creating a custom sink which is just a callback. Someone tried to create a callback sink in spdlog a couple years ago but the PR was denied because it was too specific for the spdlog library. Even though it was rejected, it might be interesting to see how they did it as a starting point. PR can be found here: https://github.com/gabime/spdlog/pull/205/files |
Proposal
For logging in Azure Kinect we are planning to add an interface that will allow log messages from the SDK to be forward to the users executable. This will allow customers to merge K4a.dll logs into their own logging solution for better debuggability of system issues. It will also allow tools like K4A viewer can show error logs in real time in a dedicated window if it so chooses.
The proposal is to add k4a_register_debug_message_handler(). The function will take in a function pointer to deliver the messages to, a context for the callback function, and minimum log level setting the SDK should be sending to the user.
The registration API will only allow 1 callback function to be registered. If the user wants to change the logging level or the callback function, then the existing callback function needs to be unregistered first, and then a new callback function can be added. (I suppose we could allow the registration API to be called with the same callback function and treat that as an update to the logging level for a runtime change that doesn’t require unregistration. Anyone think that would be useful?)
The callback function will be invokable by any caller attempting to log. So if there are 3 threads running on 3 CPU, and all of then generate an error message at the same time, then all three of them can call into the users logging callback function at the same time. The user will need to protect against this.
The existing logging features (through the ENV variables) will continue to work as implemented when there is NO callback registered. When a callback is registered, then our current logging will be disabled.
The supported logging levels:
Callback function signature:
Register & unregister API’s
Considerations
Using a callback function is a different programming paradigm when we currently use with K4A. In the case of debug messages, if we want to stay API philosophy of implementing a get_debug_message() API (similar to get_capture in that the user must own the thread), then we would be forced to implement a lot more code, that would likely be a duplication of functionality that the users logger would need to implement. Having an API like get_debug_message() would mean our SDK would have to queue up and store the debug messages in the event the users logger could not keep up. We would also then have to deal with dropped debug messages when the queue got full, and have to get the locking mechanics correct for having a single reader and multiple writers. Additionally we would also then want to consider how long a message has been in our queue and consider how the message will get the correct time stamp applied to it.
All these factors need to be taken into account by any logger that is accepting messages from multiple writers. So the logic that the SDK would need would be duplicated by the customers logger. So for this reason we are not considering the get_debug_message() style of API and instead going with a callback that can forwarded by any one of the SDK threads when an issue needs to be logged.
The text was updated successfully, but these errors were encountered: