Log file for uvm object type class

In reply to chr_sue:
Thanks to dave, I did managed to figure it out.
To be honest, it’s not theoretical example … I have prepared a behavorial model and thus not intended to use any phasing aspect(which we get in uvm_component) and hence started extending my class from uvm_object. Intention was model to have separate log file.

As per dave suggestion, I tried to understand a bit and came up with following, though still has scope of improvement but works for time-being.


class my_obj extends uvm_report_object;
  `uvm_object_utils(my_obj);
 
  function new(string name = "");
    super.new(name);
    tID = get_type_name();
    tID = tID.toupper();
  endfunction
 
  function void configure(uvm_component parent = null);
    string hier_s;
    uvm_verbosity verb;
    
    if(parent != null) begin
      hier_s = parent.get_full_name();
    end else begin
       uvm_coreservice_t cs = uvm_coreservice_t::get();
       parent = cs.get_root();
    end

    hier_s = (hier_s == "") ? hier_s : { hier_s, "." };

    hier_s = { hier_s, get_full_name(), ".log" }
    log = $fopen(hier_s, "w");
 
    if(!log) begin
      `uvm_fatal(tID, {hier_s, "can't open to write"});
    end
      
    verb = uvm_verbosity'(parent.get_report_verbosity_level());
    this.set_report_verbosity_level(verb);
    this.set_report_id_action(tID, UVM_LOG);
    this.set_report_id_file(tID, log);
    
 
  endfunction
 
  function void display();
    `uvm_info(tID, "this print goes to log file", UVM_HIGH);
  endfunction
 
  function void end_of_sim();
    if(log) $fclose(log);
  endfunction
 
  local int log = -1;
  protected string tID;
 
endclass
 

module try;
 
  my_obj obj;
 
  initial begin
    obj = my_obj::type_id::create("obj");
    obj.configure();
    obj.display();
    obj.end_of_sim(); 
  end
 
endmodule