errlog 0.1.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bbd26baa17726137322c3d5df046b9cbcdffd189
4
- data.tar.gz: d4cc1c6f7e80b69c68b35c3f2b616588ca6cbc52
3
+ metadata.gz: 6ed0cb0ec70f924ad34f237159636c0ab7c54b98
4
+ data.tar.gz: 1ba8e06be7edb9311ec15efbcc98f503a108b75f
5
5
  SHA512:
6
- metadata.gz: 8ff796221f1b57d49247a1905a8ca00abb2e55119fe574a0fbeb38a771f331bf2c496de08c49557122fbcdfffe44c3b29a06a82141aeca5d6c04d585e30480e0
7
- data.tar.gz: a74925cff35f45f5d496892413e64a2c28f83c04e91275e60b814d73a2c75c6b5270e2dd27aa55b5524ffca173dbfc9a41d982de05ce10c6ec19cbbe0fd478da
6
+ metadata.gz: 124b650da5d3e9fc1653407ca024177a2ec74a7515f5f5a2de6e2932e8e0ec9494298dda969f29b598fd58c4cbb83e6ce108d4c7982deb1db2af0f98d4bc9293
7
+ data.tar.gz: 9d0acde00ad38e9821024471f8dc4d785de77fa969b03dbf969d43172bcc77e9b82909285eaf93f6873f69ebba93cf15e787b175f2da9cefdb12aa4d975141ce
data/bin/errlogr CHANGED
@@ -11,7 +11,7 @@ Errlog reporting tool (visit http://errlog.com for details)
11
11
 
12
12
  Usage:
13
13
 
14
- errlog [params] "text to report"
14
+ errlogr [params] "text to report"
15
15
 
16
16
  Parameters
17
17
 
data/lib/errlog.rb CHANGED
@@ -9,6 +9,10 @@ require 'thread'
9
9
  require 'httpclient'
10
10
  require 'weakref'
11
11
 
12
+ if defined?(Rails)
13
+ require 'errlog/rails_controller_extensions'
14
+ end
15
+
12
16
  module Errlog
13
17
 
14
18
  include Errlog::Constants
@@ -22,6 +22,14 @@ module Errlog
22
22
  report "#{e.class.name}: #{e.to_s}", Errlog::ERROR
23
23
  end
24
24
 
25
+ def report_warning text, &block
26
+ report text, Errlog::WARNING, &block
27
+ end
28
+
29
+ def report_trace text, &block
30
+ report text, Errlog::TRACE, &block
31
+ end
32
+
25
33
  def report text, severity = Errlog::ERROR, &block
26
34
  raise 'Errlog is not configured. Use Errlog.config' unless Errlog.configured?
27
35
  !self.app_name and self.app_name = Errlog.app_name
@@ -0,0 +1,92 @@
1
+ module Errlog
2
+ module ControllerFilter
3
+
4
+ def self.included base
5
+ base.send :prepend_around_filter, :errlog_exceptions_trap
6
+ base.send :helper_method, :errlog_context
7
+ base.send :helper_method, :errlog_report
8
+ base.send :helper_method, :errlog_collect_context
9
+ base.send :helper_method, :errlog_exception
10
+ true
11
+ end
12
+
13
+ def errlog_context
14
+ @errlog_context || Errlog.clear_context
15
+ end
16
+
17
+ def errlog_exceptions_trap
18
+ ctx = @errlog_context = Errlog.clear_context
19
+
20
+ rl = Rails.logger = ctx.create_logger Rails.logger
21
+ acl = ActionController::Base.logger = ctx.create_logger ActionController::Base.logger
22
+ arl = nil
23
+ if defined?(ActiveRecord)
24
+ arl = ActiveRecord::Base.logger = ctx.create_logger ActiveRecord::Base.logger
25
+ end
26
+
27
+ yield
28
+
29
+ rescue Exception => e
30
+ errlog_collect_context ctx
31
+ ctx.report_exception e
32
+ raise
33
+
34
+ ensure
35
+ Rails.logger = rl.prev_logger
36
+ ActionController::Base.logger = acl.prev_logger
37
+ arl and ActiveRecord::Base.logger = arl.prev_logger
38
+ true
39
+ end
40
+
41
+ def errlog_exception e, context = nil
42
+ errlog_collect_context(context).report_exception e
43
+ end
44
+
45
+ def errlog_report text, severity = Errlog::ERROR, context=nil
46
+ errlog_collect_context(context).report text, severity
47
+ end
48
+
49
+ def errlog_collect_context ctx=nil
50
+ ctx ||= errlog_context
51
+ ctx.component = request.path
52
+ ctx.params = params
53
+ headers = {}
54
+ request.headers.to_hash.each { |k, v|
55
+ next if k =~ /cookie/i || v.class.name =~ /cookie/i
56
+ res = nil
57
+ case v
58
+ when Hash
59
+ res = {}
60
+ v.each { |k, v| res[k] = v.to_s }
61
+ when Array;
62
+ res = v.map &:to_s
63
+ #when StringIO, IO
64
+ # next
65
+ else
66
+ res = v.to_s
67
+ end
68
+ headers[k.to_s] = res
69
+ }
70
+ ctx.headers = headers
71
+ if respond_to?(:current_user)
72
+ ctx.current_user = if current_user
73
+ res = [current_user.id]
74
+ res << current_user.email if current_user.respond_to? :email
75
+ res << current_user.full_name if current_user.respond_to? :full_name
76
+ res
77
+ else
78
+ "not logged in"
79
+ end
80
+ end
81
+ ctx.url = request.url
82
+ ctx.remote_ip = request.remote_ip
83
+ if request.url =~ %r|^https?://(.+?)[/:]|
84
+ ctx.application = $1
85
+ end
86
+ ctx
87
+ end
88
+
89
+ end
90
+ end
91
+
92
+ ActionController::Base.send :include, Errlog::ControllerFilter
@@ -1,3 +1,3 @@
1
1
  module Errlog
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sergeych
@@ -102,6 +102,7 @@ files:
102
102
  - lib/errlog/constants.rb
103
103
  - lib/errlog/context.rb
104
104
  - lib/errlog/packager.rb
105
+ - lib/errlog/rails_controller_extensions.rb
105
106
  - lib/errlog/version.rb
106
107
  - spec/errlog_spec.rb
107
108
  - spec/packager_spec.rb