action_tracer 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +77 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +142 -0
- data/Rakefile +8 -0
- data/TAGS +42 -0
- data/action_tracer.gemspec +30 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/action_tracer.rb +7 -0
- data/lib/action_tracer/action_tracer.rb +41 -0
- data/lib/action_tracer/filters.rb +59 -0
- data/lib/action_tracer/logger.rb +18 -0
- data/lib/action_tracer/monkey_patches/abstract_controller/callbacks.rb +15 -0
- data/lib/action_tracer/railtie.rb +32 -0
- data/lib/action_tracer/version.rb +5 -0
- metadata +134 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e6886a0826048909019cd75d52f9ea682833b56addca3f7cd7636e313fe1c79b
|
|
4
|
+
data.tar.gz: e2f352937846c839de2837534f5b60be2c210623182d1a24d4d06323d35c8e0f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: '075917e7971d4b75385e425ca49428fc63093cfb4496fe96fd30d84e8e23a382d5ffe77a8b8c4950031528f2f67d01f8b967d44216104add9399dc63d3572a21'
|
|
7
|
+
data.tar.gz: fabc09fb2d4911362b9c732603e9901cfda1807c01a682b5c69fd2c40932707009faa2836f21e4dbf797a9bb10bc5e689662442ef8946de94190e94f4dfec9d0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.6
|
|
3
|
+
|
|
4
|
+
Layout/EmptyLineAfterMagicComment:
|
|
5
|
+
Enabled: true
|
|
6
|
+
|
|
7
|
+
Layout/EmptyLineBetweenDefs:
|
|
8
|
+
Enabled: true
|
|
9
|
+
|
|
10
|
+
Layout/EmptyLines:
|
|
11
|
+
Enabled: true
|
|
12
|
+
|
|
13
|
+
Layout/EmptyLinesAroundAccessModifier:
|
|
14
|
+
Enabled: true
|
|
15
|
+
|
|
16
|
+
Layout/EmptyLinesAroundArguments:
|
|
17
|
+
Enabled: true
|
|
18
|
+
|
|
19
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
|
20
|
+
Enabled: true
|
|
21
|
+
|
|
22
|
+
Layout/EmptyLinesAroundBeginBody:
|
|
23
|
+
Enabled: true
|
|
24
|
+
|
|
25
|
+
Layout/EmptyLinesAroundBlockBody:
|
|
26
|
+
Enabled: true
|
|
27
|
+
|
|
28
|
+
Layout/EmptyLinesAroundClassBody:
|
|
29
|
+
Enabled: true
|
|
30
|
+
|
|
31
|
+
Layout/EmptyLinesAroundExceptionHandlingKeywords:
|
|
32
|
+
Enabled: true
|
|
33
|
+
|
|
34
|
+
Layout/EmptyLinesAroundMethodBody:
|
|
35
|
+
Enabled: true
|
|
36
|
+
|
|
37
|
+
Layout/EmptyLinesAroundModuleBody:
|
|
38
|
+
Enabled: true
|
|
39
|
+
|
|
40
|
+
Layout/LeadingEmptyLines:
|
|
41
|
+
Enabled: true
|
|
42
|
+
|
|
43
|
+
Layout/TrailingEmptyLines:
|
|
44
|
+
Enabled: true
|
|
45
|
+
|
|
46
|
+
Layout/TrailingWhitespace:
|
|
47
|
+
Enabled: true
|
|
48
|
+
|
|
49
|
+
Layout/SpaceInLambdaLiteral:
|
|
50
|
+
EnforcedStyle: require_space
|
|
51
|
+
|
|
52
|
+
Layout/MultilineMethodCallIndentation:
|
|
53
|
+
EnforcedStyle: indented
|
|
54
|
+
|
|
55
|
+
Lint/RedundantRequireStatement:
|
|
56
|
+
Enabled: true
|
|
57
|
+
|
|
58
|
+
Lint/UselessComparison:
|
|
59
|
+
Enabled: true
|
|
60
|
+
|
|
61
|
+
Lint/UselessElseWithoutRescue:
|
|
62
|
+
Enabled: true
|
|
63
|
+
|
|
64
|
+
Lint/UselessSetterCall:
|
|
65
|
+
Enabled: true
|
|
66
|
+
|
|
67
|
+
Style/Documentation:
|
|
68
|
+
Enabled: false
|
|
69
|
+
|
|
70
|
+
Style/DocumentationMethod:
|
|
71
|
+
Enabled: false
|
|
72
|
+
|
|
73
|
+
Style/StringLiterals:
|
|
74
|
+
EnforcedStyle: "double_quotes"
|
|
75
|
+
|
|
76
|
+
Style/EndBlock:
|
|
77
|
+
Enabled: true
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
|
File without changes
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at unright@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 makicamel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# ActionTracer
|
|
2
|
+
|
|
3
|
+
Log Rails application actions and filters when accepts a request.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'action_tracer', group :development, :test
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Notice this gem is for Rails with ApplicationController inherited ActiveController::Base.
|
|
14
|
+
Support for Rails application with ActiveController::API is comming soon.
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Run rails server or run rspec with `ACTION_TRACER=1` to log actions and filters for `log/action_tracer.log`.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
$ ACTION_TRACER=1 rails server
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
You can also run rspec for your request specs.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
$ ACTION_TRACER=1 rspec
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
If you use docker-compose, pass environment variable:
|
|
31
|
+
|
|
32
|
+
```yml
|
|
33
|
+
version: 3
|
|
34
|
+
services:
|
|
35
|
+
web:
|
|
36
|
+
build: .
|
|
37
|
+
command: bundle exec rails s -p 3000
|
|
38
|
+
environment:
|
|
39
|
+
ACTION_TRACER: 1
|
|
40
|
+
volumes:
|
|
41
|
+
# ...
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Example
|
|
45
|
+
|
|
46
|
+
For example, you have a simple `awesome_controller.rb` like this:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
class AwesomeController < ApplicationController
|
|
50
|
+
before_action :require_login
|
|
51
|
+
before_action :set_awesome, only: :show
|
|
52
|
+
around_action :with_readonly
|
|
53
|
+
after_action :store_location
|
|
54
|
+
|
|
55
|
+
def index
|
|
56
|
+
# ...
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def show
|
|
60
|
+
# ...
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def require_login
|
|
66
|
+
# ...
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def with_readonly
|
|
70
|
+
# ...
|
|
71
|
+
yield
|
|
72
|
+
# ...
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def store_location
|
|
76
|
+
# ...
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
When you run rails server with `ACTION_TRACER=1` and access `/awesome` (action is `#index`),
|
|
82
|
+
it will put logs for `log/action_tracer.log` like this:
|
|
83
|
+
|
|
84
|
+
```log
|
|
85
|
+
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]
|
|
86
|
+
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]
|
|
87
|
+
I, [2020-09-27T03:25:43.021131 #1] INFO -- : ["APPLIED", :require_login, "/myapp/app/controllers/awesome_controller.rb", 17]
|
|
88
|
+
I, [2020-09-27T03:25:43.022063 #1] INFO -- : ["NO_APPLIED", :set_awesome, "/myapp/app/controllers/awesome_controller.rb", 25]
|
|
89
|
+
I, [2020-09-27T03:25:43.023716 #1] INFO -- : ["APPLIED", :with_readonly, "/myapp/app/controllers/awesome_controller.rb", 21]
|
|
90
|
+
I, [2020-09-27T03:25:43.025547 #1] INFO -- : ["ACTION", :index, "/myapp/app/controllers/awesome_controller.rb", 7]
|
|
91
|
+
I, [2020-09-27T03:25:43.026297 #1] INFO -- : ["APPLIED", :with_readonly, "/myapp/app/controllers/awesome_controller.rb", 21]
|
|
92
|
+
I, [2020-09-27T03:25:43.027203 #1] INFO -- : ["APPLIED", :store_location, "/myapp/app/controllers/awesome_controller.rb", 27]
|
|
93
|
+
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]
|
|
94
|
+
I, [2020-09-27T03:25:43.030776 #1] INFO -- :
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Filters are put in the order in which is executed.
|
|
98
|
+
Notice `around_action` is put 2 times around action though called 1 time.
|
|
99
|
+
|
|
100
|
+
### Log Guide
|
|
101
|
+
|
|
102
|
+
Normally log is put in this format:
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
["APPLIED", :require_login, "/myapp/app/controllers/awesome_controller.rb", 17]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
1. State. One of `APPLIED`, `NO_APPLIED` and `ACTION`.
|
|
109
|
+
`APPLIED`: Filter is executed.
|
|
110
|
+
`NO_APPLIED`: Filter is registered but not executed.
|
|
111
|
+
`ACTION`: Called action.
|
|
112
|
+
2. Method name. When filter is a Proc, just put `:Proc`.
|
|
113
|
+
3. File path. It's absolute path.
|
|
114
|
+
4. Method line no.
|
|
115
|
+
|
|
116
|
+
When filter is an object, log is put in this format:
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
["UNRECOGNIZED", #<Awesome::Object:0x00007f95c35768f8>]
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
We can't recgnize the filter is actually executed or not.
|
|
123
|
+
|
|
124
|
+
## CommingFeatures
|
|
125
|
+
|
|
126
|
+
- Support for Rails application with ActiveController::API
|
|
127
|
+
- Add non-checking mode
|
|
128
|
+
- Memorizing filters are applied or not is very costly.
|
|
129
|
+
Add non-checking mode filters are actually applied or not.
|
|
130
|
+
- Log rotate
|
|
131
|
+
|
|
132
|
+
## Contributing
|
|
133
|
+
|
|
134
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/makicamel/action_tracer. This project is intended to be a safe, welcoming space for collaboration.
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
139
|
+
|
|
140
|
+
## Code of Conduct
|
|
141
|
+
|
|
142
|
+
Everyone interacting in the ActionTracer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/makicamel/action_tracer/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/TAGS
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
lib/action_tracer/monkey_patches/abstract_controller/base.rb,433
|
|
3
|
+
module ActionTracerActionTracer3,0
|
|
4
|
+
module MonkeyPatchesMonkeyPatches4,0
|
|
5
|
+
module MonkeyPatchesActionTracer::MonkeyPatches4,0
|
|
6
|
+
module AbstractControllerAbstractController5,0
|
|
7
|
+
module AbstractControllerActionTracer::MonkeyPatches::AbstractController5,0
|
|
8
|
+
module BaseBase6,0
|
|
9
|
+
module BaseActionTracer::MonkeyPatches::AbstractController::Base6,0
|
|
10
|
+
def process_action(action, *args)process_action10,0
|
|
11
|
+
|
|
12
|
+
lib/action_tracer/railtie.rb,408
|
|
13
|
+
module ActionTracerActionTracer5,0
|
|
14
|
+
class ConfigConfig6,0
|
|
15
|
+
class ConfigActionTracer::Config6,0
|
|
16
|
+
attr_reader :pathpath7,0
|
|
17
|
+
def initialize(directory:, file:)initialize9,0
|
|
18
|
+
def self.app_pathapp_path14,0
|
|
19
|
+
def self.config(directory: "/log/", file: "action_tracer.log")config18,0
|
|
20
|
+
class Railtie < ::Rails::RailtieRailtie22,0
|
|
21
|
+
class Railtie < ::Rails::RailtieActionTracer::Railtie22,0
|
|
22
|
+
|
|
23
|
+
lib/action_tracer/logger.rb,274
|
|
24
|
+
module ActionTracerActionTracer5,0
|
|
25
|
+
class Logger < ActiveSupport::LogSubscriberLogger6,0
|
|
26
|
+
class Logger < ActiveSupport::LogSubscriberActionTracer::Logger6,0
|
|
27
|
+
def_delegators :@logger, :infoinfo8,0
|
|
28
|
+
def initializeinitialize10,0
|
|
29
|
+
def self.loggerlogger15,0
|
|
30
|
+
|
|
31
|
+
lib/action_tracer/action_tracer.rb,37
|
|
32
|
+
module ActionTracerActionTracer3,0
|
|
33
|
+
|
|
34
|
+
lib/action_tracer/file_path_checker.rb,141
|
|
35
|
+
module ActionTracerActionTracer3,0
|
|
36
|
+
module FilePathCheckerFilePathChecker4,0
|
|
37
|
+
module FilePathCheckerActionTracer::FilePathChecker4,0
|
|
38
|
+
|
|
39
|
+
lib/action_tracer/version.rb,115
|
|
40
|
+
module ActionTracerActionTracer3,0
|
|
41
|
+
VERSION = "0.1.0"VERSION4,0
|
|
42
|
+
VERSION = "0.1.0"ActionTracer::VERSION4,0
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require "action_tracer/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "action_tracer"
|
|
9
|
+
spec.version = ActionTracer::VERSION
|
|
10
|
+
spec.authors = ["makicamel"]
|
|
11
|
+
spec.email = ["unright@gmail.com"]
|
|
12
|
+
spec.homepage = "https://github.com/makicamel/action_tracer"
|
|
13
|
+
spec.summary = "Log Rails application actions and filters when accepts a request"
|
|
14
|
+
spec.description = "Log Rails application actions and filters when accepts a request"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| 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 "actionpack"
|
|
26
|
+
|
|
27
|
+
spec.add_development_dependency "bundler"
|
|
28
|
+
spec.add_development_dependency "rake"
|
|
29
|
+
spec.add_development_dependency "rspec"
|
|
30
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "action_tracer"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require "irb"
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActionTracer
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
def log(controller)
|
|
8
|
+
filter_collector.enable
|
|
9
|
+
result = yield
|
|
10
|
+
filter_collector.disable
|
|
11
|
+
Filters.build(controller).print
|
|
12
|
+
applied_filters.clear
|
|
13
|
+
ActionTracer.logger.info ""
|
|
14
|
+
|
|
15
|
+
result
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def filter_collector
|
|
19
|
+
@filter_collector ||= TracePoint.new(:return) do |tp|
|
|
20
|
+
# NOTE: ActiveSupport::Callbacks::CallTemplate is a private class
|
|
21
|
+
if tp.method_id == :expand && tp.defined_class == ActiveSupport::Callbacks::CallTemplate
|
|
22
|
+
if tp.return_value&.first.is_a? ActionController::Base
|
|
23
|
+
# target, block, method, *arguments = tp.return_value
|
|
24
|
+
case tp.return_value[2]
|
|
25
|
+
when :instance_exec # filter is a proc
|
|
26
|
+
applied_filters << tp.return_value[1]
|
|
27
|
+
when String # filter is an object
|
|
28
|
+
applied_filters << tp.return_value[1]
|
|
29
|
+
when Symbol # filter is a method
|
|
30
|
+
applied_filters << tp.return_value[2]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def applied_filters
|
|
38
|
+
@applied_filters ||= []
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActionTracer
|
|
4
|
+
class Filter
|
|
5
|
+
APPLIED = { true => "APPLIED", false => "NO_APPLIED" }.freeze
|
|
6
|
+
PROC = :Proc
|
|
7
|
+
attr_reader :applied
|
|
8
|
+
|
|
9
|
+
def initialize(filter, method:)
|
|
10
|
+
@filter = filter.is_a?(Symbol) ? filter : PROC
|
|
11
|
+
@method = method
|
|
12
|
+
@applied = ActionTracer.applied_filters.include? filter
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_a
|
|
16
|
+
if @method.respond_to? :source_location
|
|
17
|
+
[APPLIED[@applied], @filter, *@method.source_location]
|
|
18
|
+
else
|
|
19
|
+
["UNRECOGNIZED", @method]
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class Filters
|
|
25
|
+
def initialize(before = [], after = [], around = [], action:)
|
|
26
|
+
@before = before
|
|
27
|
+
@after = after
|
|
28
|
+
@around = around
|
|
29
|
+
@action = action
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.build(controller)
|
|
33
|
+
filters = { before: [], after: [], around: [] }
|
|
34
|
+
raw_filters = controller.__callbacks[:process_action].send(:chain).group_by(&:kind)
|
|
35
|
+
raw_filters.each do |kind, filter|
|
|
36
|
+
filters[kind] = filter.map(&:raw_filter).map do |f|
|
|
37
|
+
Filter.new(f, method: f.is_a?(Symbol) ? controller.method(f) : f)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
new(filters[:before], filters[:after], filters[:around], action: controller.method(controller.action_name))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def print
|
|
44
|
+
invoked_before.map(&:to_a).each { |filter| ActionTracer.logger.info filter }
|
|
45
|
+
ActionTracer.logger.info ["ACTION", @action.name, *@action.source_location]
|
|
46
|
+
invoked_after.map(&:to_a).reverse_each { |filter| ActionTracer.logger.info filter }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def invoked_before
|
|
52
|
+
@before + @around
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def invoked_after
|
|
56
|
+
@after + @around
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "forwardable"
|
|
4
|
+
|
|
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
|
+
class Railtie < ::Rails::Railtie
|
|
23
|
+
initializer "action_tracer" do
|
|
24
|
+
ActiveSupport.on_load(:action_controller) do
|
|
25
|
+
require "action_tracer/monkey_patches/abstract_controller/callbacks"
|
|
26
|
+
::ActionController::Base.prepend ActionTracer::MonkeyPatches::AbstractController::Callbacks
|
|
27
|
+
|
|
28
|
+
ActionTracer.config
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: action_tracer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- makicamel
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: actionpack
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: Log Rails application actions and filters when accepts a request
|
|
84
|
+
email:
|
|
85
|
+
- unright@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".gitignore"
|
|
91
|
+
- ".rspec"
|
|
92
|
+
- ".rubocop.yml"
|
|
93
|
+
- ".travis.yml"
|
|
94
|
+
- CHANGELOG.md
|
|
95
|
+
- CODE_OF_CONDUCT.md
|
|
96
|
+
- Gemfile
|
|
97
|
+
- LICENSE.txt
|
|
98
|
+
- README.md
|
|
99
|
+
- Rakefile
|
|
100
|
+
- TAGS
|
|
101
|
+
- action_tracer.gemspec
|
|
102
|
+
- bin/console
|
|
103
|
+
- bin/setup
|
|
104
|
+
- lib/action_tracer.rb
|
|
105
|
+
- lib/action_tracer/action_tracer.rb
|
|
106
|
+
- lib/action_tracer/filters.rb
|
|
107
|
+
- lib/action_tracer/logger.rb
|
|
108
|
+
- lib/action_tracer/monkey_patches/abstract_controller/callbacks.rb
|
|
109
|
+
- lib/action_tracer/railtie.rb
|
|
110
|
+
- lib/action_tracer/version.rb
|
|
111
|
+
homepage: https://github.com/makicamel/action_tracer
|
|
112
|
+
licenses:
|
|
113
|
+
- MIT
|
|
114
|
+
metadata: {}
|
|
115
|
+
post_install_message:
|
|
116
|
+
rdoc_options: []
|
|
117
|
+
require_paths:
|
|
118
|
+
- lib
|
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
|
+
requirements:
|
|
126
|
+
- - ">="
|
|
127
|
+
- !ruby/object:Gem::Version
|
|
128
|
+
version: '0'
|
|
129
|
+
requirements: []
|
|
130
|
+
rubygems_version: 3.1.4
|
|
131
|
+
signing_key:
|
|
132
|
+
specification_version: 4
|
|
133
|
+
summary: Log Rails application actions and filters when accepts a request
|
|
134
|
+
test_files: []
|