rails_semantic_logger 3.1.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +12 -0
- data/lib/rails_semantic_logger/{railtie.rb → engine.rb} +39 -30
- data/lib/rails_semantic_logger/extensions/action_controller/log_subscriber.rb +19 -31
- data/lib/rails_semantic_logger/extensions/active_job/logging.rb +1 -1
- data/lib/rails_semantic_logger/version.rb +1 -1
- data/lib/rails_semantic_logger.rb +5 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67bd2b0d0a80d45742fb6572b8b27f52e4dbf526
|
4
|
+
data.tar.gz: f59d1f7880d8505d0bab1cf11be026c2037ed7f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0af32c2965f21bcd60e6a7a3cbe5ecd9763c5d9d6a67fb9a390c7c9357b68520de1491f8a3ae9218c5d7a70f772b8b7cc9e499512be613295bc9c82e79f11162
|
7
|
+
data.tar.gz: 04354ac1161c9ca47fad9790f2098e1ecbdb8bfb28cefa69efb8780cb7ee7e9ae010eefdfcf9d4d0279218f0039a20ab389f4f91dc59dd6ee494d140b5cc1cf6
|
data/Rakefile
CHANGED
@@ -14,3 +14,15 @@ task :publish => :gem do
|
|
14
14
|
system "gem push rails_semantic_logger-#{RailsSemanticLogger::VERSION}.gem"
|
15
15
|
system "rm rails_semantic_logger-#{RailsSemanticLogger::VERSION}.gem"
|
16
16
|
end
|
17
|
+
|
18
|
+
desc 'Run Test Suite'
|
19
|
+
task :test do
|
20
|
+
Rake::TestTask.new(:functional) do |t|
|
21
|
+
t.test_files = FileList['test/**/*_test.rb']
|
22
|
+
t.verbose = true
|
23
|
+
end
|
24
|
+
|
25
|
+
Rake::Task['functional'].invoke
|
26
|
+
end
|
27
|
+
|
28
|
+
task default: :test
|
@@ -1,8 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# Replace standard Rails logger
|
4
|
-
module RailsSemanticLogger #:nodoc:
|
5
|
-
class Railtie < Rails::Railtie #:nodoc:
|
1
|
+
module RailsSemanticLogger
|
2
|
+
class Engine < ::Rails::Engine
|
6
3
|
# Make the SemanticLogger config available in the Rails application config
|
7
4
|
#
|
8
5
|
# Example: Add the MongoDB logging appender in the Rails environment
|
@@ -19,22 +16,22 @@ module RailsSemanticLogger #:nodoc:
|
|
19
16
|
# end
|
20
17
|
config.semantic_logger = ::SemanticLogger
|
21
18
|
|
22
|
-
config.rails_semantic_logger
|
19
|
+
config.rails_semantic_logger = ActiveSupport::OrderedOptions.new
|
23
20
|
|
24
21
|
# Convert Action Controller and Active Record text messages to semantic data
|
25
22
|
# Rails -- Started -- { :ip => "127.0.0.1", :method => "GET", :path => "/dashboards/inquiry_recent_activity" }
|
26
23
|
# UserController -- Completed #index -- { :action => "index", :db_runtime => 54.64, :format => "HTML", :method => "GET", :mongo_runtime => 0.0, :path => "/users", :status => 200, :status_message => "OK", :view_runtime => 709.88 }
|
27
|
-
config.rails_semantic_logger.semantic
|
24
|
+
config.rails_semantic_logger.semantic = true
|
28
25
|
|
29
26
|
# Change Rack started message to debug so that it does not appear in production
|
30
|
-
config.rails_semantic_logger.started
|
27
|
+
config.rails_semantic_logger.started = false
|
31
28
|
|
32
29
|
# Change Processing message to debug so that it does not appear in production
|
33
|
-
config.rails_semantic_logger.processing
|
30
|
+
config.rails_semantic_logger.processing = false
|
34
31
|
|
35
32
|
# Change Action View render log messages to debug so that they do not appear in production
|
36
33
|
# ActionView::Base -- Rendered data/search/_user.html.haml (46.7ms)
|
37
|
-
config.rails_semantic_logger.rendered
|
34
|
+
config.rails_semantic_logger.rendered = false
|
38
35
|
|
39
36
|
# Override the Awesome Print options for logging Hash data as text:
|
40
37
|
#
|
@@ -44,7 +41,17 @@ module RailsSemanticLogger #:nodoc:
|
|
44
41
|
#
|
45
42
|
# Note: The option :multiline is set to false if not supplied.
|
46
43
|
# Note: Has no effect if Awesome Print is not installed.
|
47
|
-
config.rails_semantic_logger.ap_options
|
44
|
+
config.rails_semantic_logger.ap_options = {multiline: false}
|
45
|
+
|
46
|
+
# Whether to automatically add an environment specific log file appender.
|
47
|
+
# For Example: 'log/development.log'
|
48
|
+
#
|
49
|
+
# Note:
|
50
|
+
# When Semantic Logger fails to log to an appender it logs the error to an
|
51
|
+
# internal logger, which by default writes to STDERR.
|
52
|
+
# Example, change the default internal logger to log to stdout:
|
53
|
+
# SemanticLogger::Logger.logger = SemanticLogger::Appender::File.new(STDOUT, :warn)
|
54
|
+
config.rails_semantic_logger.add_file_appender = true
|
48
55
|
|
49
56
|
# Initialize SemanticLogger. In a Rails environment it will automatically
|
50
57
|
# insert itself above the configured rails logger to add support for its
|
@@ -62,22 +69,24 @@ module RailsSemanticLogger #:nodoc:
|
|
62
69
|
# Existing loggers are ignored because servers like trinidad supply their
|
63
70
|
# own file loggers which would result in duplicate logging to the same log file
|
64
71
|
Rails.logger = config.logger = begin
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
72
|
+
if config.rails_semantic_logger.add_file_appender
|
73
|
+
path = config.paths['log'].first
|
74
|
+
FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(File.dirname(path))
|
75
|
+
|
76
|
+
# Add the log file to the list of appenders
|
77
|
+
# Use the colorized formatter if Rails colorized logs are enabled
|
78
|
+
ap_options = config.rails_semantic_logger.ap_options
|
79
|
+
formatter = config.colorize_logging == false ? SemanticLogger::Formatters::Default.new : SemanticLogger::Formatters::Color.new(ap: ap_options)
|
80
|
+
|
81
|
+
# Set internal logger to log to file only, in case another appender experiences errors during writes
|
82
|
+
appender = SemanticLogger::Appender::File.new(file_name: path, level: config.log_level, formatter: formatter)
|
83
|
+
appender.name = 'SemanticLogger'
|
84
|
+
SemanticLogger::Logger.logger = appender
|
85
|
+
|
86
|
+
# Check for previous file or stdout loggers
|
87
|
+
SemanticLogger.appenders.each { |appender| appender.formatter = formatter if appender.is_a?(SemanticLogger::Appender::File) }
|
88
|
+
SemanticLogger.add_appender(file_name: path, formatter: formatter)
|
89
|
+
end
|
81
90
|
SemanticLogger[Rails]
|
82
91
|
rescue StandardError => exc
|
83
92
|
# If not able to log to file, log to standard error with warning level only
|
@@ -147,11 +156,11 @@ module RailsSemanticLogger #:nodoc:
|
|
147
156
|
Concurrent.global_logger = SemanticLogger[Concurrent] if defined?(Concurrent)
|
148
157
|
|
149
158
|
# Rails Patches
|
150
|
-
require('rails_semantic_logger/extensions/action_cable/tagged_logger_proxy') if defined?(ActionCable
|
159
|
+
require('rails_semantic_logger/extensions/action_cable/tagged_logger_proxy') if defined?(ActionCable)
|
151
160
|
require('rails_semantic_logger/extensions/action_controller/live') if defined?(ActionController::Live)
|
152
161
|
require('rails_semantic_logger/extensions/action_dispatch/debug_exceptions') if defined?(ActionDispatch::DebugExceptions)
|
153
162
|
require('rails_semantic_logger/extensions/action_view/streaming_template_renderer') if defined?(ActionView::StreamingTemplateRenderer::Body)
|
154
|
-
require('rails_semantic_logger/extensions/active_job/logging') if defined?(ActiveJob
|
163
|
+
require('rails_semantic_logger/extensions/active_job/logging') if defined?(ActiveJob)
|
155
164
|
|
156
165
|
if config.rails_semantic_logger.semantic
|
157
166
|
require('rails_semantic_logger/extensions/rails/rack/logger') if defined?(Rails::Rack::Logger)
|
@@ -174,6 +183,6 @@ module RailsSemanticLogger #:nodoc:
|
|
174
183
|
# Replace the Bugsnag logger
|
175
184
|
Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
|
176
185
|
end
|
186
|
+
|
177
187
|
end
|
178
188
|
end
|
179
|
-
|
@@ -9,30 +9,28 @@ module ActionController
|
|
9
9
|
|
10
10
|
def process_action(event)
|
11
11
|
controller_logger(event).info do
|
12
|
-
payload = event.payload
|
13
|
-
|
14
|
-
|
15
|
-
format = format.to_s.upcase if format.is_a?(Symbol)
|
16
|
-
status = payload[:status]
|
12
|
+
payload = event.payload.dup
|
13
|
+
payload[:params].except!(*INTERNAL_PARAMS)
|
14
|
+
payload.delete(:params) if payload[:params].empty?
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
format = payload[:format]
|
17
|
+
payload[:format] = format.to_s.upcase if format.is_a?(Symbol)
|
18
|
+
|
19
|
+
exception = payload.delete(:exception)
|
20
|
+
if payload[:status].nil? && exception.present?
|
21
|
+
exception_class_name = exception.first
|
22
|
+
payload[:status] = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Rounds off the runtimes. For example, :view_runtime, :mongo_runtime, etc.
|
26
|
+
payload.keys.each do |key|
|
27
|
+
payload[key] = payload[key].to_f.round(2) if key.to_s.match(/(.*)_runtime/)
|
21
28
|
end
|
22
29
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
format: format,
|
28
|
-
path: payload[:path],
|
29
|
-
action: payload[:action],
|
30
|
-
method: payload[:method],
|
31
|
-
duration: event.duration
|
32
|
-
}
|
33
|
-
collect_runtimes(payload, log)
|
34
|
-
log[:params] = params unless params.empty?
|
35
|
-
log
|
30
|
+
payload[:message] = "Completed ##{payload[:action]}"
|
31
|
+
payload[:status_message] = Rack::Utils::HTTP_STATUS_CODES[payload[:status]] if payload[:status].present?
|
32
|
+
payload[:duration] = event.duration
|
33
|
+
payload
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
@@ -87,15 +85,5 @@ module ActionController
|
|
87
85
|
end
|
88
86
|
end
|
89
87
|
|
90
|
-
# Returns [Hash] runtimes for all registered runtime collection subscribers
|
91
|
-
# For example, :view_runtime, :mongo_runtime, etc.
|
92
|
-
def collect_runtimes(payload, log)
|
93
|
-
payload.each_pair do |key, value|
|
94
|
-
if match = key.to_s.match(/(.*)_runtime/)
|
95
|
-
log[key] = value.to_f.round(2)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
88
|
end
|
101
89
|
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: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.3'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
40
|
+
version: '3.3'
|
41
41
|
description: Replaces the default Rails logger with SemanticLogger
|
42
42
|
email:
|
43
43
|
- reidmo@gmail.com
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
51
|
- lib/rails_semantic_logger.rb
|
52
|
+
- lib/rails_semantic_logger/engine.rb
|
52
53
|
- lib/rails_semantic_logger/extensions/action_cable/tagged_logger_proxy.rb
|
53
54
|
- lib/rails_semantic_logger/extensions/action_controller/live.rb
|
54
55
|
- lib/rails_semantic_logger/extensions/action_controller/log_subscriber.rb
|
@@ -61,7 +62,6 @@ files:
|
|
61
62
|
- lib/rails_semantic_logger/extensions/rails/rack/logger.rb
|
62
63
|
- lib/rails_semantic_logger/extensions/rails/rack/logger_info_as_debug.rb
|
63
64
|
- lib/rails_semantic_logger/extensions/rails/server.rb
|
64
|
-
- lib/rails_semantic_logger/railtie.rb
|
65
65
|
- lib/rails_semantic_logger/version.rb
|
66
66
|
homepage: https://github.com/rocketjob/rails_semantic_logger
|
67
67
|
licenses:
|