Jump to content

How can I print out Logs left-aligned?


Recommended Posts

Hi Guys,

I want to print out some info in the log file as bellow:

TEST0001: seed = 12                Out_Str: Hello_test                  Out_Num: 64

TEST0002: seed = 12345678    Out_Str: Hello_Public_test     Out_Num: 1024

 

I have do this as follows:

$fdisplay("TEST%04d: seed = %d    Out_str: %s    Out_Num: %d", index, seed, out_str, out_num);

 

But I can not got the format which I wanted.

 

Can you tell me how can I do this?

 

Thanks a lot!

Link to comment
Share on other sites

try this.  the '-' means left aligned.  choose a size larger than your max, for each field, as in my example.

class Packet;
  int  seed[]='{54445,745,11209};
  string out_str[]='{"imabigstring","tiny","medium"};
  int out_num[]='{88,353,1};

  function display ();
    foreach (out_num)
      $display("TEST%04d: seed=%-8d Out_str: %-16s Out_Num: %-8d", i, seed, out_str, out_num);
  endfunction
endclass 

https://www.edaplayground.com/x/2_vR

 

 

Link to comment
Share on other sites

  • 2 years later...

Note that negative field width specifiers, as proposed by @c4brian, are non-standard.

"The automatic sizing of displayed data can be overridden by inserting a field width between the % character
and the letter that indicates the radix. The field width shall be a *non-negative* decimal integer constant."

(SV2017, p. 629)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...