Specify different message formatting for `uvm_info, `uvm_warning, etc messages displayed on stdout and for those printed in log

Hi,

I am creating a custom_report_server class by extending the uvm_report_server class.

I’d like to highlight the message tags based on their severity. For example, in the below code snippet from my custom “compose_message” function, I am highlighting the “UVM_ERROR” tag in Red.


        // more code
         end else if (severity_type.name()=="UVM_ERROR") begin
            severity_str  = $sformatf("  \033[0;37;41m%s\033[0m", "UVM_ERROR");
         end
        // more code

This works and looks great when reviewing the printed messages live in terminal/stdout.
But the problem is that the ANSI color codes get printed in the simulation log file too and so the log looks very cluttered with the “\033[0;37;41mUVM_ERROR\033[0m” strings.

Is there a way to specify ANSI color coded formatting only for the stdout messages and non-color-coded messages for the stream that is logged to files?

Thanks!

Kaushal Modi

Any updates on this? I too am very interested in functionality to properly color the uvm_error strings to make fast debugging easier …

I couldn’t find an inbuilt way to colorize the stdout but not the log file.

But this solution has been working for me:

Do perl -pi -e ‘s/\e[\d+(?>(;\d+)*)m//g’ $logfile in your simulation script after the sim finishes. So initially as long as the sim is running both stdout and $logfile will have the color codes. But after the sim, those codes will be removed from $logfile using that perl oneliner.

since you are already customizing the report server,
I would suggest trying to overload the f_display function in the uvm_report_server.
this function :

// f_display
//
// This method sends string severity to the command line if file is 0 and to
// the file(s) specified by file if it is not 0.

function void f_display(UVM_FILE file, string str);
if (file == 0)
$display(“%s”, str);
else
$fdisplay(file, “%s”, str);
endfunction

can be overridden by either this :

function void f_display(UVM_FILE file, string str);
if (file == 0)
$display(“%s” ,str);
else
$fdisplay(file, “%s”, strip_ansi(str));
endfunction

and implement an strip_ansi function that looks for and removes the ansi sequences from the string.

In reply to kaushalmodi:

Hi,
I am creating a custom_report_server class by extending the uvm_report_server class.
I’d like to highlight the message tags based on their severity. For example, in the below code snippet from my custom “compose_message” function, I am highlighting the “UVM_ERROR” tag in Red.


// more code
end else if (severity_type.name()=="UVM_ERROR") begin
severity_str  = $sformatf("  \033[0;37;41m%s\033[0m", "UVM_ERROR");
end
// more code

This works and looks great when reviewing the printed messages live in terminal/stdout.
But the problem is that the ANSI color codes get printed in the simulation log file too and so the log looks very cluttered with the “\033[0;37;41mUVM_ERROR\033[0m” strings.
Is there a way to specify ANSI color coded formatting only for the stdout messages and non-color-coded messages for the stream that is logged to files?
Thanks!
Kaushal Modi

hello sir

please you can give more detail on this …

thanks & regards
Ashish Saroj

In reply to ashish_saroj:

You are responding to a 7 year old post. It would be better to ask a completely new question. But first look at this to see if it helps.