Parse Java stack traces and transform them into comprehensive JS objects
You can checkout this working demo to see how it looks like.
| Branch | Build | Grade | Test coverage |
|---|---|---|---|
master(Stable) | |||
develop |
You can install this package either with npm, yarn or bower.
For npm:
~$ npm install java-stack-parserFor yarn:
~$ yarn add java-stack-parserThen, you can require('java-stack-parser'), import from 'java-stack-parser' or include the library in your web page directly via a <script> tag
<scriptsrc="/node_modules/java-stack-parser/lib/java-stack-parser.min.js"></script>~$ bower install java-stack-parserThen, you can include the library in your web page directly via a <script> tag
<scriptsrc="/bower_components/java-stack-parser/lib/java-stack-parser.min.js"></script>The library defines 3 objects:
Stack: represents the full stacktrace. It is compose of a list ofStackGroups.StackGrouprepresents a group of consecutiveStackLines with the sameStackPackage.StackLinerepresents a line of the full stacktrace, e.g.at java.net.SocketInputStream.read(SocketInputStream.java:185).StackPackagerepresents the package of the currentStackLine. Taking theStackLineabove, the resultingStackPackagewill bejava.net.
This object is used to parse and transform a string representing a Java stack trace. Here is an example of how to use it:
import{Stack}from'java-stack-parser';letstacktrace='...';letstack=newStack();stack.parse(stacktrace);// Display stack trace information into the consolestack.groups.forEach((group)=>{if(group.exception){console.log('['+group.exception.exception+'] '+group.exception.message);}console.log('Package: '+group.stackPackage.name+' contains '+group.lines.length+' lines');group.lines.forEach((line)=>{console.log(line.javaClass+'.'+line.method+' (Source: '+line.source+' at line: '+line.line+')');});});The Stack object gives you the ability of defining your own "vendor" packages, resulting of a better grouping. For example, if your application uses 2 libraries with a groupId of com.acme and my.library, you can pass this as an optional parameter to the constructor:
letstack=newStack({'My libraries': ['com.acme','my.library'],"Java/Sun/Oracle": ["java","javax","sun","sunw","com.sun","com.oracle"],"Apache": ["org.apache"],});Now, if the stack trace contains consecutive lin with the package com.acme or my.library, they will be group under the same StackGroup.
To build the library in development mode (non-uglified, with a watch on the source) simply do:
~$ npm run devFor the production version:
~$ npm run buildYou can run tests and check the coverage with the following 2 commands:
# Run tests~$ npm test# Check coverage~$ npm run coverageThis library is released under Apache 2.0 license