After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 517231 - threadsafe/colored windows logging
threadsafe/colored windows logging
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
git master
Other Windows
: Normal normal
: 0.10.23
Assigned To: Wim Taymans
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2008-02-18 14:54 UTC by Damien Lespiau
Modified: 2009-04-14 08:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch against cvs HEAD (7.77 KB, patch)
2008-02-18 14:54 UTC, Damien Lespiau
committed Details | Review
mandatory screenshot (67.05 KB, image/png)
2008-02-18 14:55 UTC, Damien Lespiau
  Details
What gst-launch prints by default in a cmd.exe console (26.16 KB, image/png)
2008-02-19 10:58 UTC, Damien Lespiau
  Details
Makes the new logging threadsafe (2.19 KB, patch)
2009-03-22 15:58 UTC, LRN
committed Details | Review

Description Damien Lespiau 2008-02-18 14:54:00 UTC
This patch adds support for debug messages colors on windows' cmd.exe. Screenshot included ! :p
Comment 1 Damien Lespiau 2008-02-18 14:54:54 UTC
Created attachment 105504 [details] [review]
patch against cvs HEAD
Comment 2 Damien Lespiau 2008-02-18 14:55:50 UTC
Created attachment 105505 [details]
mandatory screenshot
Comment 3 David Schleef 2008-02-19 01:35:00 UTC
I thought cmd.exe is a VT100 emulator just like the linux console, xterm, and the old MS-DOS prompt (and very nearly everything else since the 80's).  In that case, we should be able to send VT100 escape codes just like the existing code.
Comment 4 Damien Lespiau 2008-02-19 10:56:47 UTC
AFAIK, cmd.exe does not support VT100 escape sequences.

In the Old Good Days of command.com and the early days of cmd.exe (windows 95 and 98 I guess) you could use then. Since windows 2000, cmd.exe does not support ANSI escape sequences, no matter if you put a DRIVER=ansi.sys in you config.sys or not.

I've googled around and I can find some thingys about cmd.exe and colors:

* the color command that allows you to set a fg or bg color
* a property dialog that acts as a frontend to color
* the /A flag of cmd.exe that is said "to print ANSI characters", it's set by default, still no escape sequence

Anyway, if someone is able to make ANSI escape sequences work with cmd.exe, it's at least not enabled by default on my windows box. (see next screenshot)
Comment 5 Damien Lespiau 2008-02-19 10:58:05 UTC
Created attachment 105569 [details]
What gst-launch prints by default in a cmd.exe console
Comment 6 Wim Taymans 2009-03-18 18:56:06 UTC
I refactored it a bit to reduce code duplication.

commit c5ee0b7c1d4cd8925b5a5307c9491d62ae2cb01b
Author: Damien Lespiau <damien.lespiau at gmail.com>
Date:   Wed Mar 18 19:07:00 2009 +0100

    info: more indentation fixes
    
    Fixes #517231.

commit d12d111fa257141ac6ae056ede0ebb6617f29f1f
Author: Wim Taymans <wim.taymans@collabora.co.uk>
Date:   Wed Mar 18 19:06:23 2009 +0100

    info: indentation fix

commit 3857d902c32c9e366162464caba5e02ff7981588
Author: Wim Taymans <wim.taymans@collabora.co.uk>
Date:   Wed Mar 18 18:57:16 2009 +0100

    info: simply some more

commit ca33a78881d5343b06c3f2e937377e352f266dc6
Author: Wim Taymans <wim.taymans@collabora.co.uk>
Date:   Wed Mar 18 18:45:41 2009 +0100

    info: refactor debug colors for win32 and other
    
    Refactor the debug line code to use as much code as possible for the win32 and
    other color codings.
    Update docs with new symbol.

commit 0c059ad2dedd099bcb70c39f90d9b4fb94485dab
Author: Wim Taymans <wim.taymans@collabora.co.uk>
Date:   Wed Mar 18 17:30:12 2009 +0100

    windows: initial commit for terminal colors

Comment 7 LRN 2009-03-22 15:58:45 UTC
Created attachment 131126 [details] [review]
Makes the new logging threadsafe
Comment 8 LRN 2009-03-22 16:07:58 UTC
Comment on attachment 131126 [details] [review]
Makes the new logging threadsafe

Well, another way of doing that is to make multiple calls to g_strdup_printf(), concat the strings and then print them in one call to g_printerr().
Comment 9 Edward Hervey 2009-03-23 07:54:15 UTC
The second solution you mention (creating the string and THEN outputting it) is much cleaner imho and avoids using a lock. IIRC, that's how the regular outputter does it.... but I'm not 100% sure if that would work with the SetConsoleTextAttribute() method.

Re-opening and adjusting the title accordingly.
Comment 10 LRN 2009-03-23 20:03:44 UTC
It could be possible to use FillConsoleOutputAttribute() to color a string that is already written to console, but that will also require us to lock it (else we may put the colors in wrong place).
Comment 11 LRN 2009-04-07 18:20:27 UTC
Another option is to use WriteConsoleOutput() function, which takes combined character and attribute (color) data. But there is one problem with it - it won't change the cursor position. So we'll have to change it manually. Which means calling GetConsoleCursorInfo() to get current cursor position and SetConsoleCursorPosition() to change it.

It's still not thread-safe. On the other hand, if we DO use locking, this solution offers shortest locktime, because character/color buffer is prepared outside of lock, function locks only to write data into the console and move the cursor, which should be faster than writing a string and changing color attribute a few times (current solution) or writing one string and then setting console attributes a few times (the FillConsoleOutputAttribute solution).

FillConsoleOutputAttribute has an advantage of writing meaningful text data in both implementations (with or without locking), because the presence of a lock only affects the way it colorizes text (it may colorize wrong characters in concurrent mode, but at least text will be intact).
Comment 12 Wim Taymans 2009-04-14 08:34:32 UTC
I commited the mutex patch because it does the right thing for now and nobody said that debugging in full colors to the console should be efficient. If you have a better and cheaper patch, please reopen and attach.


commit 7e0bdbf2086b5fffa439dbd876a5e57281dc7c1a
Author: LRN <lrn1986 at gmail.com>
Date:   Tue Apr 14 10:32:07 2009 +0200

    info: use mutex to do console colors on windows
    
    Use a static mutex to keep the console colors and context together when
    debugging with colors on Windows.
    Fixes #517231.