Redirect output messages to different files in UVM

Hello,

I have a class extending from uvm_reg_cbs (not a component) which creates some messages that need to be redirected and formatted to different file, I know that I could use $fopen, $fwrite** to achieve this but I was wondering if there is a “UVM way” of doing this, below the code I have usign $fopen, $fwrite


virtual class fd_wrapper;
  static integer fd;
  static function open_fd();
    fd = $fopen("./data", "w");
  endfunction

  static function close_fd();
    fd = $fclose(fd);
  endfunction
  static function void write_fd(string msg)
    $fwrite(fd, msg);
  endfunction
endclass
  

class my_env extends uvm_env;
//regular uvm code
my_cb cb;

virtual function end_of_elaboration_phase(uvm_phase phase);

  cb = my_cb::type_id::create("cb");
  //add cb to all registers
  //open the file
  fd_wrapper::open_fd();
   
endfunction

virtual function final_phase(uvm_phase phase);
 fd_wrapper::close_fd();
endfunction

endclass

class my_cb extends uvm_reg_cbs;
//regular uvm stuff

virtual task pre_write(uvm_reg_item rw);
  format(rw);
endtask

virtual function void format(uvm_reg_item rw);
  string msg;
  //create msg based on some logic using rw
  fd_wrapper::write_fd(msg);
  //`uvm_info(...) //redirect and format uvm_info instead of calling write_fd
endfunction 

endclass


Apologies if my code and question is a bit messy.

Thanks,

-R

In reply to rgarcia07:

Use set_report_severity_id_file and set_report_severity_id_action.

In reply to rgarcia07:
You can do the following changes in the env file to log the messages to different fle.



class my_env extends uvm_env;
//regular uvm code
my_cb cb;
int f1;//file descriptor
 
virtual function end_of_elaboration_phase(uvm_phase phase);
 
  cb = my_cb::type_id::create("cb");
  //add cb to all registers
  //open the file
 f1= $fopen("cb_file","w")
 cb.set_report_id_file("CB",f1);// The first argument is the ID which is used in reporting macros in my_cb class.
 cb.set_report_id_action("CB",UVM_LOG)
endfunction

 
endclass

With this, all the messages in my_cb class with id “CB” will be logged in to the file cb_file