# Redirect output messages to different files in UVM

**URL:** <https://verificationacademy.com/forums/t/redirect-output-messages-to-different-files-in-uvm/37523>\
**Category:** UVM\
**Tags:** filewrite, systemverilog-uvm, UVM, uvm\_report\_server, FWRITE\
**Created:** [April 30, 2020, 8:57pm UTC](https://verificationacademy.com/forums/t/redirect-output-messages-to-different-files-in-uvm/37523 "2020-04-30T20:57:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgarcia07](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/a87d85/32.png) [@rgarcia07](https://verificationacademy.com/forums/u/rgarcia07)\
**Post date:** [April 30, 2020, 8:57pm UTC](https://verificationacademy.com/forums/t/redirect-output-messages-to-different-files-in-uvm/37523/1 "2020-04-30T20:57:58Z")

</div>

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** _

```verilog

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

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [May 1, 2020, 6:34am UTC](https://verificationacademy.com/forums/t/redirect-output-messages-to-different-files-in-uvm/37523/2 "2020-05-01T06:34:20Z")

</div>

_In reply to [rgarcia07](https://verificationacademy.com/forums/t/redirect-output-messages-to-different-files-in-uvm/37523):_

Use [set\_report\_severity\_id\_file](https://verificationacademy.com/verification-methodology-reference/uvm/docs_1.2/html/files/base/uvm_report_object-svh.html#uvm_report_object.set_report_severity_id_file) and [set\_report\_severity\_id\_action](https://verificationacademy.com/verification-methodology-reference/uvm/docs_1.2/html/files/base/uvm_report_object-svh.html#uvm_report_object.set_report_severity_id_action).

---

<div class="post-metadata">

**Author:** ![shanthi](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@shanthi](https://verificationacademy.com/forums/u/shanthi)\
**Post date:** [May 2, 2020, 9:49am UTC](https://verificationacademy.com/forums/t/redirect-output-messages-to-different-files-in-uvm/37523/3 "2020-05-02T09:49:59Z")

</div>

_In reply to [rgarcia07](https://verificationacademy.com/forums/t/redirect-output-messages-to-different-files-in-uvm/37523/2):_  
You can do the following changes in the env file to log the messages to different fle.

```verilog

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
