Skip to content

Commit

Permalink
Stack trace support
Browse files Browse the repository at this point in the history
  • Loading branch information
weeeBox committed Nov 26, 2015
1 parent 461bc4f commit 7ad3841
Show file tree
Hide file tree
Showing 54 changed files with 1,880 additions and 362 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Lunar Console Changelog

## v.0.0.8b - TBA

**Improvements:**

* **Android**: added stack trace info for every log entry.
* **iOS**: improved stack trace info for every log entry.

**Fixes:**

* **Android**: fixed touches passing through some are of the console into the scene.

## v.0.0.7b - 11/23/2015

**Fixes:**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
387 changes: 387 additions & 0 deletions Native/Android/LunarConsole/app/src/main/assets/input.txt

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,92 +1,103 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<LinearLayout
android:orientation="horizontal"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout">
android:orientation="horizontal">

<EditText
style="@style/IntEditText"
android:id="@+id/edit_text_delay"
style="@style/IntEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1000"/>

<Button
android:id="@+id/button_start_logger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_logger_start"
android:id="@+id/button_start_logger"/>
android:text="@string/button_logger_start"/>

</LinearLayout>

<Button
android:id="@+id/button_log_exception"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_log_error"
android:id="@+id/button_log_exception"
android:layout_above="@+id/button_show_console"
android:layout_alignEnd="@+id/button_show_console"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/button_show_console"
android:layout_alignEnd="@+id/button_show_console"/>
android:text="@string/button_log_error"/>

<Button
android:id="@+id/button_show_console"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Console"
android:id="@+id/button_show_console"
android:layout_alignEnd="@+id/linearLayout"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/linearLayout"
android:layout_alignEnd="@+id/linearLayout"/>
android:text="Show Console"/>

<EditText
android:id="@+id/edit_text_capacity"
style="@style/IntEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_text_capacity"
android:layout_below="@+id/linearLayout"
android:layout_alignEnd="@+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/linearLayout"
android:layout_alignEnd="@+id/linearLayout"
android:layout_below="@+id/linearLayout"
android:text="1024"/>

<EditText
android:id="@+id/edit_text_trim"
style="@style/IntEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_text_trim"
android:layout_below="@+id/edit_text_capacity"
android:layout_alignEnd="@+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/linearLayout"
android:layout_alignEnd="@+id/linearLayout"
android:layout_below="@+id/edit_text_capacity"
android:text="128"/>

<CheckBox
android:id="@+id/checkbox_use_main_thread"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Use main thread"
android:checked="true"
android:id="@+id/checkbox_use_main_thread"
android:layout_below="@+id/edit_text_trim"
android:layout_alignEnd="@+id/edit_text_capacity"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/edit_text_capacity"
android:layout_alignEnd="@+id/edit_text_capacity"/>
android:layout_below="@+id/edit_text_trim"
android:checked="true"
android:text="Use main thread"/>

<CheckBox
android:id="@+id/checkbox_enable_stack_trace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/checkbox_use_main_thread"
android:checked="true"
android:text="Enable stack trace"/>


</RelativeLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package spacemadness.com.lunarconsole.utils;

import junit.framework.TestCase;

