Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Created stacktraces.groovy

  • Loading branch information...
commit fa8e4effd9467d002ebdb85b2fba89024ff9a06f 1 parent d4dd304
Andrey Paramonov authored
Showing with 42 additions and 0 deletions.
  1. +42 −0 stacktraces.groovy
View
42 stacktraces.groovy
@@ -0,0 +1,42 @@
+#!/usr/bin/env groovy
+
+if (!args) {
+ println 'Usage: stacktraces.groovy <path/to/logfile>'
+ System.exit 0
+}
+
+class LogFile extends File {
+
+ String entryStartPattern
+
+ LogFile(String fileName, String entryStartPattern) {
+ super(fileName)
+ this.entryStartPattern = entryStartPattern
+ }
+
+ def eachEntry(closure) {
+ def newEntry = true, entry = ''
+ eachLine {
+ if (newEntry) {
+ entry += it
+ newEntry = false
+ } else if (it =~ entryStartPattern) {
+ closure.call entry
+ entry = it
+ } else {
+ entry += "\n${it}"
+ }
+ }
+ closure.call entry
+ }
+
+ def eachStacktrace(closure) {
+ eachEntry() {
+ if (it =~ /(?m)^(?:\t| {8})at/) closure.call it
+ }
+ }
+}
+
+new LogFile(args[0], /^\d{4}-\d{2}-\d{2}/).eachStacktrace() {
+ println it
+}
Please sign in to comment.
Something went wrong with that request. Please try again.