Android Logger crashes log write file

Source: Internet
Author: User

The stack call log that causes the program to crash writes to the file for easy collection of bugs. In Debugging the Android program, for some reason the phone can not connect to the PC side, the IDE can not see the program crashed log, I hope log can be written to the file, for the published app can be used to collect bugs through this feature.

01import Java.io.filenotfoundexception;02import Java.io.fileoutputstream;03import Java.io.ioexception;04import Java.io.printstream;05import java.lang.thread.uncaughtexceptionhandler;06 07public class Mycrashhandler implements uncaughtexceptionhandler{08 private static Mycrashhandler crashhandler;10 @Override12 public void Uncau Ghtexception (thread thread, Throwable ex) {//TODO auto-generated method stub14 if (Crashhandler! = null) {try {vi template Daquan                //write crash log to file             &NB Sp  fileoutputstream FileOutputStream = new FileOutputStream ("/mnt/sdcard/crash_log.txt", true);                printstream printstream = new PrintStream (fileoutputstream),     &NBS P          ex.printstacktrace (printstream)               &NBS P;printstream.flush ()                printstream.close ();     &NBS P          fileoutputstream.close (), &nbsp           Filenotfou; Ndexception e) {               //TODO auto-generated catch block25   &nbs P            e.printstacktrace (), +            } catch (Ioexcept Ion e) {  &nbsp            //TODO auto-generated catch block28             &N Bsp  e.printstacktrace ()            }30        }31    }&NB sp;32     33    //Set default processor  thread    public void init () {+]       . Setdefaultuncaughtexceptionhandler (this);    }HTTP://WWW.HUIYI8.COM/VI/37     38    private Mycrashhandler () {}39     40    //single-case,  public static Mycrashhandler I Nstance () {       if (Crashhandler = = null) {$            synchroniz Ed (crashhandler) {               crashhandler = new Mycrashhandler ();          }46        }47        return crashhandler;48 &N Bsp  }49}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.