rails_semantic_logger 4.1.1 → 4.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cdd33618927fbb42d25eebd261c682dc05a9408
4
- data.tar.gz: 69e28c6b4ca5dc2d33b970af7fd38733bf50e12d
3
+ metadata.gz: 4a7c538cec8c358c81939c54ff8db6ce47e1ca46
4
+ data.tar.gz: 9eeb2407f8157458f9dcbf2db5577a06140df5a8
5
5
  SHA512:
6
- metadata.gz: 8fc1e2d4a6724bfc0640b10b7a33340d53feed9acd06ac7ca515031d25043128c82fd43f64e0eae4ac9844716af83adae05d7fe17047eb6ccfe170943d70db7b
7
- data.tar.gz: 331526a71a7c1f4341f17eb2da10223a6484faf0dcf1e02cf05742b960d257b270a13d4ddbdaca4c4cfc8a41d7e8503af9c00cb4bfad6321a296f8d452c4d7ee
6
+ metadata.gz: f2b620e2153ed6201c4c84434fe8e94d41fa1635dd414cd23b669b4258b5a4fc2cefddce129ab415976587ef9abdd53e6594d97c8e07f98be8fd2659d71fc4a2
7
+ data.tar.gz: 3aaeb1cd8136eeb906051a41ad45ce2d709bb46cf3c458f4fb520c9548f3de82898bf67eae8a32992b12b13de650b0d97ecbb9872311ee150640a66a6c5fc32d
@@ -56,18 +56,44 @@ module RailsSemanticLogger
56
56
  # Silence asset logging
57
57
  config.rails_semantic_logger.quiet_assets = false
58
58
 
59
- # Hash of named tags.
60
- # Use in a similar fashion to the Rails config.log_tags, except that it is now a hash.
59
+ # Override the output format for the primary Rails log file.
61
60
  #
62
- # Example:
63
- # config.rails_semantic_logger.named_tags = {
64
- # request_id: :request_id,
65
- # ip: :remote_ip,
66
- # user: -> request { request.cookie_jar['login'] }
67
- # }
61
+ # Valid options:
62
+ # * :default
63
+ # Plain text output with no color.
64
+ # * :color
65
+ # Plain text output with color.
66
+ # * :json
67
+ # JSON output format.
68
+ # * class
68
69
  #
69
- # Notes:
70
- # - Nil Values are ignored and will be left out of the named tags.
70
+ # * Proc
71
+ # A block that will be called to format the output.
72
+ # It is supplied with the `log` entry and should return the formatted data.
73
+ #
74
+ # Note:
75
+ # * `:default` is automatically changed to `:color` if `config.colorize_logging` is `true`.
76
+ #
77
+ # JSON Example, in `application.rb`:
78
+ #
79
+ # config.rails_semantic_logger.format = :json
80
+ #
81
+ # Custom Example, create `app/lib/my_formatter.rb`:
82
+ #
83
+ # # My Custom colorized formatter
84
+ # class MyFormatter < SemanticLogger::Formatters::Color
85
+ # # Return the complete log level name in uppercase
86
+ # def level
87
+ # "#{color}log.level.upcase#{color_map.clear}"
88
+ # end
89
+ # end
90
+ #
91
+ # # In application.rb:
92
+ # config.rails_semantic_logger.format = MyFormatter.new
93
+ config.rails_semantic_logger.format = :default
94
+
95
+ # DEPRECATED
96
+ # Instead, supply a Hash to config.log_tags
71
97
  config.rails_semantic_logger.named_tags = nil
72
98
 
73
99
  # Initialize SemanticLogger. In a Rails environment it will automatically
@@ -93,7 +119,8 @@ module RailsSemanticLogger
93
119
  # Add the log file to the list of appenders
94
120
  # Use the colorized formatter if Rails colorized logs are enabled
95
121
  ap_options = config.rails_semantic_logger.ap_options
96
- formatter = config.colorize_logging == false ? SemanticLogger::Formatters::Default.new : SemanticLogger::Formatters::Color.new(ap: ap_options)
122
+ formatter = config.rails_semantic_logger.format
123
+ formatter = SemanticLogger::Formatters::Color.new(ap: ap_options) if (formatter == :default) && (config.colorize_logging != false)
97
124
 
