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.
- data/lib/logjam_agent/buffered_logger.rb +36 -1
- data/lib/logjam_agent/request.rb +1 -1
- data/lib/logjam_agent/version.rb +1 -1
- metadata +3 -3
@@ -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
|
data/lib/logjam_agent/request.rb
CHANGED
data/lib/logjam_agent/version.rb
CHANGED
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:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Stefan Kaes
|