logjam_agent 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/logjam_agent.rb CHANGED
@@ -28,4 +28,39 @@ module LogjamAgent
28
28
 
29
29
  mattr_accessor :disabled
30
30
  self.disabled = false
31
+
32
+ mattr_accessor :exception_classes
33
+ self.exception_classes = []
34
+
35
+ mattr_accessor :exception_matcher
36
+ self.exception_matcher = nil
37
+
38
+ def self.auto_detect_exception(exception_class)
39
+ # ignore Exception classes created with Class.new (timeout.rb, my old friend)
40
+ if (class_name = exception_class.to_s) =~ /^[\w:]+$/
41
+ exception_classes << class_name unless exception_classes.include?(class_name)
42
+ end
43
+ end
44
+
45
+ def self.reset_exception_matcher
46
+ self.exception_matcher = Regexp.new(self.exception_classes.map{|e| Regexp.escape(e)}.join("|"))
47
+ end
48
+
49
+ def self.determine_loaded_exception_classes
50
+ ObjectSpace.each_object(Class) do |klass|
51
+ auto_detect_exception(klass) if klass < Exception
52
+ end
53
+ reset_exception_matcher
54
+ end
55
+
56
+ def self.auto_detect_logged_exceptions
57
+ determine_loaded_exception_classes
58
+ Exception.class_eval <<-"EOS"
59
+ def self.inherited(subclass)
60
+ ::LogjamAgent.auto_detect_exception(subclass)
61
+ ::LogjamAgent.reset_exception_matcher
62
+ end
63
+ EOS
64
+ end
65
+
31
66
  end
@@ -42,8 +42,8 @@ module LogjamAgent
42
42
  message = format_exception(message)
43
43
  else
44
44
  message = (message || (block && block.call) || '').to_s
45
- if request && severity >= Logger::ERROR && (ex = detect_logged_exception(message))
46
- request.add_exception(ex)
45
+ if request && severity >= Logger::ERROR && (e = detect_logged_exception(message))
46
+ request.add_exception(e)
47
47
  end
48
48
  end
49
49
  time = Time.now
@@ -58,48 +58,17 @@ module LogjamAgent
58
58
  @log = log_device
59
59
  end
60
60
 
61
- @@exception_classes = []
62
- def self.auto_detect_exception(exception_class)
63
- # but ignore Exception classes created with Class.new (timeout.rb, my old friend)
64
- if (class_name = exception_class.to_s) =~ /^[\w:]+$/
65
- @@exception_classes << class_name
66
- end
67
- end
68
-
69
- @@exception_matcher = nil
70
- def self.reset_exception_matcher
71
- @@exception_matcher = Regexp.new(@@exception_classes.map{|e| Regexp.escape(e)}.join("|"))
72
- end
73
-
74
- def self.auto_detect_logged_exceptions
75
- determine_loaded_exception_classes
76
- Exception.class_eval <<-"EOS"
77
- def self.inherited(subclass)
78
- logger_class = ::LogjamAgent::BufferedLogger
79
- logger_class.auto_detect_exception(subclass)
80
- logger_class.reset_exception_matcher
81
- end
82
- EOS
83
- end
84
-
85
61
  private
86
62
 
87
63
  def detect_logged_exception(message)
88
- (matcher = @@exception_matcher) && message[matcher]
89
- end
90
-
91
- def self.determine_loaded_exception_classes
92
- ObjectSpace.each_object(Class) do |klass|
93
- auto_detect_exception(klass) if klass < Exception
94
- end
95
- reset_exception_matcher
64
+ (matcher = LogjamAgent.exception_matcher) && message[matcher]
96
65
  end
97
66
 
98
67
  def format_exception(exception)
99
- msg = "#{exception.class} : #{exception.message}"
68
+ msg = "#{exception.class} (#{exception.message})"
100
69
  if backtrace = exception.backtrace
101
70
  backtrace = Rails.backtrace_cleaner.clean(backtrace, :all) if defined?(Rails)
102
- msg << "\n #{backtrace.join("\n ")}"
71
+ msg << ":\n #{backtrace.join("\n ")}"
103
72
  else
104
73
  msg
105
74
  end
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logjam_agent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stefan Kaes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-24 00:00:00 +02:00
18
+ date: 2011-09-25 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency