3 ms·
Printing a table to the console or log file. A very simple example from just this weekend for me is that I wanted to see how C++ was laying out an object in mem
by ziml77 5y ago
Printing a table to the console or log file. A very simple example from just this weekend for me is that I wanted to see how C++ was laying out an object in memory. I assigned the pointers to one and two character variables. When I printed out the variable name followed by the address, I actually had to go back and add an extra space before the single character variable names so the addresses would align. That made it much easier to see the differences between the various pointers into the object.
- Stratoscope 5y agoFunny you mention log files with extra spaces. At my current job, I deal with an API called the RTO, and I wanted to log the requests to that API and the matching responses. Of course the words "request" and "response" are not the same length. But I thought it would look nice to line things up for a request and its matching response, so I just added an extra space after "request:", like this: RTO request: {...} RTO response: {...} When testing locally in a terminal, this looked great. Everything lined up and was pretty. What I didn't realize was that most people view these logs in New Relic, which does use a monospaced font but does not prevent collapsing of adjacent spaces. So the logs look like this: RTO request: {...} RTO response: {...} Obviously not the end of the world! But it did happen that the first part of the {...} stuff should match between the request and the response, so it made it easier to understand (if it worked) to line them up. I am tempted to change the messages to this, which I think will work around this problem: RTO request : {...} RTO response: {...} Sometimes you can't win for losing!
- danuker 5y ago> does use a monospaced font but does not prevent collapsing of adjacent spaces. Whoever implemented this in "New Relic" did not think at all about preserving information, which seems critical in a log file.
- iudqnolq 5y agoIt may be lost at display time. The default behavior of a browser is to collapse adjacent white space so something like <p> Hello <span>World</span> doesn't render with a huge number of spaces.
- ziml77 5y agoYou could also align the text with a leading space. But either that workaround or yours only works because the lengths are 1 apart. I wonder why the creators of New Relic decided to let spaces collapse like that. I can't imagine ever wanting that feature in a monospace font.