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

Replace eprintln with use of the log facade #3099

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

tronical
Copy link
Member

This allows rust applications to have more control over the output the run-time library generates.

@tronical
Copy link
Member Author

Follow-up question #1:

Should all our Rust examples use env_logger by default perhaps?

@tronical
Copy link
Member Author

For C++ the path forward would be basically a front-end API to allow setting a hook, like what Olivier proposed:

enum LogType {
    SlintDebug, //< The output of `debug()`in slint
    Info, //< (Not sure)
    Warning, // Some non-fatal error happened 
    Error, // Something really bad hapenned
}
using LogHook = void (*) (LogType type, std::string_view message);

slint::set_log_hook([](type, message) {
  switch (type) { 
     //...
  }
 } );

@@ -148,7 +148,7 @@ once_cell = { version = "1.5", default-features = false, features = ["alloc"] }
pin-weak = { version = "1.1", default-features = false }
num-traits = { version = "0.2", default-features = false }

log = { version = "0.4.17", optional = true }
log = { workspace = true, optional = true }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to keep it as optional then?

And where are the println! going if no log backend is selected?
Are they then going to be invisible. Making it even harder for use to figure out problems?

@ogoffart
Copy link
Member

Should all our Rust examples use env_logger by default perhaps?

i'm thinking the slint should enable a logger by default that print to stderr or something like that if the "log" feature is not set.
It is otherwise pretty terrible if out of the box, a simple hello world don't show the warning on what went wrong if something goes wrong.

@ogoffart
Copy link
Member

We could have a mod log in i_slint_core, that re-export the macro from the log crate, or just implement macro that print to stderr depending on a feature flag. (or should it be in i_slint_common since it is also used there?)

@ogoffart
Copy link
Member

We should also remove the debug_log macro in favor of this.

@ogoffart ogoffart mentioned this pull request Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants