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

log_to_console now logs to console in Windows #11834

Merged
merged 2 commits into from May 25, 2023

Conversation

maloel
Copy link
Collaborator

@maloel maloel commented May 24, 2023

The viewer has a setting:
image
The default is to log to console, minimum level Warning.

This did nothing in Windows. It does not affect the Debug Console Window in the Viewer.

This changes:

  • When turned on, it will attempt to connect to a parent console
    • if run from a console, the console will show logs
    • if run from GUI (or GUI debugger), a console window will not open
  • Added rsutils function to ensure_console() which we now use when calling log_to_console
  • Fixed the code so it will turn OFF console output if the user unchecks this box (it left it on before!)

NOTE that I had to make this work in both Shared and Static builds. In the former, anything outside of librealsense will not affect the librealsense logs - so I had to place the console-opening inside librealsense (originally it was only in the Viewer).

@maloel maloel requested a review from Nir-Az May 24, 2023 06:34
@@ -63,7 +63,14 @@ namespace rs2
config_file::instance().set_default(configurations::window::saved_size, false);

config_file::instance().set_default(configurations::viewer::is_measuring, false);
config_file::instance().set_default(configurations::viewer::log_to_console, true);
config_file::instance().set_default(configurations::viewer::log_to_console,
#ifdef WIN32
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like bad alignment.
I suggest

auto default_log_to_console = true;
// In Windows, there is no console by default
#ifdef WIN32
  default_log_to_console = false;
#endif
config_file::instance().set_default(configurations::viewer::log_to_console, default_log_to_console );

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll change

src/log.h Outdated
@@ -180,6 +181,8 @@ namespace librealsense

void log_to_console(rs2_log_severity min_severity)
{
if( min_severity != RS2_LOG_SEVERITY_NONE )
rsutils::os::ensure_console();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you test how python on Windows behave with this code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Everything behaves the same -- python is usually started from a console.
Only thing new is that, if there is no console, a new window will pop up (on Windows).

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One thing we could do is create a console if the build is a debug build, with the idea being that, when debugging, you do want to see the debug in a separate window...

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the current implementation is better.
Let's not surprise the users.

@maloel maloel merged commit 773d3d4 into IntelRealSense:development May 25, 2023
16 checks passed
@maloel maloel deleted the development branch May 25, 2023 07:48
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