action_tracer 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +33 -9
- data/lib/action_tracer/configuration.rb +45 -0
- data/lib/action_tracer/filters.rb +30 -17
- data/lib/action_tracer/monkey_patches/active_support/callbacks.rb +6 -6
- data/lib/action_tracer/railtie.rb +0 -16
- data/lib/action_tracer/version.rb +1 -1
- data/lib/action_tracer.rb +1 -1
- metadata +3 -3
- data/lib/action_tracer/logger.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7214356083ad06c96fe92939aa010ea7ad918d2273431eedecd9edfe3d358f3d
|
4
|
+
data.tar.gz: 13e9c9b139723297a2a92407786761a7f1df0bfc58a793e980daaa7232d665f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da46b25d92b0c5fba47b21cda6ccd555a6bf89dd9bcb40be436bbc55b7dc4c7cc4cce1d662927d26f492bc0fda5eba4f2ff1cddc0347b2f7f3450978dd0c7beb
|
7
|
+
data.tar.gz: 074af54035733e26735e927a84e0e1bc2717a28cddb583af30035deae31f29d3bd9391eed8830b4a684eb40355f75b67b6fbd031fd48d0775dfdd4ad2112613f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -60,12 +60,12 @@ it will put logs for `log/action_tracer.log` like this:
|
|
60
60
|
```log
|
61
61
|
I, [2020-09-27T03:25:43.018298 #1] INFO -- : ["APPLIED", :set_turbolinks_location_header_from_session, "/usr/local/bundle/gems/turbolinks-5.2.1/lib/turbolinks/redirection.rb", 43]
|
62
62
|
I, [2020-09-27T03:25:43.019410 #1] INFO -- : ["APPLIED", :verify_authenticity_token, "/usr/local/bundle/gems/actionpack-5.1.7/lib/action_controller/metal/request_forgery_protection.rb", 211]
|
63
|
-
I, [2020-09-27T03:25:43.021131 #1] INFO -- : ["APPLIED", :require_login, "
|
64
|
-
I, [2020-09-27T03:25:43.022063 #1] INFO -- : ["NO_APPLIED", :set_awesome, "
|
65
|
-
I, [2020-09-27T03:25:43.023716 #1] INFO -- : ["APPLIED", :with_readonly, "
|
66
|
-
I, [2020-09-27T03:25:43.025547 #1] INFO -- : ["ACTION", :index, "
|
67
|
-
I, [2020-09-27T03:25:43.026297 #1] INFO -- : ["APPLIED", :with_readonly, "
|
68
|
-
I, [2020-09-27T03:25:43.027203 #1] INFO -- : ["APPLIED", :store_location, "
|
63
|
+
I, [2020-09-27T03:25:43.021131 #1] INFO -- : ["APPLIED", :require_login, "app/controllers/awesome_controller.rb", 17]
|
64
|
+
I, [2020-09-27T03:25:43.022063 #1] INFO -- : ["NO_APPLIED", :set_awesome, "app/controllers/awesome_controller.rb", 25]
|
65
|
+
I, [2020-09-27T03:25:43.023716 #1] INFO -- : ["APPLIED", :with_readonly, "app/controllers/awesome_controller.rb", 21]
|
66
|
+
I, [2020-09-27T03:25:43.025547 #1] INFO -- : ["ACTION", :index, "app/controllers/awesome_controller.rb", 7]
|
67
|
+
I, [2020-09-27T03:25:43.026297 #1] INFO -- : ["APPLIED", :with_readonly, "app/controllers/awesome_controller.rb", 21]
|
68
|
+
I, [2020-09-27T03:25:43.027203 #1] INFO -- : ["APPLIED", :store_location, "app/controllers/awesome_controller.rb", 27]
|
69
69
|
I, [2020-09-27T03:25:43.030074 #1] INFO -- : ["APPLIED", :verify_same_origin_request, "/usr/local/bundle/gems/actionpack-5.1.7/lib/action_controller/metal/request_forgery_protection.rb", 240]
|
70
70
|
I, [2020-09-27T03:25:43.030776 #1] INFO -- :
|
71
71
|
```
|
@@ -78,7 +78,7 @@ Notice `around_action` is put 2 times around action though called 1 time.
|
|
78
78
|
Normally log is put in this format:
|
79
79
|
|
80
80
|
```ruby
|
81
|
-
["APPLIED", :require_login, "
|
81
|
+
["APPLIED", :require_login, "app/controllers/awesome_controller.rb", 17]
|
82
82
|
```
|
83
83
|
|
84
84
|
1. State. One of `APPLIED`, `NO_APPLIED` and `ACTION`.
|
@@ -86,7 +86,7 @@ Normally log is put in this format:
|
|
86
86
|
`NO_APPLIED`: Filter is registered but not executed.
|
87
87
|
`ACTION`: Called action.
|
88
88
|
2. Method name. When filter is a Proc, just put `:Proc`.
|
89
|
-
3. File path.
|
89
|
+
3. File path. In your application directory, it's omitted path. See Configuration section for details.
|
90
90
|
4. Method line no.
|
91
91
|
|
92
92
|
When filter is an object, log is put in this format:
|
@@ -95,7 +95,31 @@ When filter is an object, log is put in this format:
|
|
95
95
|
["UNRECOGNIZED", #<Awesome::Object:0x00007f95c35768f8>]
|
96
96
|
```
|
97
97
|
|
98
|
-
We can't
|
98
|
+
We can't recognize the filter is actually executed or not.
|
99
|
+
|
100
|
+
### Configuration
|
101
|
+
|
102
|
+
To customize how to output log, add `config/initializers/action_tracer.rb`:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
ActionTracer.configure do |config|
|
106
|
+
# when you want to omit source_location path
|
107
|
+
config.omitted_source_location_paths = ["#{Dir.pwd}/"]
|
108
|
+
# e.g.
|
109
|
+
# config.omitted_source_location_paths = []
|
110
|
+
# ["APPLIED", :require_login, "/Users/makicamel/works/github.com/makicamel/myapp/app/controllers/awesome_controller.rb", 17]
|
111
|
+
# config.omitted_source_location_paths = ["#{Dir.pwd}/"]
|
112
|
+
# ["APPLIED", :require_login, "app/controllers/awesome_controller.rb", 17]
|
113
|
+
|
114
|
+
# when you want to output log to stdout
|
115
|
+
config.logger = Rails.logger
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
- `omitted_source_location_paths`: Omitted source_location path. In default `["#{Dir.pwd}/"]`.
|
120
|
+
- `logger`: Injectable logger. For example, to specify to output log to stdout.
|
121
|
+
- `directory`: The directory to put log. In default `/log/`.
|
122
|
+
- `file_name`: The log file name. In default `action_tracer.log`.
|
99
123
|
|
100
124
|
## CommingFeatures
|
101
125
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionTracer
|
4
|
+
class Configration
|
5
|
+
attr_writer :app_path, :directory, :file_name, :logger, :omitted_source_location_paths
|
6
|
+
|
7
|
+
def app_path
|
8
|
+
@app_path ||= Dir.pwd
|
9
|
+
end
|
10
|
+
|
11
|
+
def directory
|
12
|
+
@directory ||= '/log/'
|
13
|
+
end
|
14
|
+
|
15
|
+
def file_name
|
16
|
+
@file_name ||= 'action_tracer.log'
|
17
|
+
end
|
18
|
+
|
19
|
+
def logger
|
20
|
+
@logger ||= Logger.new(app_path + directory + file_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def omitted_source_location_paths
|
24
|
+
@omitted_source_location_paths ||= ["#{Dir.pwd}/"]
|
25
|
+
end
|
26
|
+
|
27
|
+
def omitted_source_location_path
|
28
|
+
@omitted_source_location_path ||= %r{#{omitted_source_location_paths.join('|')}}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class << self
|
33
|
+
def configure
|
34
|
+
yield config
|
35
|
+
end
|
36
|
+
|
37
|
+
def config
|
38
|
+
@config ||= Configration.new
|
39
|
+
end
|
40
|
+
|
41
|
+
def logger
|
42
|
+
@logger ||= @config.logger
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -7,19 +7,30 @@ module ActionTracer
|
|
7
7
|
PROC = :Proc
|
8
8
|
attr_reader :applied
|
9
9
|
|
10
|
-
def initialize(filter, method:)
|
10
|
+
def initialize(filter, kind:, method:)
|
11
11
|
@filter = filter.is_a?(Symbol) ? filter : PROC
|
12
|
+
@kind = kind
|
12
13
|
@method = method
|
13
14
|
@applied = ActionTracer.applied_filters.include? filter
|
14
15
|
end
|
15
16
|
|
16
17
|
def to_a
|
17
18
|
if @method.respond_to? :source_location
|
18
|
-
|
19
|
+
source_location, line_number = *@method.source_location
|
20
|
+
source_location = source_location.sub(::ActionTracer.config.omitted_source_location_path, '')
|
21
|
+
[APPLIED[@applied], @filter, source_location, line_number].compact
|
19
22
|
else
|
20
23
|
[APPLIED[:unrecognized], @method]
|
21
24
|
end
|
22
25
|
end
|
26
|
+
|
27
|
+
def before?
|
28
|
+
@kind == :before || @kind == :around
|
29
|
+
end
|
30
|
+
|
31
|
+
def after?
|
32
|
+
@kind == :after || @kind == :around
|
33
|
+
end
|
23
34
|
end
|
24
35
|
|
25
36
|
class Action
|
@@ -34,7 +45,9 @@ module ActionTracer
|
|
34
45
|
end
|
35
46
|
|
36
47
|
def to_a
|
37
|
-
|
48
|
+
source_location, line_number = *@method.source_location
|
49
|
+
source_location = source_location.sub(::ActionTracer.config.omitted_source_location_path, '')
|
50
|
+
[APPLIED[:action], @name, source_location, line_number].compact
|
38
51
|
end
|
39
52
|
|
40
53
|
def self.nil_method
|
@@ -44,23 +57,23 @@ module ActionTracer
|
|
44
57
|
end
|
45
58
|
|
46
59
|
class Filters
|
47
|
-
def initialize(
|
48
|
-
@
|
49
|
-
@after = after
|
50
|
-
@around = around
|
60
|
+
def initialize(filters:, action:)
|
61
|
+
@filters = filters
|
51
62
|
@action = action
|
52
63
|
end
|
53
64
|
|
54
65
|
class << self
|
55
66
|
def build(controller)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
67
|
+
raw_filters = controller.__callbacks[:process_action].__send__(:chain)
|
68
|
+
filters = raw_filters.map do |raw_filter|
|
69
|
+
filter = raw_filter.__send__(filter_method)
|
70
|
+
Filter.new(
|
71
|
+
filter,
|
72
|
+
kind: raw_filter.kind,
|
73
|
+
method: filter.is_a?(Symbol) ? controller.method(filter) : filter
|
74
|
+
)
|
62
75
|
end
|
63
|
-
new(filters
|
76
|
+
new(filters: filters, action: Action.build(controller))
|
64
77
|
end
|
65
78
|
|
66
79
|
private
|
@@ -73,17 +86,17 @@ module ActionTracer
|
|
73
86
|
def print
|
74
87
|
invoked_before.map(&:to_a).each { |filter| ActionTracer.logger.info filter }
|
75
88
|
ActionTracer.logger.info @action.to_a
|
76
|
-
invoked_after.map(&:to_a).
|
89
|
+
invoked_after.map(&:to_a).each { |filter| ActionTracer.logger.info filter }
|
77
90
|
end
|
78
91
|
|
79
92
|
private
|
80
93
|
|
81
94
|
def invoked_before
|
82
|
-
@before
|
95
|
+
@filters.select(&:before?)
|
83
96
|
end
|
84
97
|
|
85
98
|
def invoked_after
|
86
|
-
@after
|
99
|
+
@filters.select(&:after?).reverse
|
87
100
|
end
|
88
101
|
end
|
89
102
|
end
|
@@ -12,11 +12,11 @@ module ActionTracer
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def make_lambda
|
15
|
-
super >> proc { ActionTracer.applied_filters << @method_name }
|
15
|
+
super >> proc { |result| ActionTracer.applied_filters << @method_name; result }
|
16
16
|
end
|
17
17
|
|
18
18
|
def inverted_lambda
|
19
|
-
super >> proc { ActionTracer.applied_filters << @method_name }
|
19
|
+
super >> proc { |result| ActionTracer.applied_filters << @method_name; result }
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -26,11 +26,11 @@ module ActionTracer
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def make_lambda
|
29
|
-
super >> proc { ActionTracer.applied_filters << @override_target }
|
29
|
+
super >> proc { |result| ActionTracer.applied_filters << @override_target; result }
|
30
30
|
end
|
31
31
|
|
32
32
|
def inverted_lambda
|
33
|
-
super >> proc { ActionTracer.applied_filters << @override_target }
|
33
|
+
super >> proc { |result| ActionTracer.applied_filters << @override_target; result }
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -40,11 +40,11 @@ module ActionTracer
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def make_lambda
|
43
|
-
super >> proc { ActionTracer.applied_filters << @override_block }
|
43
|
+
super >> proc { |result| ActionTracer.applied_filters << @override_block; result }
|
44
44
|
end
|
45
45
|
|
46
46
|
def inverted_lambda
|
47
|
-
super >> proc { ActionTracer.applied_filters << @override_block }
|
47
|
+
super >> proc { |result| ActionTracer.applied_filters << @override_block; result }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
else
|
@@ -3,22 +3,6 @@
|
|
3
3
|
require "forwardable"
|
4
4
|
|
5
5
|
module ActionTracer
|
6
|
-
class Config
|
7
|
-
attr_reader :path
|
8
|
-
|
9
|
-
def initialize(directory:, file:)
|
10
|
-
@path = directory + file
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.app_path
|
15
|
-
@app_path ||= Dir.pwd
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.config(directory: "/log/", file: "action_tracer.log")
|
19
|
-
@config ||= Config.new(directory: app_path + directory, file: file)
|
20
|
-
end
|
21
|
-
|
22
6
|
class Railtie < ::Rails::Railtie
|
23
7
|
initializer "action_tracer" do
|
24
8
|
ActiveSupport.on_load(:action_controller) do
|
data/lib/action_tracer.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_tracer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- makicamel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -89,8 +89,8 @@ files:
|
|
89
89
|
- bin/setup
|
90
90
|
- lib/action_tracer.rb
|
91
91
|
- lib/action_tracer/action_tracer.rb
|
92
|
+
- lib/action_tracer/configuration.rb
|
92
93
|
- lib/action_tracer/filters.rb
|
93
|
-
- lib/action_tracer/logger.rb
|
94
94
|
- lib/action_tracer/monkey_patches/abstract_controller/callbacks.rb
|
95
95
|
- lib/action_tracer/monkey_patches/active_support/callbacks.rb
|
96
96
|
- lib/action_tracer/railtie.rb
|
data/lib/action_tracer/logger.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "forwardable"
|
4
|
-
|
5
|
-
module ActionTracer
|
6
|
-
class Logger < ActiveSupport::LogSubscriber
|
7
|
-
extend Forwardable
|
8
|
-
def_delegators :@logger, :info
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@logger = ::Logger.new(ActionTracer.config.path)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.logger
|
16
|
-
@logger ||= Logger.new
|
17
|
-
end
|
18
|
-
end
|