1#!/usr/bin/ruby
2# Copyright 2010 Thomas Stromberg - All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16#
17# Gives you information about the most recent crash for each application
18# that has crashed within the last 2 days
19
20$LogDir=ENV['HOME'] + '/Library/Logs/CrashReporter'
21$Days=1
22$StackCount=5
23
24files=`find #$LogDir -mtime -#$Days -type f | grep -v synergy`
25files.each { |filename|
26    filename.chop!
27    record = 0
28    date=''
29    stackTrace = []
30
31    File.open(filename).readlines.each { |line|
32        #puts line
33
34        if line =~ /^Date.*(200.*)/
35            date = $1
36        end
37
38        if line =~ /^Thread \d+ Crashed/
39            record = 1
40            # reset the stack trace
41            stackTrace = []
42        end
43
44        if record
45            stackTrace << line
46            record = record + 1
47
48            # stop recording after $StackCount lines
49            if record > ($StackCount + 2)
50                record = nil
51            end
52        end
53    }
54
55    puts File.basename(filename) + " - " + date
56    puts "==================================================="
57    stackTrace.each { |line|
58        puts line
59    }
60    puts ""
61}
62
63
64