slint icon indicating copy to clipboard operation
slint copied to clipboard

Replace eprintln with use of the log facade

Open tronical opened this issue 2 years ago • 5 comments

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

tronical avatar Jul 17 '23 16:07 tronical

Follow-up question #1:

Should all our Rust examples use env_logger by default perhaps?

tronical avatar Jul 17 '23 16:07 tronical

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) { 
     //...
  }
 } );

tronical avatar Jul 17 '23 16:07 tronical

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 avatar Jul 17 '23 17:07 ogoffart

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 avatar Jul 17 '23 17:07 ogoffart

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

ogoffart avatar Jul 17 '23 17:07 ogoffart