39

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 ? Jul 4, 2014 at 14:00
  • 14
    I for one. Especially if I use multiple languages in an answer. Still, any idea to make it more discoverable would be welcome. Jul 4, 2014 at 14:02
  • 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 :) Dec 22, 2021 at 18:55

2 Answers 2

1

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
  • 8
    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. Jul 5, 2014 at 17:49
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. Jul 4, 2014 at 12:29
  • 7
    "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. Jul 4, 2014 at 12:49

You must log in to answer this question.

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