Kaloyan Roussev
Kaloyan Roussev

Reputation: 14711

Android Studio LogCat doesnt display new lines

If I try to Log.e or Log.d something that stretches to a few lines, only the first line is shown in my LogCat. This has been happening for a month now. How do I overcome this?

Example:

I have a list of WorkDay objects, whose toString() implementation looks like this:

@Override
public String toString() {
    StringBuilder stringBuilder = new StringBuilder(50);
    stringBuilder.append("\n\nWorkDay string representation: ");
    stringBuilder.append("\nworkEntries: ");
    stringBuilder.append(workEntries);
    stringBuilder.append("\ndate: ");
    stringBuilder.append(date);
    stringBuilder.append("\nisUpdated: ");
    stringBuilder.append(isUpdated);
    stringBuilder.append("\nshiftCode: ");
    stringBuilder.append(shiftCode);
    return stringBuilder.toString();
}

When i log.e a list of those, I used to get logcat output something like this:

Log.e: list {
    work day representation {
    bla bla bla bla 
    bla bla }, 
    work day representation{
    bla bla bla bla
    bla bla bla }

And now, my otput looks like this:

Log.e: list {
Log.e: whatever next output is.

What I think is happening is, that LogCat trims new lines. How do I make it show them.

Upvotes: 2

Views: 1407

Answers (2)

aaaabcv
aaaabcv

Reputation: 29

Sorry, the marked answer is just a solution if I make my own logs. When I have 3rd party code I still have the problem. I observed that the newline separated lines are swallowed only in Android Studio (1.5 for me) but e.g. Android Device Monitor shows the correct output. It's a workaround to switch to ADM for logs but veeery unconvenient.

Upvotes: 1

Alex Mamo
Alex Mamo

Reputation: 138814

The response for this problem is: stringBuilder.append(Html.fromHtml("<br>"));

Upvotes: 1

Related Questions