logjam_agent 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,10 +38,13 @@ module LogjamAgent
38
38
  return if @level > severity
39
39
  request = self.request
40
40
  if message.is_a?(Exception)
41
- request.add_exception(message) if request
41
+ request.add_exception(message.class.to_s) if request
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)
47
+ end
45
48
  end
46
49
  time = Time.now
47
50
  buffer << formatter.call(severity, time, progname, message) << "\n"
@@ -55,8 +58,40 @@ module LogjamAgent
55
58
  @log = log_device
56
59
  end
57
60
 
61
+ @@exception_classes = []
62
+ def self.auto_detect_exception(exception_class)
63
+ @@exception_classes << exception_class.to_s
64
+ end
65
+
66
+ @@exception_matcher = nil
67
+ def self.reset_exception_matcher
68
+ @@exception_matcher = Regexp.new(@@exception_classes.map{|e| Regexp.escape(e)}.join("|"))
69
+ end
70
+
71
+ def self.auto_detect_logged_exceptions
72
+ determine_loaded_exception_classes
73
+ Exception.class_eval <<-"EOS"
74
+ def self.inherited(subclass)
75
+ logger_class = ::LogjamAgent::BufferedLogger
76
+ logger_class.auto_detect_exception(subclass)
77
+ logger_class.reset_exception_matcher
78
+ end
79
+ EOS
80
+ end
81
+
58
82
  private
59
83
 
84
+ def detect_logged_exception(message)
85
+ matcher = @@exception_matcher && message[matcher]
86
+ end
87
+
88
+ def self.determine_loaded_exception_classes
89
+ ObjectSpace.each_object(Class) do |klass|
90
+ auto_detect_exception(klass) if klass < Exception
91
+ end
92
+ reset_exception_matcher
93
+ end
94
+
60
95
  def format_exception(exception)
61
96
  msg = "#{exception.class} : #{exception.message}"
62
97
  if backtrace = exception.backtrace
@@ -19,7 +19,7 @@ module LogjamAgent
19
19
  end
20
20
 
21
21
  def add_exception(exception)
22
- ((@fields[:exceptions] ||= []) << exception.class.to_s).uniq!
22
+ ((@fields[:exceptions] ||= []) << exception).uniq!
23
23
  end
24
24
 
25
25
  def forward
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stefan Kaes