error_log 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.txt ADDED
@@ -0,0 +1,34 @@
1
+ error_log
2
+ by Kacper Ciesla (omboy)
3
+
4
+ == DESCRIPTION:
5
+
6
+ Easy way to track exceptions and warning in your rails app
7
+
8
+ It's still just a skeleton.
9
+ More description and documentation will come.. one day.. I guess.
10
+
11
+ == LICENSE:
12
+
13
+ (The MIT License)
14
+
15
+ Copyright (c) 2010 Kacper Ciesla
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining
18
+ a copy of this software and associated documentation files (the
19
+ 'Software'), to deal in the Software without restriction, including
20
+ without limitation the rights to use, copy, modify, merge, publish,
21
+ distribute, sublicense, and/or sell copies of the Software, and to
22
+ permit persons to whom the Software is furnished to do so, subject to
23
+ the following conditions:
24
+
25
+ The above copyright notice and this permission notice shall be
26
+ included in all copies or substantial portions of the Software.
27
+
28
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
29
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
31
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
32
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
33
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
34
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/error_log ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), %w[.. lib error_log]))
5
+
6
+ # Put your code here
7
+
@@ -0,0 +1,23 @@
1
+
2
+ #TODO :would be nice to check first if ApplicationController is defined and if not use ActionController::Base
3
+ module ErrorLog
4
+ class Controller < ActionController::Base
5
+
6
+ prepend_view_path File.join(ErrorLog.path,'views')
7
+
8
+ # FIXME: this layout declaration should not be needed here for default layout
9
+ # however without it, it does not load default layout for some reason
10
+ layout 'application'
11
+
12
+ def index
13
+ @error_logs = ErrorLog::Model.all(:order => 'created_at DESC', :conditions => {:viewed => false}).group_by(&:hash)
14
+ render :template => '/index'
15
+ end
16
+
17
+ def set_all_viewed
18
+ ErrorLog::Model.update_all(:viewed => true)
19
+ redirect_to :back
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,16 @@
1
+ class Object
2
+ def catch_error(category='catch_error', options={})
3
+ raise "no block given!" unless block_given?
4
+ begin
5
+ yield
6
+ return false
7
+ rescue Exception => e
8
+ ErrorLog::Model.create(
9
+ :error => e.to_str,
10
+ :backtrace => e.backtrace,
11
+ :category => category
12
+ )
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ require 'digest/md5'
2
+
3
+ module ErrorLog
4
+ class Model < ActiveRecord::Base
5
+
6
+ class Migration < ActiveRecord::Migration
7
+ def self.up
8
+ create_table :error_logs do |t|
9
+ t.text :error
10
+ t.text :backtrace
11
+ t.string :category
12
+ t.string :hash
13
+ t.integer :level_id
14
+ t.timestamp :created_at
15
+ t.boolean :viewed, :default => false
16
+ end
17
+ end
18
+ end
19
+
20
+ self.table_name = 'error_logs'
21
+ unless self.table_exists?
22
+ Migration.up
23
+ end
24
+
25
+ before_save do |obj|
26
+ if obj.backtrace.kind_of? Array
27
+ obj.backtrace = obj.backtrace.join("\n")
28
+ end
29
+
30
+ obj.hash = Digest::MD5.hexdigest(obj.backtrace.to_s + obj.error.to_s + obj.category.to_s)
31
+
32
+ true
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module ErrorLog
2
+ VERSION = "0.0.1" unless defined?(::ErrorLog::VERSION)
3
+ end
data/lib/error_log.rb ADDED
@@ -0,0 +1,68 @@
1
+
2
+ module ErrorLog
3
+
4
+ # :stopdoc:
5
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
+ # :startdoc:
8
+
9
+ # Returns the version string for the library.
10
+ #
11
+ def self.version
12
+ VERSION
13
+ end
14
+
15
+ # Returns the library path for the module. If any arguments are given,
16
+ # they will be joined to the end of the libray path using
17
+ # <tt>File.join</tt>.
18
+ #
19
+ def self.libpath( *args, &block )
20
+ rv = args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
21
+ if block
22
+ begin
23
+ $LOAD_PATH.unshift LIBPATH
24
+ rv = block.call
25
+ ensure
26
+ $LOAD_PATH.shift
27
+ end
28
+ end
29
+ return rv
30
+ end
31
+
32
+ # Returns the lpath for the module. If any arguments are given,
33
+ # they will be joined to the end of the path using
34
+ # <tt>File.join</tt>.
35
+ #
36
+ def self.path( *args, &block )
37
+ rv = args.empty? ? PATH : ::File.join(PATH, args.flatten)
38
+ if block
39
+ begin
40
+ $LOAD_PATH.unshift PATH
41
+ rv = block.call
42
+ ensure
43
+ $LOAD_PATH.shift
44
+ end
45
+ end
46
+ return rv
47
+ end
48
+
49
+ # Utility method used to require all files ending in .rb that lie in the
50
+ # directory below this file that has the same name as the filename passed
51
+ # in. Optionally, a specific _directory_ name can be passed in such that
52
+ # the _filename_ does not have to be equivalent to the directory.
53
+ #
54
+ def self.require_all_libs_relative_to( fname, dir = nil )
55
+ dir ||= ::File.basename(fname, '.*')
56
+ search_me = ::File.expand_path(
57
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
58
+
59
+ Dir.glob(search_me).sort.each {|rb| require rb}
60
+ end
61
+
62
+ end # module ErrorLog
63
+
64
+
65
+ # Hook into rails
66
+ ActiveSupport.on_load(:after_initialize) do
67
+ ErrorLog.require_all_libs_relative_to(__FILE__)
68
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: error_log
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Kacper Ciesla
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-08-06 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Who cares about description, nobody reads it anyway.
23
+ email:
24
+ - kacper.ciesla@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - bin/error_log
33
+ - lib/error_log.rb
34
+ - lib/error_log/version.rb
35
+ - lib/error_log/model.rb
36
+ - lib/error_log/controller.rb
37
+ - lib/error_log/core_ext.rb
38
+ - README.txt
39
+ has_rdoc: true
40
+ homepage:
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.7
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Easy way to handle errors and warnings in rails apps
73
+ test_files: []
74
+