rack-action_logger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +53 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rspec +17 -0
- data/bin/setup +8 -0
- data/docs/action_log.png +0 -0
- data/docs/attributed_log.png +0 -0
- data/docs/request_log.png +0 -0
- data/docs/sample_log.png +0 -0
- data/example/rails4/.generators +8 -0
- data/example/rails4/.gitignore +48 -0
- data/example/rails4/.rakeTasks +7 -0
- data/example/rails4/Gemfile +53 -0
- data/example/rails4/Gemfile.lock +192 -0
- data/example/rails4/README.rdoc +28 -0
- data/example/rails4/Rakefile +6 -0
- data/example/rails4/app/assets/images/.keep +0 -0
- data/example/rails4/app/assets/javascripts/application.js +16 -0
- data/example/rails4/app/assets/javascripts/hello.coffee +3 -0
- data/example/rails4/app/assets/stylesheets/application.css +15 -0
- data/example/rails4/app/assets/stylesheets/hello.scss +3 -0
- data/example/rails4/app/controllers/application_controller.rb +7 -0
- data/example/rails4/app/controllers/concerns/.keep +0 -0
- data/example/rails4/app/controllers/hello_controller.rb +6 -0
- data/example/rails4/app/helpers/application_helper.rb +2 -0
- data/example/rails4/app/helpers/hello_helper.rb +2 -0
- data/example/rails4/app/mailers/.keep +0 -0
- data/example/rails4/app/models/.keep +0 -0
- data/example/rails4/app/models/concerns/.keep +0 -0
- data/example/rails4/app/views/hello/index.html.erb +2 -0
- data/example/rails4/app/views/layouts/application.html.erb +14 -0
- data/example/rails4/bin/bundle +3 -0
- data/example/rails4/bin/rails +4 -0
- data/example/rails4/bin/rake +4 -0
- data/example/rails4/bin/rspec +17 -0
- data/example/rails4/bin/setup +29 -0
- data/example/rails4/config/application.rb +37 -0
- data/example/rails4/config/boot.rb +3 -0
- data/example/rails4/config/database.yml +25 -0
- data/example/rails4/config/environment.rb +5 -0
- data/example/rails4/config/environments/development.rb +41 -0
- data/example/rails4/config/environments/production.rb +79 -0
- data/example/rails4/config/environments/test.rb +42 -0
- data/example/rails4/config/initializers/assets.rb +11 -0
- data/example/rails4/config/initializers/backtrace_silencers.rb +7 -0
- data/example/rails4/config/initializers/cookies_serializer.rb +3 -0
- data/example/rails4/config/initializers/filter_parameter_logging.rb +4 -0
- data/example/rails4/config/initializers/fluent_logger.rb +1 -0
- data/example/rails4/config/initializers/inflections.rb +16 -0
- data/example/rails4/config/initializers/mime_types.rb +4 -0
- data/example/rails4/config/initializers/rack-action_logger.rb +6 -0
- data/example/rails4/config/initializers/session_store.rb +3 -0
- data/example/rails4/config/initializers/wrap_parameters.rb +14 -0
- data/example/rails4/config/locales/en.yml +23 -0
- data/example/rails4/config/routes.rb +3 -0
- data/example/rails4/config/secrets.yml +22 -0
- data/example/rails4/config.ru +4 -0
- data/example/rails4/db/schema.rb +16 -0
- data/example/rails4/db/seeds.rb +7 -0
- data/example/rails4/lib/assets/.keep +0 -0
- data/example/rails4/lib/tasks/.keep +0 -0
- data/example/rails4/public/404.html +67 -0
- data/example/rails4/public/422.html +67 -0
- data/example/rails4/public/500.html +66 -0
- data/example/rails4/public/favicon.ico +0 -0
- data/example/rails4/public/robots.txt +5 -0
- data/example/rails4/spec/controllers/hello_controller_spec.rb +10 -0
- data/example/rails4/spec/rails_helper.rb +57 -0
- data/example/rails4/spec/spec_helper.rb +99 -0
- data/example/rails4/vendor/assets/javascripts/.keep +0 -0
- data/example/rails4/vendor/assets/stylesheets/.keep +0 -0
- data/example/rails5/.generators +8 -0
- data/example/rails5/.gitignore +48 -0
- data/example/rails5/.rakeTasks +7 -0
- data/example/rails5/Gemfile +54 -0
- data/example/rails5/Gemfile.lock +205 -0
- data/example/rails5/README.md +24 -0
- data/example/rails5/Rakefile +6 -0
- data/example/rails5/app/assets/config/manifest.js +3 -0
- data/example/rails5/app/assets/images/.keep +0 -0
- data/example/rails5/app/assets/javascripts/application.js +16 -0
- data/example/rails5/app/assets/javascripts/cable.js +13 -0
- data/example/rails5/app/assets/javascripts/channels/.keep +0 -0
- data/example/rails5/app/assets/javascripts/hello.coffee +3 -0
- data/example/rails5/app/assets/stylesheets/application.css +15 -0
- data/example/rails5/app/assets/stylesheets/hello.scss +3 -0
- data/example/rails5/app/channels/application_cable/channel.rb +4 -0
- data/example/rails5/app/channels/application_cable/connection.rb +4 -0
- data/example/rails5/app/controllers/application_controller.rb +5 -0
- data/example/rails5/app/controllers/concerns/.keep +0 -0
- data/example/rails5/app/controllers/hello_controller.rb +6 -0
- data/example/rails5/app/helpers/application_helper.rb +2 -0
- data/example/rails5/app/helpers/hello_helper.rb +2 -0
- data/example/rails5/app/jobs/application_job.rb +2 -0
- data/example/rails5/app/mailers/application_mailer.rb +4 -0
- data/example/rails5/app/models/application_record.rb +3 -0
- data/example/rails5/app/models/concerns/.keep +0 -0
- data/example/rails5/app/views/hello/index.html.erb +2 -0
- data/example/rails5/app/views/layouts/application.html.erb +14 -0
- data/example/rails5/app/views/layouts/mailer.html.erb +13 -0
- data/example/rails5/app/views/layouts/mailer.text.erb +1 -0
- data/example/rails5/bin/bundle +3 -0
- data/example/rails5/bin/rails +4 -0
- data/example/rails5/bin/rake +17 -0
- data/example/rails5/bin/rspec +17 -0
- data/example/rails5/bin/setup +34 -0
- data/example/rails5/bin/update +29 -0
- data/example/rails5/config/application.rb +13 -0
- data/example/rails5/config/boot.rb +3 -0
- data/example/rails5/config/cable.yml +9 -0
- data/example/rails5/config/database.yml +25 -0
- data/example/rails5/config/environment.rb +5 -0
- data/example/rails5/config/environments/development.rb +54 -0
- data/example/rails5/config/environments/production.rb +86 -0
- data/example/rails5/config/environments/test.rb +42 -0
- data/example/rails5/config/initializers/application_controller_renderer.rb +6 -0
- data/example/rails5/config/initializers/assets.rb +11 -0
- data/example/rails5/config/initializers/backtrace_silencers.rb +7 -0
- data/example/rails5/config/initializers/cookies_serializer.rb +5 -0
- data/example/rails5/config/initializers/filter_parameter_logging.rb +4 -0
- data/example/rails5/config/initializers/fluent_logger.rb +1 -0
- data/example/rails5/config/initializers/inflections.rb +16 -0
- data/example/rails5/config/initializers/mime_types.rb +4 -0
- data/example/rails5/config/initializers/new_framework_defaults.rb +24 -0
- data/example/rails5/config/initializers/rack-action_logger.rb +6 -0
- data/example/rails5/config/initializers/session_store.rb +3 -0
- data/example/rails5/config/initializers/wrap_parameters.rb +14 -0
- data/example/rails5/config/locales/en.yml +23 -0
- data/example/rails5/config/puma.rb +47 -0
- data/example/rails5/config/routes.rb +3 -0
- data/example/rails5/config/secrets.yml +22 -0
- data/example/rails5/config/spring.rb +6 -0
- data/example/rails5/config.ru +5 -0
- data/example/rails5/db/schema.rb +15 -0
- data/example/rails5/db/seeds.rb +7 -0
- data/example/rails5/lib/assets/.keep +0 -0
- data/example/rails5/lib/tasks/.keep +0 -0
- data/example/rails5/public/404.html +67 -0
- data/example/rails5/public/422.html +67 -0
- data/example/rails5/public/500.html +66 -0
- data/example/rails5/public/apple-touch-icon-precomposed.png +0 -0
- data/example/rails5/public/apple-touch-icon.png +0 -0
- data/example/rails5/public/favicon.ico +0 -0
- data/example/rails5/public/robots.txt +5 -0
- data/example/rails5/spec/controllers/hello_controller_spec.rb +10 -0
- data/example/rails5/spec/rails_helper.rb +57 -0
- data/example/rails5/spec/spec_helper.rb +99 -0
- data/example/rails5/vendor/assets/javascripts/.keep +0 -0
- data/example/rails5/vendor/assets/stylesheets/.keep +0 -0
- data/lib/rack/action_logger/configuration.rb +25 -0
- data/lib/rack/action_logger/container.rb +95 -0
- data/lib/rack/action_logger/context.rb +15 -0
- data/lib/rack/action_logger/controller_concerns/request_log.rb +18 -0
- data/lib/rack/action_logger/controller_concerns.rb +8 -0
- data/lib/rack/action_logger/emit_adapter/base.rb +18 -0
- data/lib/rack/action_logger/emit_adapter/fluent_adapter.rb +11 -0
- data/lib/rack/action_logger/emit_adapter/logger_adapter.rb +10 -0
- data/lib/rack/action_logger/emit_adapter/null_adapter.rb +7 -0
- data/lib/rack/action_logger/emitter.rb +44 -0
- data/lib/rack/action_logger/version.rb +5 -0
- data/lib/rack/action_logger.rb +30 -0
- data/rack-action_logger.gemspec +30 -0
- metadata +283 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
ENV['RAILS_ENV'] ||= 'test'
|
3
|
+
require File.expand_path('../../config/environment', __FILE__)
|
4
|
+
# Prevent database truncation if the environment is production
|
5
|
+
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
6
|
+
require 'spec_helper'
|
7
|
+
require 'rspec/rails'
|
8
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
9
|
+
|
10
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
11
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
12
|
+
# run as spec files by default. This means that files in spec/support that end
|
13
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
14
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
15
|
+
# end with _spec.rb. You can configure this pattern with the --pattern
|
16
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
17
|
+
#
|
18
|
+
# The following line is provided for convenience purposes. It has the downside
|
19
|
+
# of increasing the boot-up time by auto-requiring all files in the support
|
20
|
+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
21
|
+
# require only the support files necessary.
|
22
|
+
#
|
23
|
+
# Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
|
24
|
+
|
25
|
+
# Checks for pending migration and applies them before tests are run.
|
26
|
+
# If you are not using ActiveRecord, you can remove this line.
|
27
|
+
ActiveRecord::Migration.maintain_test_schema!
|
28
|
+
|
29
|
+
RSpec.configure do |config|
|
30
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
31
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
32
|
+
|
33
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
34
|
+
# examples within a transaction, remove the following line or assign false
|
35
|
+
# instead of true.
|
36
|
+
config.use_transactional_fixtures = true
|
37
|
+
|
38
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
39
|
+
# based on their file location, for example enabling you to call `get` and
|
40
|
+
# `post` in specs under `spec/controllers`.
|
41
|
+
#
|
42
|
+
# You can disable this behaviour by removing the line below, and instead
|
43
|
+
# explicitly tag your specs with their type, e.g.:
|
44
|
+
#
|
45
|
+
# RSpec.describe UsersController, :type => :controller do
|
46
|
+
# # ...
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# The different available types are documented in the features, such as in
|
50
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
51
|
+
config.infer_spec_type_from_file_location!
|
52
|
+
|
53
|
+
# Filter lines from Rails gems in backtraces.
|
54
|
+
config.filter_rails_from_backtrace!
|
55
|
+
# arbitrary gems may also be filtered via:
|
56
|
+
# config.filter_gems_from_backtrace("gem name")
|
57
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# This file was generated by the `rails generate rspec:install` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
44
|
+
# have no way to turn it off -- the option exists only for backwards
|
45
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
46
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
47
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
48
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
49
|
+
|
50
|
+
# The settings below are suggested to provide a good initial experience
|
51
|
+
# with RSpec, but feel free to customize to your heart's content.
|
52
|
+
=begin
|
53
|
+
# This allows you to limit a spec run to individual examples or groups
|
54
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
55
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
56
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
57
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
58
|
+
config.filter_run_when_matching :focus
|
59
|
+
|
60
|
+
# Allows RSpec to persist some state between runs in order to support
|
61
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
62
|
+
# you configure your source control system to ignore this file.
|
63
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
64
|
+
|
65
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
66
|
+
# recommended. For more details, see:
|
67
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
68
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
69
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
70
|
+
config.disable_monkey_patching!
|
71
|
+
|
72
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
73
|
+
# file, and it's useful to allow more verbose output when running an
|
74
|
+
# individual spec file.
|
75
|
+
if config.files_to_run.one?
|
76
|
+
# Use the documentation formatter for detailed output,
|
77
|
+
# unless a formatter has already been configured
|
78
|
+
# (e.g. via a command-line flag).
|
79
|
+
config.default_formatter = 'doc'
|
80
|
+
end
|
81
|
+
|
82
|
+
# Print the 10 slowest examples and example groups at the
|
83
|
+
# end of the spec run, to help surface which specs are running
|
84
|
+
# particularly slow.
|
85
|
+
config.profile_examples = 10
|
86
|
+
|
87
|
+
# Run specs in random order to surface order dependencies. If you find an
|
88
|
+
# order dependency and want to debug it, you can fix the order by providing
|
89
|
+
# the seed, which is printed after each run.
|
90
|
+
# --seed 1234
|
91
|
+
config.order = :random
|
92
|
+
|
93
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
94
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
95
|
+
# test failures related to randomization by passing the same `--seed` value
|
96
|
+
# as the one that triggered the failure.
|
97
|
+
Kernel.srand config.seed
|
98
|
+
=end
|
99
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rack/action_logger/emit_adapter/logger_adapter'
|
2
|
+
require 'rack/action_logger/emit_adapter/fluent_adapter'
|
3
|
+
require 'rack/action_logger/emit_adapter/null_adapter'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module Rack::ActionLogger
|
7
|
+
class Configuration
|
8
|
+
attr_accessor :emit_adapter
|
9
|
+
attr_accessor :wrap_key
|
10
|
+
attr_accessor :default_tag
|
11
|
+
attr_accessor :tag_prefix
|
12
|
+
attr_accessor :logger
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@emit_adapter = EmitAdapter::LoggerAdapter
|
16
|
+
@tag_prefix = 'action'
|
17
|
+
@logger = Logger.new(STDOUT)
|
18
|
+
@logger.progname = 'rack_action_logger'
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_tag
|
22
|
+
"#{@tag_prefix}.log"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
module Rack::ActionLogger
|
5
|
+
module Container
|
6
|
+
THREAD_KEY = :rack_action_logger
|
7
|
+
EXPORT_KEYS = [:rack_action_logger_attributes]
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def store
|
11
|
+
Thread.current[THREAD_KEY] ||= {}
|
12
|
+
end
|
13
|
+
|
14
|
+
def clear
|
15
|
+
Thread.current[THREAD_KEY] = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_is_emit_started
|
19
|
+
store[:rack_action_logger_emit_started] = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_is_emit_started
|
23
|
+
store[:rack_action_logger_emit_started] ||= false
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_append_log(hash, tag)
|
27
|
+
return unless is_valid_hash hash
|
28
|
+
return unless is_valid_tag tag
|
29
|
+
hash[:tag] = tag
|
30
|
+
get_append_logs.push(hash)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_append_logs
|
34
|
+
store[:rack_action_logger_append_logs] ||= []
|
35
|
+
end
|
36
|
+
|
37
|
+
def merge_attributes(attributes)
|
38
|
+
return unless is_valid_hash attributes
|
39
|
+
get_attributes.merge! attributes
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_attributes
|
43
|
+
store[:rack_action_logger_attributes] ||= {}
|
44
|
+
end
|
45
|
+
|
46
|
+
def set_request_log(hash, tag)
|
47
|
+
return unless is_valid_hash hash
|
48
|
+
return unless is_valid_tag tag
|
49
|
+
hash[:tag] = tag
|
50
|
+
get_request_log.merge! hash
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_request_log
|
54
|
+
store[:rack_action_logger_request_log] ||= {}
|
55
|
+
end
|
56
|
+
|
57
|
+
def export
|
58
|
+
# ここenumerableで置き換える
|
59
|
+
hash = {}
|
60
|
+
EXPORT_KEYS.each do |key|
|
61
|
+
hash[key] = store[key] if store[key]
|
62
|
+
end
|
63
|
+
hash
|
64
|
+
end
|
65
|
+
|
66
|
+
def import(hash)
|
67
|
+
hash.symbolize_keys.each do |key, value|
|
68
|
+
next unless EXPORT_KEYS.include? key
|
69
|
+
store[key] = value
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def is_valid_hash(hash)
|
76
|
+
if hash.is_a? Hash
|
77
|
+
true
|
78
|
+
else
|
79
|
+
Rack::ActionLogger.logger.error("invalid hash: #{hash}")
|
80
|
+
false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def is_valid_tag(tag)
|
85
|
+
if tag.is_a? String
|
86
|
+
true
|
87
|
+
else
|
88
|
+
Rack::ActionLogger.logger.error("invalid tag: #{tag}")
|
89
|
+
false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rack/action_logger/container'
|
2
|
+
|
3
|
+
module Rack::ActionLogger::ControllerConcerns
|
4
|
+
module RequestLog
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
before_action :set_request_log
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_request_log
|
12
|
+
Rack::ActionLogger::Container.set_request_log({ path_info: request.path_info, request_method: request.request_method }, 'action.request')
|
13
|
+
|
14
|
+
request_id = Rails::VERSION::MAJOR >= 5 ? request.request_id : request.uuid
|
15
|
+
Rack::ActionLogger::Container.merge_attributes({ request_id: request_id })
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rack/action_logger'
|
2
|
+
|
3
|
+
module Rack::ActionLogger::EmitAdapter
|
4
|
+
class Base
|
5
|
+
def self.emit(hash); end
|
6
|
+
|
7
|
+
def self.wrap(hash)
|
8
|
+
result = {}
|
9
|
+
wrap_key = Rack::ActionLogger.configuration.wrap_key
|
10
|
+
if wrap_key
|
11
|
+
result[wrap_key] = hash
|
12
|
+
else
|
13
|
+
result = hash
|
14
|
+
end
|
15
|
+
result
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rack/action_logger/emit_adapter/base'
|
2
|
+
|
3
|
+
module Rack::ActionLogger::EmitAdapter
|
4
|
+
class FluentAdapter < Base
|
5
|
+
def self.emit(hash)
|
6
|
+
tag = hash[:tag] ? hash[:tag] : Rack::ActionLogger.configuration.default_tag
|
7
|
+
hash = wrap(hash)
|
8
|
+
Fluent::Logger.post(tag, hash)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Rack::ActionLogger
|
2
|
+
class Emitter
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@can_emit = !Container.get_is_emit_started
|
6
|
+
unless @can_emit
|
7
|
+
Rack::ActionLogger.logger.error("#{self.class} is already defined.")
|
8
|
+
Rack::ActionLogger.logger.error("#{Thread.current.backtrace.join("\n")}")
|
9
|
+
end
|
10
|
+
@emit_adapter = Rack::ActionLogger.configuration.emit_adapter
|
11
|
+
@container = Container
|
12
|
+
end
|
13
|
+
|
14
|
+
def emit(context=nil)
|
15
|
+
@container.set_is_emit_started
|
16
|
+
@container.import(context) if context
|
17
|
+
result = yield
|
18
|
+
emit_all_logs # emit log unless exception raised
|
19
|
+
result
|
20
|
+
ensure
|
21
|
+
@container.clear if @can_emit
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def emit_all_logs
|
27
|
+
return unless @can_emit
|
28
|
+
emit_request_log
|
29
|
+
emit_append_logs
|
30
|
+
end
|
31
|
+
|
32
|
+
def emit_request_log
|
33
|
+
return unless (@container.get_request_log.is_a?(Hash) && @container.get_request_log != {})
|
34
|
+
hash = @container.get_request_log.merge @container.get_attributes
|
35
|
+
@emit_adapter.emit(hash)
|
36
|
+
end
|
37
|
+
|
38
|
+
def emit_append_logs
|
39
|
+
@container.get_append_logs.each do |hash|
|
40
|
+
@emit_adapter.emit(@container.get_attributes.merge!(hash))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rack/action_logger/configuration'
|
2
|
+
|
3
|
+
module Rack::ActionLogger
|
4
|
+
class << self
|
5
|
+
attr_accessor :configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.new(app)
|
9
|
+
Context.new(app)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configure
|
13
|
+
yield configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.configuration
|
17
|
+
@configuration ||= Configuration.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.logger
|
21
|
+
configuration.logger
|
22
|
+
end
|
23
|
+
|
24
|
+
autoload :Configuration, 'rack/action_logger/configuration'
|
25
|
+
autoload :Container, 'rack/action_logger/container'
|
26
|
+
autoload :Context, 'rack/action_logger/context'
|
27
|
+
autoload :Emitter, 'rack/action_logger/emitter'
|
28
|
+
autoload :ControllerConcerns, 'rack/action_logger/controller_concerns'
|
29
|
+
autoload :EmitAdapter, 'rack/action_logger/emit_adapter'
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rack/action_logger/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rack-action_logger'
|
8
|
+
spec.version = Rack::ActionLogger::VERSION
|
9
|
+
spec.authors = ['Koichi Ishida']
|
10
|
+
spec.email = ['wapa5pow@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Rack::ActionLogger is a tool to log user activity'
|
13
|
+
spec.description = 'Rack::ActionLogger is a tool to log user activity'
|
14
|
+
spec.homepage = 'https://github.com/wapa5pow/rack-action_logger'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'activesupport'
|
25
|
+
spec.add_dependency 'fluent-logger', '~> 0.5'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
end
|