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

console.log() qml not working #188

Closed
Ayush1325 opened this issue Jul 22, 2021 · 12 comments
Closed

console.log() qml not working #188

Ayush1325 opened this issue Jul 22, 2021 · 12 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues.

Comments

@Ayush1325
Copy link
Collaborator

Ayush1325 commented Jul 22, 2021

I am using env_logger as backend. I can see log messages from the Rust side. However, I cannot see the messages logged from QML.
I thought this was added in #86 but I also found #163 so I'm not sure if it still works.
So is it broken in QT6 or are there some additional steps required which are not mentioned in the README?

System Information:
QT: 6.1.2
Display Server: X11
Distro: Fedroa 34
Kernel: 5.12.17-300.fc34

@ratijas
Copy link
Collaborator

ratijas commented Jul 22, 2021

It's not "broken", it's a feature that Qt sends logs to system journal instead of stdout/stderr by default. Read more at links posted in #162 (which was moved to #163). You gotta use set QT_FORCE_STDERR_LOGGING=1 or just launch from a terminal.

@ratijas
Copy link
Collaborator

ratijas commented Jul 22, 2021

I mean, wait, hold on a second. QT_FORCE_STDERR_LOGGING is just for logging on Qt side.

You wrote that you are using env_logger in Rust. But did you set up Qt to Rust log forwarding afterwards as described in README?

fn main() {
    qmetaobject::log::init_qt_to_rust();
    // don't forget to set up env_logger or any other logging backend.
}

@Ayush1325
Copy link
Collaborator Author

I mean, wait, hold on a second. QT_FORCE_STDERR_LOGGING is just for logging on Qt side.

You wrote that you are using env_logger in Rust. But did you set up Qt to Rust log forwarding afterwards as described in README?

fn main() {
    qmetaobject::log::init_qt_to_rust();
    // don't forget to set up env_logger or any other logging backend.
}

Yes, I did that, tried interchanging the order of initialization too but no luck.

It's not "broken", it's a feature that Qt sends logs to system journal instead of stdout/stderr by default. Read more at links posted in #162 (which was moved to #163). You gotta use set QT_FORCE_STDERR_LOGGING=1 or just launch from a terminal.

Tried that too, still can't get any output on the console.

For more context, my qml is as follows:

import QtQuick 2.6
import QtQuick.Window 2.0
import QtQuick.Controls 2.12

Window {
    id: window
    visible: true
    title: qsTr("WeebTK")

    Button {
        text: qsTr("Ok")
        onClicked: console.log("clicked")
    }
}

@Ayush1325 Ayush1325 reopened this Jul 22, 2021
@Ayush1325
Copy link
Collaborator Author

Sorry for that, mistakenly closed the issue.

@ratijas
Copy link
Collaborator

ratijas commented Jul 22, 2021

I don't know then. Maybe logging levels, or env logger ignores "qml" messages. There is also a global Qt logging configuration somewhere in ~/.config, but I'm not sure.

@ratijas
Copy link
Collaborator

ratijas commented Jul 22, 2021

Yes, I did that, tried interchanging the order of initialization too but no luck.

Order of initialization shouldn't matter (unless you are logging something in the middle), since it only registers a function in Qt, and doesn't do anything with Rust logging framework per se.

@Ayush1325
Copy link
Collaborator Author

I don't know then. Maybe logging levels, or env logger ignores "qml" messages. There is also a global Qt logging configuration somewhere in ~/.config, but I'm not sure.

Well, I did set RUST_LOG variable to show all logs, and confirmed that it is working by logging from the rust side. So only the QML logs don't seem to work. They do work in projects created with QT Creator, so it shouldn't be a problem with Qt install, I think.

@ratijas ratijas added the C-discussion Category: Discussion or questions that doesn't represent real issues. label Jul 22, 2021
@ratijas
Copy link
Collaborator

ratijas commented Jul 22, 2021

It's not a problem with Qt install, sure. It's all about its runtime, and how it detects whether it needs to pass logs to registered handler or not. You might even want to check their source code (especially qtbase/src/corelib/global/qlogging.cpp) and trace calls, and play around with environment variables and configuration and stuff.

Check environment section in Qt Creator, it might help understand why it works from IDE.

@Ayush1325
Copy link
Collaborator Author

It's not a problem with Qt install, sure. It's all about its runtime, and how it detects whether it needs to pass logs to registered handler or not. You might even want to check their source code (especially qtbase/src/corelib/global/qlogging.cpp) and trace calls, and play around with environment variables and configuration and stuff.

Check environment section in Qt Creator, it might help understand why it works from IDE.

Ok, Ill try and see what I can find.

@sztomi
Copy link
Contributor

sztomi commented Aug 10, 2021

FWIW, I had to set two levels in my logger (fern) to see all log messages from Qt, after setting the default level to error:

    .level(log::LevelFilter::Error)
    // "default" is the category that the qmetaobject log integration sets by default
    .level_for("default", log::LevelFilter::Debug)
    // "qml" is the category for console.log & friends from qml
    .level_for("qml", log::LevelFilter::Debug)

@sztomi
Copy link
Contributor

sztomi commented Aug 10, 2021

One more thing! I had to set the following:

export QT_LOGGING_RULES="*.debug=true; qt.*.debug=false"

This can also be set in ~/.config/QtProject/qtlogging.ini as

[Rules]
*.debug=true
qt.*.debug=false

The second rule filters out the logging from Qt itself (this would be very noisy otherwise).

Qt documentation for this: https://doc.qt.io/qt-5/qloggingcategory.html#logging-rules

@Ayush1325
Copy link
Collaborator Author

I was able to fix the issue by setting RUST_LOG properly. It either needs to be set as

RUST_LOG=qml # Other options can be added

or

RUST_LOG=debug # Other options can be added

to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues.
Projects
None yet
Development

No branches or pull requests

3 participants