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

Option to force colours #611

Closed
vebjornjr opened this issue Oct 22, 2024 · 6 comments · Fixed by #612
Closed

Option to force colours #611

vebjornjr opened this issue Oct 22, 2024 · 6 comments · Fixed by #612

Comments

@vebjornjr
Copy link

Is your feature request related to a problem? Please describe.
Colours are missing in Quill logs when running an application in QtCreator. QtCreator doesn't run the application in a terminal, but the output is shown in Application Output. I don't really know what kind of environment Application Output is, but it seems like Quill doesn't detect that it can show colour there. (Colours should be available in Application Output).

Describe the solution you'd like
An option to force colour usage to override the ConsoleColours::_set_can_use_colours() logic.

Additional context
A similar problem and solution with SpdLog: https://stackoverflow.com/questions/78707422/qtcreator-application-output-not-colored-with-logs-from-spdlog-c

@odygrd
Copy link
Owner

odygrd commented Oct 22, 2024

Hello, I am fine adding an option to force colours, but the solution is not that simple, please read below.

As a workaround for now I was able to get colours working in the existing quill version by selecting Run in terminal in the Qt Creator

image

@odygrd
Copy link
Owner

odygrd commented Oct 22, 2024

As you probably noticed above that was the Terminal QtCreator window and not the Application Output
I tried to force the colours but it is not currently working in the Application Output, the problem is this error

GetConsoleScreenBufferInfo failed. error: unknown error errno: 6

When we get this error we failback to writing a log without colours on Windows OS

https://github.com/odygrd/quill/blob/add-colourmode/include/quill/sinks/ConsoleSink.h#L458

@odygrd
Copy link
Owner

odygrd commented Oct 22, 2024

For windows it won’t work even if you force them

Colours are not working when running the application in QtCreator Application Output or VS debug window. This is because these environments don't provide a standard Windows console handle and Quill is using the console handle to set the colours for Windows

For Linux ANSI codes are used but I haven’t tested QtCreator on Linux

To handle outputting colours in non console environments on Windows we need to use ANSI codes which is currently only enabled for Linux

Are you using Windows or a different OS to run QtCreator ?

@odygrd odygrd linked a pull request Oct 22, 2024 that will close this issue
@odygrd odygrd reopened this Oct 23, 2024
@odygrd
Copy link
Owner

odygrd commented Oct 23, 2024

In version 7.4.0 that will be released in a few days, you can now use the following code, which will work on platforms other than Windows:

  quill::Frontend::create_or_get_sink<quill::ConsoleSink>(
    "sink_id_1", quill::ConsoleColours::ColourMode::Always);

A further fix in version 8.0.0 (expected in a few months/weeks), will fix this on Windows as well.

@vebjornjr
Copy link
Author

Nice work! Really quick too. Thank you.

I run QtCreator on Linux. I built quill from master and tested it in a little test project now. The force colour option works fine in Application Output.
image

@odygrd
Copy link
Owner

odygrd commented Oct 23, 2024

Thank you for confirming it works !

@odygrd odygrd closed this as completed Oct 23, 2024
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 a pull request may close this issue.

2 participants