godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.17k stars 20.21k forks source link

GD.LogRich logs escape codes to log files #77211

Open waldnercharles opened 1 year ago

waldnercharles commented 1 year ago

Godot version

v4.0.2.stable.mono.official [7a0977ce2]

System information

Windows 10

Issue description

I've been toying around with rich text logging on Windows and noticed that the added escape codes are being logged in the log files as well.

Ideally I believe these shouldn't exist in the log files.

Steps to reproduce

  1. Enable File Logging in Project Settings > General > Debug > File Logging > Enable File Logging
  2. Run a script that calls GD.PrintRich("[color=green]Hello World[/color]");
  3. Open the log file in %appdata%/Godot/app_userdata/your_project/godot.log

Minimal reproduction project

N/A

KoBeWi commented 1 year ago

__print_line_rich() seems to have a code that replaces BBCode with ANSI escapes. https://github.com/godotengine/godot/blob/0032c1c0c203ba225dd41bdc799f2e622bccfde5/core/string/print_string.cpp#L88-L98

Maybe the condition disables it for files? Not sure what's the more expected behavior though.

Calinou commented 1 year ago

print_line_rich() should contain a isatty(fileno(stdout)) check. If false (which indicates a non-interactive scenario such as writing stdout to a file), use print_line().

This is a UNIX API; I'm not sure what the Windows API equivalent of this is. (We use ANSI escape codes on Windows too when using print_line_rich(), as this is supported on Windows 10 and later.)