logjam_agent 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/logjam_agent.rb +29 -0
- data/lib/logjam_agent/buffered_logger.rb +4 -21
- data/lib/logjam_agent/middleware.rb +2 -2
- data/lib/logjam_agent/rack/logger.rb +6 -6
- data/lib/logjam_agent/railtie.rb +19 -0
- data/lib/logjam_agent/request.rb +2 -3
- data/lib/logjam_agent/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTkzZmVmY2Q4NDkxNzQwNmNhYWRmMzBjOTQ3YmJlYWRhNzU4ZjQ0Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTdjOTg3MGQ5MTI0NWVmN2RlYjllMTViZTVkOWNjNzUzM2E5Njg0Mg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjE2YWMxZGY0N2RmNjcxMTliYzg1NDdjNTU2N2U3MDFmYzljYWU5YmJhNzcy
|
10
|
+
YWM4MjhjZmYwOTg5NDZhNWM1OTk0ZWRhZjY1YzlkZmQwOTM3ZDZkYzUwNDU1
|
11
|
+
OGNhMDMxNmM1MmM1NDhhYTczNTc3NmI3ZjQyZmRhYzNmMTlkZjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzdjMDlmZTRiM2FmY2Y4MTFjMTM0ZmFjMjdjZjRjNWQwNTkzOTE4YTgwNzgy
|
14
|
+
YWVhZDUzYmMzNmU1MmU0ZjU1NDk2ZmQwMjgxOTg1YTQ1ZDgwMzg3YTRjODdm
|
15
|
+
MjUyM2RmZWZkMzUzZTg2ZTUwOGUyM2I4ZjQ1ZTNiNTc2MWQzNWY=
|
data/lib/logjam_agent.rb
CHANGED
@@ -2,6 +2,30 @@ require "socket"
|
|
2
2
|
require "uuid4r"
|
3
3
|
require "time_bandits"
|
4
4
|
|
5
|
+
module LogjamAgent
|
6
|
+
module RequestHandling
|
7
|
+
def request
|
8
|
+
Thread.current.thread_variable_get(:logjam_request)
|
9
|
+
end
|
10
|
+
|
11
|
+
def request=(request)
|
12
|
+
Thread.current.thread_variable_set(:logjam_request, request)
|
13
|
+
end
|
14
|
+
|
15
|
+
def start_request(app = LogjamAgent.application_name, env = LogjamAgent.environment_name, initial_fields = {})
|
16
|
+
self.request = Request.new(app, env, initial_fields)
|
17
|
+
end
|
18
|
+
|
19
|
+
def finish_request(additional_fields = {})
|
20
|
+
if request = self.request
|
21
|
+
request.fields.merge!(additional_fields)
|
22
|
+
self.request = nil
|
23
|
+
request.forward
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
5
29
|
require "logjam_agent/version"
|
6
30
|
require "logjam_agent/amqp_forwarder"
|
7
31
|
require "logjam_agent/zmq_forwarder"
|
@@ -18,6 +42,9 @@ module LogjamAgent
|
|
18
42
|
|
19
43
|
class ForwardingError < StandardError; end
|
20
44
|
|
45
|
+
mattr_accessor :logger
|
46
|
+
self.logger = nil
|
47
|
+
|
21
48
|
mattr_accessor :error_handler
|
22
49
|
self.error_handler = lambda { |exception| }
|
23
50
|
|
@@ -53,6 +80,8 @@ module LogjamAgent
|
|
53
80
|
mattr_accessor :disabled
|
54
81
|
self.disabled = false
|
55
82
|
|
83
|
+
extend RequestHandling
|
84
|
+
|
56
85
|
mattr_accessor :exception_classes
|
57
86
|
self.exception_classes = []
|
58
87
|
|
@@ -52,6 +52,9 @@ module LogjamAgent
|
|
52
52
|
|
53
53
|
attr_accessor :formatter
|
54
54
|
|
55
|
+
# for backwards compatibility. needs to go away.
|
56
|
+
include LogjamAgent::RequestHandling
|
57
|
+
|
55
58
|
def initialize(*args)
|
56
59
|
super(*args)
|
57
60
|
# stupid bug in the buffered logger code (Rails::VERSION::STRING < "3.2")
|
@@ -59,32 +62,12 @@ module LogjamAgent
|
|
59
62
|
@formatter = lambda{|_, _, _, message| message}
|
60
63
|
end
|
61
64
|
|
62
|
-
def request
|
63
|
-
Thread.current.thread_variable_get(:logjam_request)
|
64
|
-
end
|
65
|
-
|
66
|
-
def request=(request)
|
67
|
-
Thread.current.thread_variable_set(:logjam_request, request)
|
68
|
-
end
|
69
|
-
|
70
|
-
def start_request(app, env, initial_fields={})
|
71
|
-
self.request = Request.new(app, env, self, initial_fields)
|
72
|
-
end
|
73
|
-
|
74
|
-
def finish_request(additional_fields={})
|
75
|
-
if request = self.request
|
76
|
-
request.fields.merge!(additional_fields)
|
77
|
-
self.request = nil
|
78
|
-
request.forward
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
65
|
def add(severity, message = nil, progname = nil, tags_text = nil, &block)
|
83
66
|
return if level > severity
|
84
67
|
message = progname if message.nil?
|
85
68
|
progname = nil
|
86
69
|
message ||= block.call || '' if block
|
87
|
-
request =
|
70
|
+
request = LogjamAgent.request
|
88
71
|
if message.is_a?(Exception)
|
89
72
|
request.add_exception(message.class.to_s) if request
|
90
73
|
message = format_exception(message)
|
@@ -28,11 +28,11 @@ module LogjamAgent
|
|
28
28
|
env_name = env["logjam_agent.environment_name"] || LogjamAgent.environment_name
|
29
29
|
caller_id = env["HTTP_X_LOGJAM_CALLER_ID"] || ""
|
30
30
|
caller_action = env["HTTP_X_LOGJAM_ACTION"] || ""
|
31
|
-
|
31
|
+
LogjamAgent.start_request(app_name, env_name, :caller_id => caller_id, :caller_action => caller_action)
|
32
32
|
end
|
33
33
|
|
34
34
|
def finish_request(env)
|
35
|
-
|
35
|
+
LogjamAgent.finish_request(env["time_bandits.metrics"])
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -35,7 +35,7 @@ module LogjamAgent
|
|
35
35
|
@taggers.collect do |tag|
|
36
36
|
case tag
|
37
37
|
when :uuid
|
38
|
-
|
38
|
+
LogjamAgent.request.uuid
|
39
39
|
when Proc
|
40
40
|
tag.call(request)
|
41
41
|
when Symbol
|
@@ -52,7 +52,7 @@ module LogjamAgent
|
|
52
52
|
|
53
53
|
path = request.filtered_path
|
54
54
|
|
55
|
-
logjam_fields =
|
55
|
+
logjam_fields = LogjamAgent.request.fields
|
56
56
|
logjam_fields.merge!(:started_at => start_time.iso8601, :ip => request.remote_ip, :host => @hostname)
|
57
57
|
logjam_fields.merge!(extract_request_info(request))
|
58
58
|
|
@@ -77,7 +77,7 @@ module LogjamAgent
|
|
77
77
|
|
78
78
|
ActiveSupport::LogSubscriber.flush_all!
|
79
79
|
|
80
|
-
|
80
|
+
LogjamAgent.request.fields.merge!(request_info)
|
81
81
|
|
82
82
|
env["time_bandits.metrics"] = TimeBandits.metrics
|
83
83
|
end
|
@@ -163,7 +163,7 @@ module ActionController #:nodoc:
|
|
163
163
|
full_name = "#{controller}##{action}"
|
164
164
|
action_name = LogjamAgent.action_name_proc.call(full_name)
|
165
165
|
|
166
|
-
|
166
|
+
LogjamAgent.request.fields[:action] = action_name
|
167
167
|
|
168
168
|
info " Processing by #{full_name} as #{payload[:formats].first.to_s.upcase}"
|
169
169
|
info " Parameters: #{params.inspect}" unless params.empty?
|
@@ -182,7 +182,7 @@ module ActionController #:nodoc:
|
|
182
182
|
full_name = "#{controller}##{action}"
|
183
183
|
action_name = LogjamAgent.action_name_proc.call(full_name)
|
184
184
|
|
185
|
-
|
185
|
+
LogjamAgent.request.fields[:action] = action_name
|
186
186
|
|
187
187
|
info " Processing by #{full_name} as #{format}"
|
188
188
|
info " Parameters: #{params.inspect}" unless params.empty?
|
@@ -201,7 +201,7 @@ module ActionController #:nodoc:
|
|
201
201
|
full_name = "#{controller}##{action}"
|
202
202
|
action_name = LogjamAgent.action_name_proc.call(full_name)
|
203
203
|
|
204
|
-
|
204
|
+
LogjamAgent.request.fields[:action] = action_name
|
205
205
|
|
206
206
|
info "Processing by #{full_name} as #{format}"
|
207
207
|
info " Parameters: #{params.inspect}" unless params.empty?
|
data/lib/logjam_agent/railtie.rb
CHANGED
@@ -19,10 +19,12 @@ module LogjamAgent
|
|
19
19
|
logger.formatter = LogjamAgent::SyslogLikeFormatter.new
|
20
20
|
logger.auto_flushing = false if Rails.env.production? && Rails::VERSION::STRING < "3.2"
|
21
21
|
logger = ActiveSupport::TaggedLogging.new(logger) if Rails::VERSION::STRING >= "3.2"
|
22
|
+
LogjamAgent.logger = logger
|
22
23
|
logger
|
23
24
|
rescue StandardError
|
24
25
|
logger = LogjamAgent::BufferedLogger.new(STDERR)
|
25
26
|
logger = ActiveSupport::TaggedLogging.new(logger) if Rails::VERSION::STRING >= "3.2"
|
27
|
+
LogjamAgent.logger = logger
|
26
28
|
logger.level = ::Logger::WARN
|
27
29
|
logger.warn(
|
28
30
|
"Logging Error: Unable to access log file. Please ensure that #{path} exists and is writable. " +
|
@@ -38,6 +40,22 @@ module LogjamAgent
|
|
38
40
|
initializer "logjam_agent", :after => "time_bandits" do |app|
|
39
41
|
app.config.middleware.swap("TimeBandits::Rack::Logger", "LogjamAgent::Rack::Logger")
|
40
42
|
app.config.middleware.insert_before("LogjamAgent::Rack::Logger", "LogjamAgent::Middleware")
|
43
|
+
|
44
|
+
# patch controller testing to create a logjam request, because middlewares aren't executed
|
45
|
+
if Rails.env.test?
|
46
|
+
ActiveSupport.on_load(:action_controller) do
|
47
|
+
require 'action_controller/test_case'
|
48
|
+
module ActionController::TestCase::Behavior
|
49
|
+
def process_with_logjam(*args)
|
50
|
+
LogjamAgent.start_request
|
51
|
+
process_without_logjam(*args)
|
52
|
+
ensure
|
53
|
+
LogjamAgent.finish_request
|
54
|
+
end
|
55
|
+
alias_method_chain :process, :logjam
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
41
59
|
end
|
42
60
|
|
43
61
|
# make
|
@@ -53,6 +71,7 @@ module LogjamAgent
|
|
53
71
|
end
|
54
72
|
EVA
|
55
73
|
end
|
74
|
+
|
56
75
|
end
|
57
76
|
end
|
58
77
|
|
data/lib/logjam_agent/request.rb
CHANGED
@@ -8,8 +8,7 @@ module LogjamAgent
|
|
8
8
|
class Request
|
9
9
|
attr_reader :fields, :uuid
|
10
10
|
|
11
|
-
def initialize(app, env,
|
12
|
-
@logger = logger
|
11
|
+
def initialize(app, env, initial_fields)
|
13
12
|
@app = app
|
14
13
|
@env = env
|
15
14
|
@forwarder = Forwarders.get(app, env)
|
@@ -63,7 +62,7 @@ module LogjamAgent
|
|
63
62
|
end
|
64
63
|
|
65
64
|
def handle_forwarding_error(exception)
|
66
|
-
|
65
|
+
LogjamAgent.logger.error exception.to_s if LogjamAgent.logger
|
67
66
|
LogjamAgent.error_handler.call(exception)
|
68
67
|
rescue Exception
|
69
68
|
# swallow all exceptions
|
data/lib/logjam_agent/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logjam_agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|