public class StackTraceTest extends TestCase
{
public void testOptimize() throws Exception
{
String stackTrace = "UnityEngine.Debug:LogError(Object)\n" +
"Test:Method(String) (at /Users/lunar-unity-console/Project/Assets/Scripts/Test.cs:30)\n" +
"<LogMessages>c__Iterator0:MoveNext() (at /Users/lunar-unity-console/Project/Assets/Logger.cs:85)\n" +
"UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)\n" +
"Logger:LogMessages() (at /Users/lunar-unity-console/Project/Assets/Logger.cs:66)\n" +
"UnityEngine.EventSystems.EventSystem:Update()";

String expected = "UnityEngine.Debug:LogError(Object)\n" +
"Test:Method(String) (at Assets/Scripts/Test.cs:30)\n" +
"<LogMessages>c__Iterator0:MoveNext() (at Assets/Logger.cs:85)\n" +
"UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)\n" +
"Logger:LogMessages() (at Assets/Logger.cs:66)\n" +
"UnityEngine.EventSystems.EventSystem:Update()";

String actual = StackTrace.optimize(stackTrace);
assertEquals(expected, actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package spacemadness.com.lunarconsole.console;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -112,9 +113,14 @@ void bindViewHolder(ConsoleEntry entry)

public abstract void onBindViewHolder(T entry);

protected Context getContext()
{
return itemView.getContext();
}

protected Resources getResources()
{
return itemView.getContext().getResources();
return getContext().getResources();
}

protected String getString(int id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

package spacemadness.com.lunarconsole.console;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
Expand All @@ -32,6 +33,17 @@

public class ConsoleEntry
{
private static final int[] LOG_ENTRY_ICON_RES_LOOKUP = new int[COUNT];

static
{
LOG_ENTRY_ICON_RES_LOOKUP[ERROR] = R.drawable.lunar_console_icon_log_error;
LOG_ENTRY_ICON_RES_LOOKUP[ASSERT] = R.drawable.lunar_console_icon_log_error;
LOG_ENTRY_ICON_RES_LOOKUP[WARNING] = R.drawable.lunar_console_icon_log_warning;
LOG_ENTRY_ICON_RES_LOOKUP[LOG] = R.drawable.lunar_console_icon_log;
LOG_ENTRY_ICON_RES_LOOKUP[EXCEPTION] = R.drawable.lunar_console_icon_log_error;
}

public int index;
public final byte type;
public final String message;
Expand All @@ -49,6 +61,33 @@ public ConsoleEntry(byte type, String message, String stackTrace)
this.stackTrace = stackTrace;
}

@SuppressWarnings("deprecation")
public Drawable getIconDrawable(Context context)
{
int id = getIconResId(type);
return context.getResources().getDrawable(id);
}

@SuppressWarnings("deprecation")
public int getBackgroundColor(Context context)
{
int colorId = index % 2 == 0 ?
R.color.lunar_console_color_cell_background_dark :
R.color.lunar_console_color_cell_background_light;
return context.getResources().getColor(colorId);
}

public boolean hasStackTrace()
{
return stackTrace != null && stackTrace.length() > 0;
}

private int getIconResId(int type)
{
return type >= 0 && type < LOG_ENTRY_ICON_RES_LOOKUP.length ?
LOG_ENTRY_ICON_RES_LOOKUP[type] : R.drawable.lunar_console_icon_log;
}

//////////////////////////////////////////////////////////////////////////////
// View holder

Expand All @@ -58,17 +97,6 @@ public static class ViewHolder extends ConsoleAdapter.ViewHolder<ConsoleEntry>
private final ImageView iconView;
private final TextView messageView;

private static final int[] LOG_ENTRY_ICON_RES_LOOKUP = new int[COUNT];

static
{
LOG_ENTRY_ICON_RES_LOOKUP[ERROR] = R.drawable.lunar_console_icon_log_error;
LOG_ENTRY_ICON_RES_LOOKUP[ASSERT] = R.drawable.lunar_console_icon_log_error;
LOG_ENTRY_ICON_RES_LOOKUP[WARNING] = R.drawable.lunar_console_icon_log_warning;
LOG_ENTRY_ICON_RES_LOOKUP[LOG] = R.drawable.lunar_console_icon_log;
LOG_ENTRY_ICON_RES_LOOKUP[EXCEPTION] = R.drawable.lunar_console_icon_log_error;
}

public ViewHolder(View itemView)
{
super(itemView);
Expand All @@ -81,26 +109,10 @@ public ViewHolder(View itemView)
@Override
public void onBindViewHolder(ConsoleEntry entry)
{
int backgroundColor = entry.index % 2 == 0 ?
getColor(R.color.lunar_console_color_cell_background_dark) :
getColor(R.color.lunar_console_color_cell_background_light);
layout.setBackgroundColor(backgroundColor);

iconView.setImageDrawable(getIconResDrawable(entry.type));
Context context = getContext();
layout.setBackgroundColor(entry.getBackgroundColor(context));
iconView.setImageDrawable(entry.getIconDrawable(context));
messageView.setText(entry.message);
}

@SuppressWarnings("deprecation")
private Drawable getIconResDrawable(int type)
{
int id = getIconResId(type);
return getResources().getDrawable(id);
}

private int getIconResId(int type)
{
return type >= 0 && type < LOG_ENTRY_ICON_RES_LOOKUP.length ?
LOG_ENTRY_ICON_RES_LOOKUP[type] : R.drawable.lunar_console_icon_log;
}
}
}

0 comments on commit 7ad3841

Please sign in to comment.