Skip to content

Commit

Permalink
Created stacktraces.groovy
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Paramonov committed Oct 28, 2009
1 parent d4dd304 commit fa8e4ef
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions stacktraces.groovy
Original file line number Original file line Diff line number Diff line change
@@ -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
}

0 comments on commit fa8e4ef

Please sign in to comment.