44

At the moment, we have these choices when providing error messages / logs:

  1. Use code-blocks

    This preserves the formatting of the error message, though it uses spurious highlighting and disables line-wrapping (both the latter are seldom appropriate)

  2. Use code-blocks with <!-- language: none -->

    Same as #1, but at least no inappropriate highlighting.

  3. Use <pre>...</pre>

    Same as #2, but html works and thus must be escaped.

  4. Use quote-marks

    Markdown and HTML work and must be escaped, no fixed-width font and whitespace-collapsing, but at least line-wrapping works

  5. Insert as normal text

    None of the advantages of either previous option and all the drawbacks, though still popular with new users who do not know better or cannot be bothered.

None of those is really good for logs/errors which easily get just too wide.

What I propose is introducing an alternative, which is especially appropriate for logs and error-messages:

Add something like <!-- language: log --> which makes code-blocks use no highlighting and word-wrap their lines to avoid horizontal scrolling.

This SO question shows which style would have to be applied to code-blocks marked as log: How do I wrap text in a pre tag?

3
  • 2
    How many people use language markup anyway ? Commented Jul 4, 2014 at 14:00
  • 18
    I for one. Especially if I use multiple languages in an answer. Still, any idea to make it more discoverable would be welcome. Commented Jul 4, 2014 at 14:02
  • 1
    yes, please! bonus feature: log highlighting for special formats (e.g. language: log-apache). here's a link to my companion request on mata.stackoverflow :) Commented Dec 22, 2021 at 18:55

3 Answers 3

1

As a workaround for single-line errors, you can use inline code formatting, for example:

Could not create file. Directory structure too deep: com/enterprise/disruptive/deep/learning/data/science/holistic/fizz/buzz/synergic/framework/manager

It's ugly, but at least you can read the whole thing without scrolling.


The reason I say single line only is that newlines get removed as well as whitespace at the start of a line, for example, look at this Python traceback:

Block:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'foo' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)

Inline:

Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name 'foo' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)

You'd have to manually add the newlines (<br/> or equivalent) and wrap each line with inline code formatting, which is a pain.

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'foo' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)

Even then, it's hard to tell where a wrapped line ends and the next line begins since there's only a tiny little space at the start of a <code> block thanks to SE's CSS (basically code { padding-left: 4px; }).

Or you could double the newlines, but it's even uglier:

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

ImportError: cannot import name 'foo' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)

Or you could use list formatting:

  1. Traceback (most recent call last):
  2. File "<stdin>", line 1, in <module>
  3. ImportError: cannot import name 'foo' from 'gi' (/usr/lib/python3/dist-packages/gi/__init__.py)
0

This would not work in all cases.

In some cases using code blocks works, but in others it's better to blockquote, so why do we need a specific option for this when we can either use code blocks with <!-- language: none --> or blockquotes as appropriate? Admittedly this doesn't solve your word wrap issue, but does solve the highlighting.

The other thing to consider that a raw dump of the log might not be the most appropriate thing to include in the question anyway. It would probably be better if only the key parts were included - like the last 5 lines, or extraneous information was edited out. If this were done the formatting issues may well disappear.

2
  • 4
    I never said all logs / warnings / error-messages should be formatted thus. But many would win considerably, as horizontal scrolling can be extremely cumbersome and the source for good and sufficient reasons could not do any proper line-wrapping, because it is viewport-dependent. Commented Jul 4, 2014 at 12:29
  • 10
    "Admittedly this does not solve your word wrap issue" That is the crux of the matter though. And even though most times 5 lines or such are enough (at least on SO) (and the OP should learn how to identify them anyway), there's no reason to make those cases where including more is appropriate unreadable or hard to do. Commented Jul 4, 2014 at 12:49
0

You already have the option of wrapping the log lines in <pre></pre> tags which will then show like a console output, but without any formatting.

Also, you won't need to use four space indents

    127.0.0.1 - [21/Dec/2012:13:55:36 -0900] "GET /clock.svg HTTP/1.0" 200 1513 

And just have the following:

<pre>
127.0.0.1 - [21/Dec/2012:13:55:36 -0900] "GET /clock.svg HTTP/1.0" 200 1513 
</pre>
1
  • 10
    Please consider that the main point was not removing the formatting but allowing word-wrapping instead of horizontal scrolling. I know the rest is already trivially possible, and I wrote down another way already. Added highlighting to the proposal. Commented Jul 5, 2014 at 17:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .