imprint 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,12 +4,10 @@ module Imprint
4
4
  # Not relying on default rails logging, more often using lograge
5
5
  # Still want to log incoming params safely, which lograge doesn't include
6
6
  # this does the same sensative param filtering as rails defaults
7
- # it also allows injecting some other variables useful for tracing logs
8
7
  def log_entrypoint
9
8
  raise "you must call Imprint.configuration and configure the gem before using LogHelpers" if Imprint.configuration.nil?
10
9
  log_filter = ActionDispatch::Http::ParameterFilter.new(Imprint.configuration[:log_filters] || Rails.application.config.filter_parameters)
11
10
  header_blacklist = Imprint.configuration[:header_blacklist] || []
12
- variables_to_append = Imprint.configuration[:variables_to_append] || []
13
11
  cookies_whitelist = Imprint.configuration[:cookies_whitelist] || []
14
12
 
15
13
  http_request_headers = request.headers.select{|header_name, header_value| header_name.match("^HTTP.*") && !header_blacklist.include?(header_name) }
@@ -21,20 +19,14 @@ module Imprint
21
19
  end
22
20
 
23
21
  data_append << " params: "
24
- log_filter.filter(params).each_pair{|k,v| data_append << " #{k}=\"#{v}\"" }
25
-
26
- variables_to_append.each do |var|
27
- var_val = self.instance_variable_get("@#{var}".to_sym).try(:id)
28
- var_val ||= 'nil'
29
- data_append << " #{var}_id=\"#{var_val}\""
30
- end
22
+ log_filter.filter(request.query_parameters).each_pair{|k,v| data_append << " #{k}=\"#{v}\"" }
31
23
 
32
24
  cookies_whitelist.each do |cookie_key|
33
25
  cookie_val = cookies[cookie_key] ? cookies[cookie_key] : 'nil'
34
26
  data_append << " #{cookie_key}=\"#{cookie_val}\""
35
27
  end
36
28
 
37
- logger.info "Started request_method=#{request.method.inspect} request_url=\"#{request.url.inspect}\" at request_time=\"#{Time.now.to_default_s}\" request_ip=#{request.remote_ip.inspect} #{data_append}"
29
+ logger.info "Started request_method=#{request.method.inspect} request_url=\"#{request.path}\" request_time=\"#{Time.now.to_default_s}\" request_ip=#{request.remote_ip.inspect} #{data_append}"
38
30
  rescue
39
31
  logger.error "error logging log_entrypoint for request"
40
32
  end
@@ -10,8 +10,8 @@ if defined?(ActiveSupport::BufferedLogger)
10
10
  # If a newline is necessary then create a new message ending with a newline.
11
11
  # Ensures that the original message is not mutated.
12
12
  message = "#{message}\n" unless message[-1] == "\n"
13
- if (defined?(Imprint::Tracer)) && message && message.is_a?(String) && message.length > 1 && Imprint::Tracer.get_trace_id
14
- message = message.gsub("\n"," [trace_id=#{Imprint::Tracer.get_trace_id}]\n")
13
+ if (defined?(Imprint::Tracer)) && message && message.is_a?(String) && message.length > 1 && Imprint::Tracer.get_trace_id && !message.include?('trace_id=')
14
+ message = message.gsub("\n"," trace_id=#{Imprint::Tracer.get_trace_id}\n")
15
15
  end
16
16
  buffer << message
17
17
  auto_flush
@@ -24,7 +24,7 @@ if defined?(ActiveSupport::BufferedLogger)
24
24
  # Ensures that the original message is not mutated.
25
25
  message = "#{message}\n" unless message[-1] == "\n"
26
26
  if (defined?(Imprint::Tracer)) && message && message.is_a?(String) && message.length > 1 && Imprint::Tracer.get_trace_id && !message.include?('trace_id=')
27
- message = message.gsub("\n"," [trace_id=#{Imprint::Tracer.get_trace_id}]\n")
27
+ message = message.gsub("\n"," trace_id=#{Imprint::Tracer.get_trace_id}\n")
28
28
  end
29
29
  @log.add(severity, message, progname, &block)
30
30
  end
@@ -43,7 +43,7 @@ if defined?(ActiveSupport::Logger::SimpleFormatter)
43
43
  # Ensures that the original message is not mutated.
44
44
  message = "#{message}\n" unless message[-1] == "\n"
45
45
  if (defined?(Imprint::Tracer)) && message && message.is_a?(String) && message.length > 1 && Imprint::Tracer.get_trace_id && !message.include?('trace_id=')
46
- message = message.gsub("\n"," [trace_id=#{Imprint::Tracer.get_trace_id}]\n")
46
+ message = message.gsub("\n"," trace_id=#{Imprint::Tracer.get_trace_id}\n")
47
47
  end
48
48
  message
49
49
  end
@@ -1,3 +1,3 @@
1
1
  module Imprint
2
- VERSION = "1.1.5"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -62,15 +62,19 @@ class LogHelpersTest < Test::Unit::TestCase
62
62
  ''
63
63
  end
64
64
 
65
+ def request.path
66
+ ''
67
+ end
68
+
65
69
  def request.remote_ip
66
70
  ''
67
71
  end
68
72
 
69
- request
70
- end
73
+ def request.query_parameters
74
+ {}
75
+ end
71
76
 
72
- def params
73
- {}
77
+ request
74
78
  end
75
79
 
76
80
  def stub_rails
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imprint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.5
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-28 00:00:00.000000000 Z
12
+ date: 2014-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  segments:
149
149
  - 0
150
- hash: 4420321569846472065
150
+ hash: 1212060812570549601
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements:
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  segments:
158
158
  - 0
159
- hash: 4420321569846472065
159
+ hash: 1212060812570549601
160
160
  requirements: []
161
161
  rubyforge_project:
162
162
  rubygems_version: 1.8.23