8

I'm fairly confused on how I should be formatting error logs. I've been coming across lots of posts like this one, where people post the errors that they are getting, or what LogCat is throwing at them. This is very important for the people who are answering, and it needs to be easily readable.

Leaving it without formatting is obviously not the right way to do it - it looks pretty ugly:

Error Log without formatting

I think that a quote makes sense, but the quote looks ugly as well.

Error log formatted as a quote

Formatting as code looks fine:

Error log formatted as code

So my question has two main parts:

First of all, by convention, how should I format all of these logs and error messages?

Second of all, why does formatting something as a quote behave the way it does? When I select the error in the raw post, it looks like this: selected text But then when I hit the "quote" button, it gets broken like this: "quoted" text

Is that the intended behavior? What's going on? Why the weird breaks?

3
  • 1
    Rule of thumb: if it's an output of a program (including stack trace on console), then most probably it should be in code-block.
    – Andrew T.
    Nov 17, 2014 at 5:02
  • 2
    @AndrewT. uh, rule of thumb: If it's code, it goes in a code block. If it's not code, it doesn't. Output isn't code. Putting non-code into a code block results in invalid syntax highlighting and makes the baby Jesus weep. Unless and only if you turn off syntax highlighting. I'll expound on this in an answer.
    – user1228
    Nov 17, 2014 at 19:10
  • @Will sorry, I forgot to expand my comment since I remembered I've seen similar question and was trying to find it. Turns out this answer on MSE is the one I remember. My comment is partially correct, and your answer is correct.
    – Andrew T.
    Nov 18, 2014 at 2:56

1 Answer 1

10

There's only two ways, imho. Depends on how lazy you are, which you choose.

The "correct" way to format output or exception details would to be well formatted and easily read. I'd say this definitely precludes throwing it blindly in a code block, as that results in idiotic random syntax formatting:

enter image description here

UGH! People should be shot for that.

If your output doesn't have any tabbed formatting or require monospace in order to be easily read, then using a quote is sufficient

04-28 09:26:55.935: E/AndroidRuntime(1437): FATAL EXCEPTION: main
04-28 09:26:55.935: E/AndroidRuntime(1437): Process:
com.neurondigital.HighwaySpeed, PID: 1437 04-28 09:26:55.935:
E/AndroidRuntime(1437): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{com.neurondigital.HighwaySpeed/com.neurondigital.HighwaySpeed.HighwaySpeed}:
java.lang.NullPointerException 04-28 09:26:55.935:
E/AndroidRuntime(1437): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)

Note, you probably will have to use a double space " " at the end of each line to enforce line breaks.

Alternatively, if you don't want to work that hard, or if your output has formatting or horizontal columns or something else that requires monospaced font to make it easily readable, place it in a code block but after turning off syntax highlighting using <!-- language: lang-none -->. The following is formatted as code so you can see how it works. See this answer for more information.

<!-- language: lang-none -->

    SEVERE: Exception loading sessions from persistent storage
    java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException:
       bean.ProjectAreaBean
     at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1333)

which results in

SEVERE: Exception loading sessions from persistent storage
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException:
   bean.ProjectAreaBean
 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1333)

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