Giter Site home page Giter Site logo

java-stack-parser's Introduction

java-stack-parser

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) Travis Codacy Codecov
develop Travis Codacy Codecov

Install

You can install this package either with npm, yarn or bower.

npm / yarn

For npm:

~$ npm install java-stack-parser

For yarn:

~$ yarn add java-stack-parser

Then, you can require('java-stack-parser'), import from 'java-stack-parser' or include the library in your web page directly via a <script> tag

<script src="/node_modules/java-stack-parser/lib/java-stack-parser.min.js"></script>

bower

~$ bower install java-stack-parser

Then, you can include the library in your web page directly via a <script> tag

<script src="/bower_components/java-stack-parser/lib/java-stack-parser.min.js"></script>

Documentation

The library defines 3 objects:

  • Stack: represents the full stacktrace. It is compose of a list of StackGroups.
  • StackGroup represents a group of consecutive StackLines with the same StackPackage.
  • StackLine represents a line of the full stacktrace, e.g. at java.net.SocketInputStream.read(SocketInputStream.java:185).
  • StackPackage represents the package of the current StackLine. Taking the StackLine above, the resulting StackPackage will be java.net.

Stack Object

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';

let stacktrace = '...';
let stack = new Stack();

stack.parse(stacktrace);

// Display stack trace information into the console
stack.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:

let stack = new Stack({
    '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.

Development

To build the library in development mode (non-uglified, with a watch on the source) simply do:

~$ npm run dev

For the production version:

~$ npm run build

You can run tests and check the coverage with the following 2 commands:

# Run tests
~$ npm test
# Check coverage
~$ npm run coverage

License

This library is released under Apache 2.0 license

java-stack-parser's People

Contributors

tbouron avatar

Stargazers

Zo-Hasina Rasatavohary avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.