Skip to content

cxx-qt-lib: Add two more QtLogging functions #1227

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

redstrate
Copy link
Contributor

This adds two new global functions available in : qFormatLogMessage and qSetMessagePattern.

qFormatLogMessage is similar to qt_message_output, but actually documented. Instead of going to the default message handler though, it outputs to a QString. This is probably not useful without message handler support, but it's easy to expose.

qSetMessagePattern is very useful, as it allows CXX-Qt applications to set custom Qt message patterns for logging.

@redstrate redstrate self-assigned this Mar 14, 2025
@redstrate redstrate force-pushed the work/josh/qtlogging-format branch from 9772397 to 7c5ef0b Compare March 14, 2025 14:04
Copy link

codecov bot commented Mar 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (20dd5ad) to head (6c13f1e).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1227   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           73        73           
  Lines        12681     12681           
=========================================
  Hits         12681     12681           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@LeonMatthesKDAB LeonMatthesKDAB left a comment

Choose a reason for hiding this comment

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

Some smaller issues, but more importantly we need to investigate whether set_message_pattern is safe to call!


/// Generates a formatted string out of the type, context, str arguments.
#[cxx_name = "qSetMessagePattern"]
fn set_message_pattern(pattern: &QString);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The Qt documentation states that qFormatLogMessage is thread-safe.

However, it does not state that set_message_pattern is thread-safe!
Can you investigate whether this function is thread-safe?
Otherwise we may need to make it unsafe or enforce safety somehow...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that we're having similar issues with #1205

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's fine to mark it as unsafe, I should probably add a comment explaining why it is right?

@LeonMatthesKDAB
Copy link
Collaborator

Ping @redstrate, can you solve the remaining issues?

@redstrate redstrate force-pushed the work/josh/qtlogging-format branch 2 times, most recently from b24934b to 337c4e8 Compare May 7, 2025 12:20
@redstrate
Copy link
Contributor Author

Ping @redstrate, can you solve the remaining issues?

Done, sorry it's been a busy week - but I have time now :)

@redstrate redstrate force-pushed the work/josh/qtlogging-format branch from 337c4e8 to 0b04610 Compare May 7, 2025 12:23
@redstrate redstrate requested a review from LeonMatthesKDAB May 7, 2025 12:23
This adds two new global functions available in <QtLogging>:
qFormatLogMessage and qSetMessagePattern.

qFormatLogMessage is similar to qt_message_output, but actually
documented. Instead of going to the default message handler though, it
outputs to a QString. This is probably not useful without message
handler support, but it's easy to expose.

qSetMessagePattern is very useful, as it allows CXX-Qt applications to
set custom Qt message patterns for logging.
@redstrate redstrate force-pushed the work/josh/qtlogging-format branch from 0b04610 to 6c13f1e Compare May 7, 2025 12:41
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.

2 participants