logjam_agent 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -14,33 +14,39 @@ module LogjamAgent
|
|
14
14
|
@formatter = lambda{|_, _, _, message| message}
|
15
15
|
end
|
16
16
|
|
17
|
+
def request
|
18
|
+
Thread.current[:logjam_request]
|
19
|
+
end
|
20
|
+
|
21
|
+
def request=(request)
|
22
|
+
Thread.current[:logjam_request] = request
|
23
|
+
end
|
24
|
+
|
17
25
|
def start_request(app, env, initial_fields={})
|
18
|
-
|
26
|
+
self.request = Request.new(app, env, self, initial_fields)
|
19
27
|
end
|
20
28
|
|
21
29
|
def finish_request(additional_fields={})
|
22
|
-
# puts "finishing request"
|
23
30
|
if request = self.request
|
24
31
|
request.fields.merge!(additional_fields)
|
25
|
-
|
32
|
+
self.request = nil
|
26
33
|
request.forward
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
30
|
-
def request
|
31
|
-
Thread.current[:logjam_request]
|
32
|
-
end
|
33
|
-
|
34
37
|
def add(severity, message = nil, progname = nil, &block)
|
35
38
|
return if @level > severity
|
36
|
-
|
39
|
+
request = self.request
|
40
|
+
if message.is_a?(Exception)
|
41
|
+
request.add_exception(message) if request
|
42
|
+
message = format_exception(message)
|
43
|
+
else
|
44
|
+
message = (message || (block && block.call) || '').to_s
|
45
|
+
end
|
37
46
|
time = Time.now
|
38
47
|
buffer << formatter.call(severity, time, progname, message) << "\n"
|
39
48
|
auto_flush
|
40
|
-
|
41
|
-
# puts "adding line to request"
|
42
|
-
request.add_line(severity, time, message)
|
43
|
-
end
|
49
|
+
request.add_line(severity, time, message) if request
|
44
50
|
message
|
45
51
|
end
|
46
52
|
|
@@ -48,5 +54,17 @@ module LogjamAgent
|
|
48
54
|
raise "cannot connect logger to new log device" unless log_device.respond_to?(:write)
|
49
55
|
@log = log_device
|
50
56
|
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def format_exception(exception)
|
61
|
+
msg = "#{exception.class} : #{exception.message}"
|
62
|
+
if backtrace = exception.backtrace
|
63
|
+
backtrace = Rails.backtrace_cleaner.clean(backtrace, :all) if defined?(Rails)
|
64
|
+
msg << "\n #{backtrace.join("\n ")}"
|
65
|
+
else
|
66
|
+
msg
|
67
|
+
end
|
68
|
+
end
|
51
69
|
end
|
52
70
|
end
|
data/lib/logjam_agent/request.rb
CHANGED
@@ -18,9 +18,13 @@ module LogjamAgent
|
|
18
18
|
@lines << [severity, format_time(timestamp), message.strip]
|
19
19
|
end
|
20
20
|
|
21
|
+
def add_exception(exception)
|
22
|
+
((@fields[:exceptions] ||= []) << exception.class.to_s).uniq!
|
23
|
+
end
|
24
|
+
|
21
25
|
def forward
|
22
26
|
engine = @fields.delete(:engine)
|
23
|
-
@forwarder.
|
27
|
+
@forwarder.forward(@fields.to_json, engine)
|
24
28
|
rescue Exception => e
|
25
29
|
handle_forwarding_error(e)
|
26
30
|
end
|
@@ -29,7 +33,7 @@ module LogjamAgent
|
|
29
33
|
|
30
34
|
def format_time(t)
|
31
35
|
# iso time with microseconds
|
32
|
-
t.strftime("%Y-%m-%dT%H:%M:%S.#{t.usec}")
|
36
|
+
t.strftime("%Y-%m-%dT%H:%M:%S.#{"%06d" % t.usec}")
|
33
37
|
end
|
34
38
|
|
35
39
|
def handle_forwarding_error(exception)
|
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: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
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-
|
18
|
+
date: 2011-09-23 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|