Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint few stack trace lines while iterating through log file entries
    primarykey
    data
    text
    <p>I'm creating a Log Filter application that will present a report of all the ERROR entries that were found in the application logs, I was wondering what would be the best method to present a few lines of the stack trace along with each error.</p> <p>The final result would be something like this:</p> <pre><code>+ ErrorA - ErrorB com.package.Class.method(Class.java:666) com.package.AnotherClass.ADifferentMethodMethod(Class.java:2012) com.thatOtherPackage.ThatClass.someOtherMethod(ThatClass.java:34) + ErrorC </code></pre> <p>Here's what I have so far:</p> <pre><code>public JSONArray processFiles(File[] files){ FileReader fr = null; BufferedReader br = null; JSONObject jFiles = new JSONObject(); JSONArray jaf = new JSONArray(); try { for (File file : files) { jFiles.put("fileName", file.getName()); boolean fileIsOk = true; try { fr = new FileReader(file); } catch (FileNotFoundException e) { //Thanks to Windows, there's no way to check file.canRead() //http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6203387 fileIsOk = false; } if(fileIsOk) { br = new BufferedReader(fr); String line = null; JSONObject jLogEntries = new JSONObject(); JSONArray jalog = new JSONArray(); int lineNum = 0; while ((line = br.readLine()) != null) { if (line.contains("| ERROR |")) { jLogEntries.put("line " + lineNum, line); ++lineNum; } **// TODO: Implement something to print the next 5 lines of the stack trace.** } lineNum = 0; jalog.add(jLogEntries); jFiles.put("logEntries", jalog); jaf.add(jFiles); } }// end of files iteration } catch (IOException e) { e.printStackTrace(); } catch (Exception e){ e.printStackTrace(); } return jaf; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload