logjam_agent 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/logjam_agent.rb +15 -5
- data/lib/logjam_agent/request.rb +1 -13
- data/lib/logjam_agent/version.rb +1 -1
- metadata +4 -4
data/lib/logjam_agent.rb
CHANGED
@@ -87,16 +87,26 @@ module LogjamAgent
|
|
87
87
|
EOS
|
88
88
|
end
|
89
89
|
|
90
|
+
# setup json encoding
|
91
|
+
begin
|
92
|
+
require "oj"
|
93
|
+
def self.encode_payload(data)
|
94
|
+
Oj.dump(data, :mode => :compat)
|
95
|
+
end
|
96
|
+
rescue LoadError
|
97
|
+
def self.encode_payload(data)
|
98
|
+
data.to_json
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
90
102
|
def self.event(label, extra_fields = {})
|
91
|
-
|
103
|
+
fields = {
|
92
104
|
:label => label,
|
93
105
|
:started_at => Time.now.iso8601,
|
94
106
|
:host => hostname
|
95
107
|
}
|
96
|
-
|
97
|
-
|
98
|
-
json_message = Oj.dump(logjam_fields, :format => :compat)
|
99
|
-
forwarder.forward(json_message, :routing_key => events_routing_key)
|
108
|
+
fields.merge!(extra_fields)
|
109
|
+
forwarder.forward(encode_payload(fields), :routing_key => events_routing_key)
|
100
110
|
end
|
101
111
|
|
102
112
|
private
|
data/lib/logjam_agent/request.rb
CHANGED
@@ -41,25 +41,13 @@ module LogjamAgent
|
|
41
41
|
|
42
42
|
def forward
|
43
43
|
engine = @fields.delete(:engine)
|
44
|
-
@forwarder.forward(encode_payload, :engine => engine)
|
44
|
+
@forwarder.forward(LogjamAgent.encode_payload(@fields), :engine => engine)
|
45
45
|
rescue Exception => e
|
46
46
|
handle_forwarding_error(e)
|
47
47
|
end
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
if defined?(Oj)
|
52
|
-
def encode_payload
|
53
|
-
Oj.dump(@fields, :mode => :compat)
|
54
|
-
rescue
|
55
|
-
@fields.to_json
|
56
|
-
end
|
57
|
-
else
|
58
|
-
def encode_payload
|
59
|
-
@fields.to_json
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
51
|
def format_time(t)
|
64
52
|
# iso time with microseconds
|
65
53
|
t.strftime("%Y-%m-%dT%H:%M:%S.#{"%06d" % t.usec}")
|
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: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 5
|
10
|
+
version: 0.6.5
|
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: 2013-
|
18
|
+
date: 2013-04-12 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|