98
125
  # Set internal logger to log to file only, in case another appender experiences errors during writes
99
126
  appender = SemanticLogger::Appender::File.new(file_name: path, level: config.log_level, formatter: formatter)
@@ -209,8 +236,9 @@ module RailsSemanticLogger
209
236
  require('rails_semantic_logger/extensions/action_controller/log_subscriber_processing') if defined?(ActionView::LogSubscriber)
210
237
  end
211
238
 
212
- if config.rails_semantic_logger.named_tags && defined?(Rails::Rack::Logger)
213
- Rails::Rack::Logger.named_tags = config.rails_semantic_logger.named_tags
239
+ # Backward compatibility
240
+ if config.rails_semantic_logger.named_tags
241
+ config.log_tags = config.rails_semantic_logger.named_tags
214
242
  end
215
243
  end
216
244
 
@@ -11,26 +11,25 @@ module ActiveRecord
11
11
  return if IGNORE_PAYLOAD_NAMES.include?(name)
12
12
 
13
13
  log_payload = {
14
- sql: payload[:sql],
14
+ sql: payload[:sql],
15
15
  }
16
- log = {
16
+ log = {
17
17
  message: name,
18
18
  payload: log_payload,
19
19
  duration: event.duration
20
20
  }
21
21
  unless (payload[:binds] || []).empty?
22
22
  log_payload[:binds] = binds = {}
23
- # Changed with Rails 5
24
- if Rails.version.to_f >= 5.1
25
- casted_params = type_casted_binds(payload[:binds], payload[:type_casted_binds])
26
- payload[:binds].zip(casted_params).map { |attr, value|
27
- render_bind(attr, value)
28
- }
29
- elsif Rails.version.to_i >= 5
23
+ if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 0 && Rails::VERSION::TINY <= 2
30
24
  payload[:binds].each do |attr|
31
25
  attr_name, value = render_bind(attr)
32
26
  binds[attr_name] = value
33
27
  end
28
+ elsif Rails::VERSION::MAJOR >= 5
29
+ casted_params = type_casted_binds(payload[:binds], payload[:type_casted_binds])
30
+ payload[:binds].zip(casted_params).map { |attr, value|
31
+ render_bind(attr, value)
32
+ }
34
33
  else
35
34
  payload[:binds].each do |col, v|
36
35
  attr_name, value = render_bind(col, v)
@@ -4,8 +4,6 @@ Rails::Rack::Logger
4
4
  module Rails
5
5
  module Rack
6
6
  class Logger
7
- mattr_accessor :named_tags
8
-
9
7
  @logger = SemanticLogger['Rack']
10
8
 
11
9
  def self.logger
@@ -15,9 +13,13 @@ module Rails
15
13
  def call(env)
16
14
  request = ActionDispatch::Request.new(env)
17
15
 
18
- proc = -> { call_app(request, env) }
19
- proc = -> { logger.tagged(compute_tags(request), &proc) } if @taggers && !@taggers.empty?
20
- named_tags ? SemanticLogger.named_tagged(compute_named_tags(request), &proc) : proc.call
16
+ # Check for named tags (Hash)
17
+ if @taggers && !@taggers.empty?
18
+ tags = @taggers.is_a?(Hash) ? compute_named_tags(request) : compute_tags(request)
19
+ logger.tagged(tags) { call_app(request, env) }
20
+ else
21
+ call_app(request, env)
22
+ end
21
23
  end
22
24
 
23
25
  def started_request_message(request)
@@ -37,10 +39,11 @@ module Rails
37
39
  self.class.logger
38
40
  end
39
41
 
42
+ # Leave out any named tags with a nil value
40
43
  def compute_named_tags(request) # :doc:
41
44
  tagged = {}
42
- named_tags.each_pair do |tag, value|
43
- resolved =
45
+ @taggers.each_pair do |tag, value|
46
+ resolved =
44
47
  case value
45
48
  when Proc
46
49
  value.call(request)
@@ -1,3 +1,3 @@
1
1
  module RailsSemanticLogger #:nodoc
2
- VERSION = '4.1.1'
2
+ VERSION = '4.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1
4
+ version: 4.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails