Create and print all the display messages in the file using $sformatf

I want to display all the statements which should be written in a file, which will be easy for debugging. For example, i have to display the statements which are related to driver in the separate file which should be created using $sformatf and the string name which we use in $sformat should be used a file name. Can u tell how to achieve the task?

In reply to Gayathrishetty:

Are you aware of UVM_LOG? Messaging/UsingMessaging | Verification Academy

Hello dave,
Yeah i know UVM_LOG, but how to use it create a macro that should be the file name which is returned by the $sformatf.

In reply to Gayathrishetty:

I do not understand what file name you are trying to create. There are many ways to do this of which $sformatf would be one of them. All of these are equivalent:

file = $fopen("my_file_name");
file = $fopen({"my_","file_", name"});
file = $fopen($sformatf("my_%s_name","file");