Skip to content

Commit

Permalink
log exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
obs committed Jul 12, 2016
1 parent 7ac92f1 commit a32ac08
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class Logger {
public static File getFile() {
return new File(Environment.getExternalStorageDirectory(), "PMCADEMO/LOG.TXT");
return new File(Environment.getExternalStorageDirectory(), "BMANUAL/LOG.TXT");
}

protected static void log(String msg) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.obsidium.bettermanual;

import com.github.ma1co.pmcademo.app.Logger;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

public class CustomExceptionHandler implements Thread.UncaughtExceptionHandler
{
private final Thread.UncaughtExceptionHandler defaultUEH;

public CustomExceptionHandler()
{
this.defaultUEH = Thread.getDefaultUncaughtExceptionHandler();
}

public void uncaughtException(Thread t, Throwable e) {
final Writer result = new StringWriter();
final PrintWriter printWriter = new PrintWriter(result);
e.printStackTrace(printWriter);
String stacktrace = result.toString();
printWriter.close();
Logger.error(stacktrace);
defaultUEH.uncaughtException(t, e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ protected void onCreate(Bundle savedInstanceState)

setContentView(R.layout.activity_manual);

if (!(Thread.getDefaultUncaughtExceptionHandler() instanceof CustomExceptionHandler))
Thread.setDefaultUncaughtExceptionHandler(new CustomExceptionHandler());

SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
surfaceView.setOnTouchListener(new SurfaceSwipeTouchListener(this));
m_surfaceHolder = surfaceView.getHolder();
Expand Down

0 comments on commit a32ac08

Please sign in to comment.