Skip to content

SquareSquash/java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

26 Commits

Repository files navigation

Squash Client Library: Java

This client library reports exceptions to Squash, the Squarish exception reporting and management system.

Documentation

For an overview of the various components of Squash, see the website documentation at https://github.com/SquareSquash/web.

Compatibility

This library is compatible with J2SE 1.6 or newer. All dependencies are handled by Maven.

Usage

The SquashEntry class is meant to be extended and then serialized with your choice of json library for transmission to your Squash server. We recommend using gson, but any auto-field-name-detecting library will do.

First, extend SquashEntry and include any additional occurrence data you wish to send to Squash. See the Occurrence class documentation in the Squash web code for a list of known properties; you can also supply any arbitrary properties as well.

importcom.squareup.squash.SquashEntry; publicclassAndroidSquashEntryextendsSquashEntryimplementsLogEntry{// The API key used for all Android Squash entries.privatestaticfinalStringAPI_KEY = "YOUR_API_KEY"; privatestaticfinalStringCLIENT_ID = "android"; privatestaticfinalStringDEBUG = "Debug"; privatestaticfinalStringRELEASE = "Release"; // Transient so it doesn't try to serialize itself.privatetransientGsongson; // Device stuff.privatefinalStringdevice_id; privatefinalStringdevice_type; privatefinalStringoperating_system; privatefinalbooleanrooted; privatefinalStringnetwork_operator; privatefinalStringnetwork_type; privatefinalStringconnectivity; privatefinalStringorientation; // Location stuff.privatefinalStringlat; privatefinalStringlon; privatefinalStringaltitude; privatefinalStringlocation_precision; privatefinalStringheading; privatefinalStringspeed; // Which app am I?privatefinalStringapp_id}

Build a constructor or whatever you need to set all these parameters, and then add the ability for the class to transmit itself to Squash:

publicclassAndroidSquashEntryextendsSquashEntryimplementsLogEntry{@OverridepublicvoidwriteTo(OutputStreamoutput) throwsIOException{finalStringjson = gson.toJson(this); output.write(Strings.getBytes(json))} }

Add an exception handler that will generate these entry instances. (In the below example we're assuming that you've also built a factory that instantiates Squash entries, and a transmit method that transmits the JSON to Squash.)

publicclassSquashUncaughtExceptionHandlerimplementsThread.UncaughtExceptionHandler{@InjectAndroidSquashEntryFactorysquashEntryFactory; @OverridepublicvoiduncaughtException(Threadthread, Throwableex){try{transmit(squashEntryFactory.create(message, ex))} catch (Throwableignored){// write your internal failsafe handler } } }

... and install the exception handler.

finalThread.UncaughtExceptionHandlerhandler = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler( newSquashUncaughtExceptionHandler(this, handler));

De-Obfuscation and File Paths

The Squash Java Deobfuscator Ruby gem can be included into your build-and-release process to upload yGuard or ProGuard obfuscation maps to Squash.

Even if you are not using code obfuscation, you can still use this gem to map Java class names to their original file paths, as Java stack traces do not include the full path to source files, which Squash needs to perform its Git-blame magic.

About

The Squash client library for Java projects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages