/**
 * Cobub Razor
 * <p>
 * An open source analytics android sdk for mobile applications
 *
 * @package Cobub Razor
 * @author WBTECH Dev Team
 * @copyright Copyright (c) 2011 - 2012, NanJing Western Bridge Co.,Ltd.
 * @license http://www.cobub.com/products/cobub-razor/license
 * @link http://www.cobub.com/products/cobub-razor/
 * @filesource
 * @since Version 0.1
 */
package com.oo.seex.oo_statistics_lib.utils;

import android.content.Context;
import android.content.SharedPreferences;

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

/**
 * 这个子线程就是用来读取系统错误日志的   log.e的内容也会被读取到
 */
public class ReadErrorLog extends Thread {
    Context context = null;


    public ReadErrorLog(Context context) {
        super();
        this.context = context;
    }


    @Override
    public void run() {
        //这个方法就是获取错误信息的
        Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

            @Override
            public void uncaughtException(Thread thread, Throwable ex) {
                StringWriter sw = new StringWriter();
                PrintWriter p = new PrintWriter(sw);
                ex.printStackTrace(p);
                String s = sw.toString();
                SharedPreferences sharedPreferences = context.getSharedPreferences("error", 0);
                String info = sharedPreferences.getString("info", "");
                info = info + s + "\n";
                sharedPreferences.edit().putString("info", info).commit();
                p.close();
            }
        });


    }
}
