error_log 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.txt +7 -0
- data/{README.txt → README.rdoc} +4 -4
- data/lib/error_log/class_methods.rb +66 -0
- data/lib/error_log/controller.rb +21 -5
- data/lib/error_log/migrations/add_params_column.rb +10 -0
- data/lib/error_log/migrations/add_vcs_revision_column.rb +10 -0
- data/lib/error_log/migrations/base.rb +20 -0
- data/lib/error_log/migrations.rb +21 -17
- data/lib/error_log/model.rb +2 -13
- data/lib/error_log/vcs.rb +23 -0
- data/lib/error_log/version.rb +1 -1
- data/lib/error_log.rb +8 -28
- data/views/index.html.haml +18 -3
- metadata +10 -5
data/Changelog.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
0.0.6 to be
|
2
|
+
* basic VCS awareness (currently git only)
|
3
|
+
* bugfix for showing errors from any category
|
4
|
+
* bugfix for sorting by level then count
|
5
|
+
* some cleanup, and a little bit of doc
|
6
|
+
* bugfix for migrations (add_index bug)
|
7
|
+
|
1
8
|
0.0.5
|
2
9
|
* haml dependency added (sorry folks, I could not stand rhtml
|
3
10
|
* viewing archive
|
data/{README.txt → README.rdoc}
RENAMED
@@ -12,7 +12,7 @@ THIS IS AN EARLY DEVELOPMENT VERSION, DO NOT EVEN TOUCH PRODUCTION SERVER WITH I
|
|
12
12
|
Actually, it is so unmature that even playing with it can make you sad.
|
13
13
|
And no one likes to be sad.
|
14
14
|
|
15
|
-
dev screenshot: http://tesuji.pl/error_logs.png
|
15
|
+
dev screenshot: http://tesuji.pl/error_logs.png (v 0.0.2)
|
16
16
|
|
17
17
|
== REQUIREMENTS
|
18
18
|
|
@@ -53,15 +53,15 @@ To be continued.
|
|
53
53
|
|
54
54
|
== TODOS
|
55
55
|
|
56
|
-
*
|
56
|
+
* alternative errors storage (for database failures, probably sqlite will do)
|
57
57
|
* better params viewing (currently only example params)
|
58
58
|
* setting error level threshold while browsing
|
59
59
|
* better look (themes would be good, but I really do not like css, so help needed)
|
60
60
|
* adding errors to ignore list
|
61
61
|
* pagination could by nice ;) (it ain't actually so bad without it thanks to grouping)
|
62
|
-
*
|
63
|
-
* clickable backtraces? we could show some code
|
62
|
+
* clickable backtraces? we could try showing some code
|
64
63
|
* rails 2.x compatibility
|
64
|
+
* svn & other vcs support
|
65
65
|
|
66
66
|
== STUFF
|
67
67
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module ErrorLog
|
2
|
+
module ClassMethods
|
3
|
+
|
4
|
+
def options
|
5
|
+
@options ||= {
|
6
|
+
:vcs => Vcs.guess
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
# Log error, exception, or whatever you have on your mind
|
11
|
+
#
|
12
|
+
# Args:
|
13
|
+
# * level - error level {:debug, :info, :warn, :error, :fatal}
|
14
|
+
# * error - error string itself
|
15
|
+
# * options
|
16
|
+
#
|
17
|
+
# Possible options:
|
18
|
+
# * :backtrace
|
19
|
+
# * :params - params that can help you recreate this error, Hash
|
20
|
+
# * :category - error category, helps you to group them later
|
21
|
+
#
|
22
|
+
def log(level,error,options={})
|
23
|
+
backtrace = options[:backtrace]
|
24
|
+
unless backtrace
|
25
|
+
begin
|
26
|
+
# I'm raising an exception just to get the current backtrace
|
27
|
+
# If there is any more clever way to do that, please share.
|
28
|
+
raise "wat?!"
|
29
|
+
rescue Exception => e
|
30
|
+
backtrace = e.backtrace[1..-1]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Silent rescues may not be optimal, for now they seem better than creating more mess
|
35
|
+
logger.error "\n\n\n#{Time.now}\n= #{error}\n#{backtrace.join("\n")}\n#{options[:params]}" rescue nil
|
36
|
+
|
37
|
+
ErrorLog::Model.create(
|
38
|
+
:error => error,
|
39
|
+
:backtrace => backtrace,
|
40
|
+
:level => level,
|
41
|
+
:params => options[:params],
|
42
|
+
:vcs_revision => current_revision,
|
43
|
+
:category => options[:category] || 'error_log'
|
44
|
+
) rescue nil
|
45
|
+
end
|
46
|
+
|
47
|
+
# Errors log, may be useful when you're facing some db related problems
|
48
|
+
def logger
|
49
|
+
@logger = Logger.new(File.join(Rails.root,'log','error.log'))
|
50
|
+
end
|
51
|
+
|
52
|
+
def init
|
53
|
+
@current_revision = Vcs.revision
|
54
|
+
Migrations.auto_migrate!
|
55
|
+
end
|
56
|
+
|
57
|
+
def current_revision
|
58
|
+
@current_revision
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
class << self
|
64
|
+
include ClassMethods
|
65
|
+
end
|
66
|
+
end
|
data/lib/error_log/controller.rb
CHANGED
@@ -9,9 +9,10 @@ module ErrorLog
|
|
9
9
|
|
10
10
|
prepare_opts
|
11
11
|
|
12
|
-
scope = ErrorLog::Model
|
12
|
+
scope = cat_scope = rev_scope = ErrorLog::Model
|
13
13
|
|
14
|
-
scope = scope.where(:category => @
|
14
|
+
scope = cat_scope = scope.where(:category => @opts[:category]) if @opts[:category]
|
15
|
+
scope = rev_scope = scope.where(:vcs_revision => @opts[:revision].empty? ? nil : @opts[:revision]) if @opts[:revision]
|
15
16
|
|
16
17
|
@error_logs = scope.all(
|
17
18
|
:select => 'count(*) as count_all,
|
@@ -30,11 +31,20 @@ module ErrorLog
|
|
30
31
|
})
|
31
32
|
|
32
33
|
|
33
|
-
@category_counts =
|
34
|
+
@category_counts = rev_scope.count(
|
34
35
|
:conditions => {:viewed => viewing_archive?},
|
35
36
|
:group => :category
|
36
37
|
)
|
37
38
|
|
39
|
+
@revisions = cat_scope.all(
|
40
|
+
:select => 'vcs_revision,
|
41
|
+
min(created_at) as created_at_first,
|
42
|
+
count(*) as count_all',
|
43
|
+
:conditions => {:viewed => viewing_archive?},
|
44
|
+
:group => :vcs_revision,
|
45
|
+
:order => 'created_at_first'
|
46
|
+
)
|
47
|
+
|
38
48
|
render :template => '/index'
|
39
49
|
end
|
40
50
|
|
@@ -82,12 +92,13 @@ module ErrorLog
|
|
82
92
|
'first' => 'created_at_first DESC',
|
83
93
|
'count' => 'count_all DESC',
|
84
94
|
'level' => 'level_id DESC',
|
85
|
-
'level_count' => '
|
95
|
+
'level_count' => 'level_id DESC, count_all DESC'
|
86
96
|
}
|
87
97
|
|
88
98
|
@opts = {
|
89
99
|
:archive => '0',
|
90
100
|
:sort_by => sorts['last'],
|
101
|
+
:revision => nil,
|
91
102
|
:category => nil
|
92
103
|
}
|
93
104
|
|
@@ -98,7 +109,12 @@ module ErrorLog
|
|
98
109
|
@opts[:sort_by] = sorts[session[:erlgs_sort_by]]
|
99
110
|
|
100
111
|
session[:erlgs_category] = params[:category] if params[:category]
|
101
|
-
|
112
|
+
session[:erlgs_category] = nil if params[:category] == '-none-'
|
113
|
+
@opts[:category] = session[:erlgs_category]
|
114
|
+
|
115
|
+
session[:erlgs_revision] = params[:revision] if params[:revision]
|
116
|
+
session[:erlgs_revision] = nil if params[:revision] == '-none-'
|
117
|
+
@opts[:revision] = session[:erlgs_revision]
|
102
118
|
end
|
103
119
|
end
|
104
120
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ErrorLog
|
2
|
+
module Migrations
|
3
|
+
# Base migration, create error_logs table
|
4
|
+
class Base < ActiveRecord::Migration
|
5
|
+
def self.up
|
6
|
+
create_table :error_logs do |t|
|
7
|
+
t.text :error
|
8
|
+
t.text :backtrace
|
9
|
+
t.string :category
|
10
|
+
t.string :error_hash
|
11
|
+
t.integer :level_id
|
12
|
+
t.timestamp :created_at
|
13
|
+
t.boolean :viewed, :default => false
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :error_logs, :category
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/error_log/migrations.rb
CHANGED
@@ -1,25 +1,29 @@
|
|
1
1
|
module ErrorLog
|
2
|
+
module Migrations
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
# Chack what do we have in database and migratie what's needed
|
5
|
+
# Those migrations does not work like rails migrations, I check manually if table exists,
|
6
|
+
# or if given column exist, and add it if it's not there. I didnt want to use rails migrations
|
7
|
+
# to avoid messing with your database, and adding there anything more than the error_logs table
|
8
|
+
# that is needed. Also this way we dont have to care if you still use old kind of numbered
|
9
|
+
# migrations.
|
10
|
+
def self.auto_migrate!
|
11
|
+
|
12
|
+
unless Model.table_exists?
|
13
|
+
Base.up
|
14
|
+
Model.reset_column_information
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
unless Model.column_names.include?('params')
|
18
|
+
AddParamsColumn.up
|
19
|
+
Model.reset_column_information
|
20
|
+
end
|
21
|
+
|
22
|
+
unless Model.column_names.include?('vcs_revision')
|
23
|
+
AddVcsRevisionColumn.up
|
24
|
+
Model.reset_column_information
|
25
|
+
end
|
19
26
|
|
20
|
-
class UpgradeMigration1 < ActiveRecord::Migration
|
21
|
-
def self.up
|
22
|
-
add_column :error_logs, :params, :text
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
data/lib/error_log/model.rb
CHANGED
@@ -5,18 +5,6 @@ module ErrorLog
|
|
5
5
|
|
6
6
|
self.table_name = 'error_logs'
|
7
7
|
|
8
|
-
# Migrate database if needed
|
9
|
-
unless self.table_exists?
|
10
|
-
Migration.up
|
11
|
-
reset_column_information
|
12
|
-
end
|
13
|
-
|
14
|
-
# Upgrade if needed
|
15
|
-
unless column_names.include?('params')
|
16
|
-
UpgradeMigration1.up
|
17
|
-
reset_column_information
|
18
|
-
end
|
19
|
-
|
20
8
|
LEVELS = {
|
21
9
|
:debug => 0,
|
22
10
|
:info => 1,
|
@@ -28,7 +16,6 @@ module ErrorLog
|
|
28
16
|
}
|
29
17
|
|
30
18
|
serialize :params, Hash
|
31
|
-
attr_accessor :count # used in grouping
|
32
19
|
|
33
20
|
def level
|
34
21
|
LEVELS.invert[self.level_id]
|
@@ -47,6 +34,8 @@ module ErrorLog
|
|
47
34
|
|
48
35
|
obj.error_hash = Digest::MD5.hexdigest(obj.backtrace.to_s + obj.error.to_s + obj.category.to_s)
|
49
36
|
|
37
|
+
obj.vcs_revision = nil if vcs_revision.empty?
|
38
|
+
|
50
39
|
true
|
51
40
|
end
|
52
41
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ErrorLog
|
2
|
+
# VCS would be a better name, I'm just sticking to rails file and modules naming convention
|
3
|
+
module Vcs
|
4
|
+
def self.guess
|
5
|
+
if File.exists?(File.join(Rails.root,'.git'))
|
6
|
+
return :git
|
7
|
+
end
|
8
|
+
false
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.revision
|
12
|
+
case ErrorLog.options[:vcs]
|
13
|
+
when :git
|
14
|
+
git_root = File.join(Rails.root,'.git')
|
15
|
+
head = File.read("#{git_root}/HEAD")
|
16
|
+
ref = head.strip.split("ref:",2).last.strip
|
17
|
+
hash = File.read("#{git_root}/#{ref}").strip
|
18
|
+
else
|
19
|
+
''
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/error_log/version.rb
CHANGED
data/lib/error_log.rb
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
require 'pp'
|
2
2
|
|
3
|
+
|
4
|
+
# Everything you find directly in this module is skel from bones
|
5
|
+
# Some really useful methods as for lib, but you probably are not
|
6
|
+
# interested in any of them
|
7
|
+
#
|
8
|
+
# If you want to take a look at methods that you call directly on
|
9
|
+
# ErrorLog module, like ErrorLog.log, take a look at class_methods.rb
|
3
10
|
module ErrorLog
|
4
11
|
|
5
12
|
# :stopdoc:
|
@@ -60,37 +67,10 @@ module ErrorLog
|
|
60
67
|
Dir.glob(search_me).sort.each {|rb| require rb}
|
61
68
|
end
|
62
69
|
|
63
|
-
|
64
|
-
def self.log(level,error,options={})
|
65
|
-
backtrace = options[:backtrace]
|
66
|
-
unless backtrace
|
67
|
-
# get current backtrace, I'm happy to learn any more clever way
|
68
|
-
begin
|
69
|
-
raise "wat?!"
|
70
|
-
rescue Exception => e
|
71
|
-
backtrace = e.backtrace[1..-1]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
#TODO: silent rescues may not be optimal, for now they seem better than creating more mess
|
76
|
-
logger.error "\n\n\n#{Time.now}\n= #{error}\n#{backtrace.join("\n")}\n#{options[:params]}" rescue nil
|
77
|
-
|
78
|
-
ErrorLog::Model.create(
|
79
|
-
:error => error,
|
80
|
-
:backtrace => backtrace,
|
81
|
-
:level => level,
|
82
|
-
:params => options[:params],
|
83
|
-
:category => options[:category] || 'error_log'
|
84
|
-
) rescue nil
|
85
|
-
end
|
86
|
-
|
87
|
-
def self.logger
|
88
|
-
@logger = Logger.new(File.join(Rails.root,'log','error.log'))
|
89
|
-
end
|
90
|
-
|
91
70
|
end # module ErrorLog
|
92
71
|
|
93
72
|
|
94
73
|
ActiveSupport.on_load(:before_initialize) do
|
95
74
|
ErrorLog.require_all_libs_relative_to(__FILE__)
|
75
|
+
ErrorLog.init
|
96
76
|
end
|
data/views/index.html.haml
CHANGED
@@ -21,14 +21,29 @@
|
|
21
21
|
%table#error_logs_wrap
|
22
22
|
%tr
|
23
23
|
%td{:valign=>"top"}
|
24
|
+
|
25
|
+
- all_count = @category_counts.values.sum
|
24
26
|
%b Categories:
|
25
27
|
%ul
|
26
28
|
%li
|
27
|
-
= link_to_if @
|
28
|
-
(#{
|
29
|
+
= link_to_if @opts[:category], 'all', :action => :index, :category => '-none-'
|
30
|
+
(#{all_count})
|
29
31
|
- @category_counts.each_pair do |category,count|
|
30
32
|
%li
|
31
|
-
#{link_to_if (@
|
33
|
+
#{link_to_if (@opts[:category] != category), category, :action => :index, :category => category} (#{count})
|
34
|
+
|
35
|
+
- if @revisions.count > 1
|
36
|
+
%b Revisions:
|
37
|
+
%ul
|
38
|
+
%li
|
39
|
+
= link_to_if @opts[:revision], 'all', :action => :index, :revision => '-none-'
|
40
|
+
(#{all_count})
|
41
|
+
- @revisions.each do |rev|
|
42
|
+
%li{:style => 'white-space: nowrap'}
|
43
|
+
- name = rev.created_at_first.to_date.to_s + ' '
|
44
|
+
- name += (rev.vcs_revision.to_s.empty? ? 'unknown' : truncate(rev.vcs_revision,:length => 9))
|
45
|
+
|
46
|
+
#{link_to_if (@opts[:revision] != rev.vcs_revision.to_s), raw(name), :action => :index, :revision => rev.vcs_revision.to_s} (#{rev.count_all})
|
32
47
|
%br
|
33
48
|
%br
|
34
49
|
%br
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: error_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kacper Ciesla
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-20 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -47,11 +47,16 @@ files:
|
|
47
47
|
- lib/error_log/model.rb
|
48
48
|
- lib/error_log/controller.rb
|
49
49
|
- lib/error_log/core_ext.rb
|
50
|
+
- lib/error_log/class_methods.rb
|
50
51
|
- lib/error_log/migrations.rb
|
52
|
+
- lib/error_log/migrations/base.rb
|
53
|
+
- lib/error_log/migrations/add_params_column.rb
|
54
|
+
- lib/error_log/migrations/add_vcs_revision_column.rb
|
55
|
+
- lib/error_log/vcs.rb
|
51
56
|
- views/index.html.haml
|
52
57
|
- views/_styles.html.erb
|
53
58
|
- views/_error_log.html.haml
|
54
|
-
- README.
|
59
|
+
- README.rdoc
|
55
60
|
- Changelog.txt
|
56
61
|
has_rdoc: true
|
57
62
|
homepage:
|