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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2EwNGYwYTRhN2YzZDAwYTE0YjJiOTcwYTQ4NWJmNGM0MmM2NjM0OQ==
4
+ YTkzZmVmY2Q4NDkxNzQwNmNhYWRmMzBjOTQ3YmJlYWRhNzU4ZjQ0Yg==
5
5
  data.tar.gz: !binary |-
6
- OTFmNzM1ZWI4MjcwOTRhYWI2ZDYwNWU4YmYzMjlkOTMwYjg4NTU4NA==
6
+ NTdjOTg3MGQ5MTI0NWVmN2RlYjllMTViZTVkOWNjNzUzM2E5Njg0Mg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NDEwODU1ZjdlMjEwNjg3MDU1ZDhhYzVlY2ZkYmE3ZWQ0ZTUxNjU4MzYwMDk2
10
- MTVjYTA0ZGY0YjdmYThjMDVkZjk1YWQxNWU0ZDRhNzVjZmY5NmZkMDBmMjg0
11
- MzEwNTNjZDkwZTI1NWNmMDE4OTljYWMwNjc5MDRhOTkwMWJlMjA=
9
+ YjE2YWMxZGY0N2RmNjcxMTliYzg1NDdjNTU2N2U3MDFmYzljYWU5YmJhNzcy
10
+ YWM4MjhjZmYwOTg5NDZhNWM1OTk0ZWRhZjY1YzlkZmQwOTM3ZDZkYzUwNDU1
11
+ OGNhMDMxNmM1MmM1NDhhYTczNTc3NmI3ZjQyZmRhYzNmMTlkZjM=
12
12
  data.tar.gz: !binary |-
13
- ZGJmZTA1OTE4MjI2NzU1OTU0Zjk0NzUxNDZlOWU5ZWNmYmMwNmFlMDc4ZmY0
14
- ODAxNTQyNjhiY2VkNTliNzU1ZDliYzUxODAxNmFkYjMyM2Y0MzFkNzQ1YzVi
15
- NDQ5MDJlNDdiMjkyYWU1NDVjODJmMTM4ZTFiN2Y0YWUzYjA4OWE=
13
+ MzdjMDlmZTRiM2FmY2Y4MTFjMTM0ZmFjMjdjZjRjNWQwNTkzOTE4YTgwNzgy
14
+ YWVhZDUzYmMzNmU1MmU0ZjU1NDk2ZmQwMjgxOTg1YTQ1ZDgwMzg3YTRjODdm
15
+ MjUyM2RmZWZkMzUzZTg2ZTUwOGUyM2I4ZjQ1ZTNiNTc2MWQzNWY=
@@ -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 = self.request || Thread.main.thread_variable_get(:logjam_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
- Rails.logger.start_request(app_name, env_name, :caller_id => caller_id, :caller_action => caller_action)
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
- Rails.logger.finish_request(env["time_bandits.metrics"])
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
- Rails.logger.request.uuid
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 = Rails.logger.request.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
- Rails.logger.request.fields.merge!(request_info)
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
- Rails.logger.request.fields[:action] = action_name
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
- Rails.logger.request.fields[:action] = action_name
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
- Rails.logger.request.fields[:action] = action_name
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?
@@ -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
 
@@ -8,8 +8,7 @@ module LogjamAgent
8
8
  class Request
9
9
  attr_reader :fields, :uuid
10
10
 
11
- def initialize(app, env, logger, initial_fields)
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
- @logger.error exception.to_s
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
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.7.3"
2
+ VERSION = "0.8.0"
3
3
  end
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.7.3
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-24 00:00:00.000000000 Z
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