Terminal: Gorm database logs not rendering colors properly unless ansicon is installed

Created on 22 Jun 2018  路  5Comments  路  Source: microsoft/terminal

My system:
mysys

My Windows build number:

  • Microsoft Windows [Version 10.0.17134.112]

I'm running golang server and printing database logs to console using gorm.
specifically using this method: https://godoc.org/github.com/jinzhu/gorm#DB.LogMode

Here's the command and output (without ansicon installed):
woansi

Here's the command and output (WITH ansicon installed):
withansi

Most helpful comment

Aye, but unfortunately our ultimate loyalty is to supporting backwards compat, and for whatever reason we can't just enable it by default :(.

However, you can be sure that means we're not pulling the reg key either :)

All 5 comments

The ANSI/VT escape sequences are not enabled by default in the Windows console. You need to set a registry key (HKEY_CURRENT_USER\Console\VirtualTerminalLevel) to turn on that functionality. I'm not sure if it is officially documented anyway, but it was explained in the comments of one of the WSL issues. See here.

Yes! Worked Perfectly. Look at those beautiful colorful logs 馃槏 Thank You!
beautylogs

For the record, the reg key is a bit of a hack, (and honestly I forgot it was there). Applications on windows that want to enable the VT support should be using SetConsoleMode with the ENABLE_VIRTUAL_TERMINAL_PROCESSING flag, so that all users of the application will get the same behavior.

@zadjii-msft If you're writing a cross-platform app, though, it's a bit disappointing being told that you have to add platform-specific API calls to your code just to get functionality that works out of the box in other operating systems (including older versions of Windows back in the ansi.sys days). Personally I would just have stuck with ansicon if that registry option wasn't available, so I hope you aren't planning on removing it.

Aye, but unfortunately our ultimate loyalty is to supporting backwards compat, and for whatever reason we can't just enable it by default :(.

However, you can be sure that means we're not pulling the reg key either :)

Was this page helpful?
0 / 5 - 0 ratings