-
Notifications
You must be signed in to change notification settings - Fork 92
Use Qt's public logging APIs rather than undocumented internals #1300
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1300 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 75 75
Lines 12772 12772
=========================================
Hits 12772 12772 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hi @jnbooth, The internal API is suited to a different use-case and allows more fine-grained access. So please add the already exposed API back. |
@LeonMatthesKDAB Do you mean something like qInstallMessageHandler? Whatever your use case is, I think there will be a way to do it using Qt's public API rather than undocumented internals. |
I actually mean the other way around :) What you're referring to is installing a custom log handler in Qts logging system. What I was referring to is installing Qts logging system as a custom log handler in Rusts log ecosystem (e.g. the log crate ) |
@LeonMatthesKDAB Looking at their docs, I think you would do it like this: use std::ffi::CString;
use cxx_qt_lib::{QString, q_critical, q_debug, q_fatal, q_info, q_warning};
use log::{Level, Log, Record};
struct QtLogger;
impl Log for SimpleLogger {
fn log(&self, record: &Record) {
let file = CString::new(record.file().unwrap_or_default());
let line = record.line().unwrap_or_default() as i32;
let message = QString::from(record.args());
match record.level() {
Level::Error => q_critical(file.as_ptr(), line, &message),
Level::Warn => q_warn(file.as_ptr(), line, &message),
Level::Info => q_info(file.as_ptr(), line, &message),
Level::Debug | Level::Trace => q_debug(file.as_ptr(), line, &message),
}
}
} No need for undocumented internals. |
Instead of exposing undocumented internal features of Qt, qtlogging.rs now exports
q_critical
,q_debug
,q_fatal
,q_info
, andq_warning
, equivalent to Qt's qCritical, qDebug, qFatal, qInfo, and qWarning. So instead of doing this:You can simply do this:
The file and line number are automatically filled in by the
file
andline
built-in macros.