Change Color of Log Text

I’m trying to easily see my own log messages in the output log when I run my game. While the category helps it would be much better if I could visually instantly see my logs via a color. Now I know you can use Warning or Error as the Verbosity but while hunting through the code I spotted that the Verbosity has a value of SetColor… I just have no idea how to use it, I spent a good few hours diving through code but got lost :slight_smile:

Basically I’d like to set it to a color so that my logs stand out against any real warnings, errors, or system logs that are automatically generated.

Which log are you talking about, onscreen messages, or UED log interface.

For on screen messages, the third parameter lets you set a color

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("%s %s: %s"), NETMODE_WORLD, CLASS_FUNC_NAME,  *Msg));

for log interface

SET_WARN_COLOR( COLOR_CYAN );
FString Msg = FString::Printf(TEXT(Format), ##__VA_ARGS__ ); 
UE_LOG( LogFF, Log, TEXT("%s%s() : %s"), NETMODE_WORLD, CLASS_FUNC_NAME, *Msg);

Hi GeekyPayback, Thank you for responding. I am specifically intrested in the Unreal Editor log. So SET_WARN_COLOR can change the color, but does it do that for all warnings or just the ones where the warn color is set?

Again thanks for the reply!

Okay I kind of see what this is doing but there are a few unknowns for me in your example. What is Format? Mainly. I am using a C++ function to write to the log defined as follows:

void WriteMyLog(FString Msg, AActor * actor)
{
	if (actor)
	{
		if (actor->GetNetMode() == ENetMode::NM_Client)
		{
			UE_LOG(MyClientLog, Warning, TEXT("%s"), *Msg);
		}
		else if (actor->GetNetMode() == ENetMode::NM_ListenServer)
		{
			UE_LOG(MyServerLog, Error, TEXT("%s"), *Msg);
		}
	}
	else
	{
		UE_LOG(MyLog, Log, TEXT("%s"), *Msg);
	}
}

This is a global function that I plan on adding Debug preprocessors around but basically it is accessable across my entire project because it is declared within my main game’s .h file.

Hello, ArcainOne

Format in this case means that you are available to adjust your string with specifiers and flags as with C printf() function.
If you like to learn more about it, please go here:

http://www.cplusplus.com/reference/cstdio/printf/

Hope this helped!

Okay, but I’m still not sure how that solves my original question, which is how do you change the color of the Log text in the log window. I have tried using SET_WARN_COLOR(COLOR_CYAN) but that does not appear to do anything…

Don’t get me wrong I’m willing to accept a “There is no way to do it” but it seems a shame if there isn’t a way, it would make debugging a bit easier…

It looks like you are trying to write your own log file, there are already wiki pages that explain how to do it (its where my example came from).

How to write a custom log file with netmode and colour

Paste your code up, because my logs do come out in cyan, so that SET_WARN_COLOR works for me.

That looks exactly what I am trying to do. I actually got the whole net mode working but that looks to be a much better method. I’ll try it out and it if works will be setting this to resolved!

SET_WARN_COLOR doeas not work in 4.17, isn’t it?

Still works for me in 4.18. put your entire file and the error message it gives and I’ll try and help

the answer: SET_WARN_COLOR does not work for me - Programming & Scripting - Epic Developer Community Forums

how to expose SET_WARN_COLOR( COLOR_CYAN );
to blueprint?

Here’s what I found…

There does not seem to be a mechanism by which to change the color of logged text in the UE Output Window and the docs don’t seem to be accurate.

The docs and online comments would have us believe that this valid…
See: Engine\Source\Runtime\Core\Public\Logging\LogMacros.h
UE_LOG(LogMyCategory, SetColor, TEXT(“%s”), OutputDeviceColor::COLOR_BLUE);
UE_LOG(LogMyCategory, Log, TEXT(“%s”), *message)
UE_LOG(LogMyCategory, SetColor, TEXT(“%s”), OutputDeviceColor::COLOR_NONE);

This macro creates calls to FOutputDevice::Log() and FOutputDevice::LogF() in…
See: Engine\Source\Runtime\Core\Public\Misc\OutputDevice.h

And those calls ultimately land in two places…

  1. Output to the Windows Console. This code seems to honor SetColor…
    See: Engine\Source\Runtime\ApplicationCore\Private\Windows\WindowsConsoleOutputDevice2.cpp
    See: Engine\Source\Runtime\ApplicationCore\Private\Windows\WindowsConsoleOutputDevice.cpp

  2. Output to the UE Output Window. This code skips SetColor (‘color events’) and auto-selects color for us based on the following logic…
    See: Engine\Source\Developer\OutputLog\Private\SOutputLog.cpp
    Green - If Category == ‘CmdLog’ (a command is being executed).
    Red - Verbosity == ELogVerbosity::Error or the message contains “Error:”.
    Yellow - Verbosity == ELogVerbosity::Warnihng or the message contains “Warning:”.
    Default (light gray) - Everything else

Logging will also prepend insert text into our message. Examples…
See: Engine\Source\Runtime\Core\Public\Logging\LogVerbosity.h
UE_LOG(LogMyCategory, Detail, TEXT(“My Message …”)) → “LogMyCategory: Detail: My Message …” (Color: Default)
UE_LOG(LogMyCategory, Warning, TEXT(“My Message …”)) → “LogMyCategory: Warning: My Message …” (Color: Yellow)
UE_LOG(LogMyCategory, Error, TEXT(“My Message …”)) → “LogMyCategory: Error: My Message …” (Color: Red)
UE_LOG(LogMyCategory, Fatal, TEXT(“My Message …”)) → “LogMyCategory: Fatal: My Message …” (Color: Red, HALTS EXECUTION, even if logging is disabled.)
UE_LOG(LogMyCategory, Log, TEXT(“My Message …”)) → “LogMyCategory: My Message …” (Color: Default)

2 Likes