Skip to content
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

C++ Logging Hook #3616

Open
ogoffart opened this issue Oct 7, 2023 · 0 comments
Open

C++ Logging Hook #3616

ogoffart opened this issue Oct 7, 2023 · 0 comments
Labels
a:language-c++ C++ API, codegen, CMake build system (mS,mO) api Changes or additions to APIs enhancement New feature or request

Comments

@ogoffart
Copy link
Member

ogoffart commented Oct 7, 2023

We should expose a hook in C++ to intercept the panics and logs.

One step will be to use the log crate in Rust for our own logs: #3099
But regardless, we should allow a hook in C++

Proposed API:

namespace slint {
     struct LogMessage {
             enum class Level {
                 /// A panic occurred. This is a bug in Slint. The process is going to be terminated after this.
                 Panic,
                 /// Some recoverable error happened, such as an image could not be loaded
                 Error,
                 //Warn, // (we don't currently have such message, do we?)
                 /// Some information message (eg, the fps from SLINT_DEBUG_PERFORMANCE)
                 Info,
                 /// Output of `debug()` function from slint
                 Debug,
             };
             Level level;
             string_view message;
             string_view file;
             int line;             

             // prevent the user to construct as aggregate that would prevent us to add fields in the future
             private:void*reserved;
     };

     /// Set a hook that is called when Slint would usually display a log message.
     /// If the hook return true, this would mean the default message should not be called.
     void set_message_hook(bool (*) (LogMessage message) );
}

For the panic, the use of string_view message means that one must render the panic in a String, which allocates. And allocating in a panic handler might not be ideal. Alternative is to call the hook for each part of the message, but that's a terrible API imho while allocating in the panic handler should still be rather safe.

@ogoffart ogoffart added the a:language-c++ C++ API, codegen, CMake build system (mS,mO) label Oct 7, 2023
@ogoffart ogoffart added enhancement New feature or request api Changes or additions to APIs labels Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:language-c++ C++ API, codegen, CMake build system (mS,mO) api Changes or additions to APIs enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant