emoji_log 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/MIT-LICENSE +20 -0
- data/README.md +50 -0
- data/Rakefile +13 -0
- data/app/assets/javascripts/emoji_log.js +41 -0
- data/lib/emoji_log/railtie.rb +13 -0
- data/lib/emoji_log/version.rb +3 -0
- data/lib/emoji_log.rb +90 -0
- data/lib/tasks/emoji_log_tasks.rake +4 -0
- metadata +68 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d56a86c32047fa7df7c1c30e0d6077d693db86ea6410396c840f5b30a7acc97c
|
|
4
|
+
data.tar.gz: 7e839f2823b5f142a73a70bcb7a882587d24cbbb0b2aab88b3b75417b90477d3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 42de46414b0ab4526c06ac6431ce6ebe378b4a725e397ebdc4f8d45a73c848c9015a575f5c56e9cdec8ff9f23f9edde2f851f79b14c4a5ef939d4c37e3a12259
|
|
7
|
+
data.tar.gz: 139c91f6eaa263e09101ca1567102b3723eaeb8ea62c8fe50b51a2b2a9b19e7b2abda189fe184dfc9f66cf31344de5d4e695b571b84256121345b122d31e9562
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2023 JP Camara
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# EmojiLog
|
|
2
|
+
|
|
3
|
+
A LogSubscriber for Rails that modifies controller logs with emojis to represent performance (🐢, 🐇, 🚀) and http status codes (🧠, ✅, 🔁, ❌, 🔥, ❓).
|
|
4
|
+
|
|
5
|
+
Inspired by an episode of the Syntax podcast.
|
|
6
|
+
|
|
7
|
+
> I wrote this really nice little handy middleware... that analyzes all my requests as they go, just timing them - and based on how long the request takes it gives me different emoji. So if the request is really fast it's a 🚀, if it's kinda fast it's a 🐇, if it's slow it's a 🐢. ...In my console while I'm just browsing the site I can just see - and it has what type of request, what path it was too, and it's just like at a glance I can see - 'oh I'm in turtle time right now - these requests to this page are all slow for some reason let me take a look'
|
|
8
|
+
>
|
|
9
|
+
> Scott Tolinski
|
|
10
|
+
> Syntax Podcast, Episode 570 - https://syntax.fm/show/570/node-js-cjs-esm
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```rb
|
|
15
|
+
config.after_initialize do
|
|
16
|
+
EmojiLog.slow = "🐢"
|
|
17
|
+
EmojiLog.average = "🐇"
|
|
18
|
+
EmojiLog.fast = "🚀"
|
|
19
|
+
EmojiLog.slow_threshold = 1000
|
|
20
|
+
EmojiLog.average_threshold = 500
|
|
21
|
+
EmojiLog.fast_threshold = 150
|
|
22
|
+
|
|
23
|
+
EmojiLog.info = "🧠"
|
|
24
|
+
EmojiLog.success = "✅"
|
|
25
|
+
EmojiLog.redirect = "🔁"
|
|
26
|
+
EmojiLog.bad = "❌"
|
|
27
|
+
EmojiLog.error = "🔥"
|
|
28
|
+
EmojiLog.cancelled = "❓"
|
|
29
|
+
end
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
Add this line to your application's Gemfile:
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
gem "emoji_log"
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
And then execute:
|
|
40
|
+
```bash
|
|
41
|
+
$ bundle
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Or install it yourself as:
|
|
45
|
+
```bash
|
|
46
|
+
$ gem install emoji_log
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const origOpen = XMLHttpRequest.prototype.open;
|
|
3
|
+
XMLHttpRequest.prototype.open = function () {
|
|
4
|
+
const start = new Date();
|
|
5
|
+
const url = arguments[1];
|
|
6
|
+
this.addEventListener(`load`, () => {
|
|
7
|
+
const end = new Date().getTime() - start.getTime();
|
|
8
|
+
// logTiming(url, end, this.status);
|
|
9
|
+
});
|
|
10
|
+
origOpen.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
|
|
14
|
+
function logTiming(url, end, statusCode) {
|
|
15
|
+
const status = statusEmoji(statusCode);
|
|
16
|
+
if (end <= 200) {
|
|
17
|
+
console.log(url, `🚀`, `${end}ms`, status);
|
|
18
|
+
} else if (end <= 500) {
|
|
19
|
+
console.log(url, `🐇`, `${end}ms`, status);
|
|
20
|
+
} else {
|
|
21
|
+
console.log(url, `🐢`, `${end}ms`, status);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// eslint-disable-next-line complexity
|
|
26
|
+
function statusEmoji(status) {
|
|
27
|
+
if (status < 100) {
|
|
28
|
+
return `❓`;
|
|
29
|
+
} else if (status < 200) {
|
|
30
|
+
return `🧠`;
|
|
31
|
+
} else if (status < 300) {
|
|
32
|
+
return `✅`;
|
|
33
|
+
} else if (status < 400) {
|
|
34
|
+
return `🔄`;
|
|
35
|
+
} else if (status < 500) {
|
|
36
|
+
return `❌`;
|
|
37
|
+
} else if (status < 600) {
|
|
38
|
+
return `🔥`;
|
|
39
|
+
}
|
|
40
|
+
return ``;
|
|
41
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/railtie'
|
|
4
|
+
require 'action_view/log_subscriber'
|
|
5
|
+
require 'action_controller/log_subscriber'
|
|
6
|
+
|
|
7
|
+
module EmojiLog
|
|
8
|
+
class Railtie < ::Rails::Railtie
|
|
9
|
+
config.after_initialize do |app|
|
|
10
|
+
EmojiLog.setup(app)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
data/lib/emoji_log.rb
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require "emoji_log/version"
|
|
2
|
+
require "emoji_log/railtie"
|
|
3
|
+
|
|
4
|
+
module EmojiLog
|
|
5
|
+
def self.setup(app)
|
|
6
|
+
# self.application = app
|
|
7
|
+
EmojiLog.slow = "🐢"
|
|
8
|
+
EmojiLog.average = "🐇"
|
|
9
|
+
EmojiLog.fast = "🚀"
|
|
10
|
+
EmojiLog.slow_threshold = 1000
|
|
11
|
+
EmojiLog.average_threshold = 500
|
|
12
|
+
EmojiLog.fast_threshold = 150
|
|
13
|
+
|
|
14
|
+
EmojiLog.info = "🧠"
|
|
15
|
+
EmojiLog.success = "✅"
|
|
16
|
+
EmojiLog.redirect = "🔁"
|
|
17
|
+
EmojiLog.bad = "❌"
|
|
18
|
+
EmojiLog.error = "🔥"
|
|
19
|
+
EmojiLog.cancelled = "❓"
|
|
20
|
+
|
|
21
|
+
::EmojiLog::ActionController.attach_to :action_controller
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class << self
|
|
25
|
+
attr_accessor :slow, :average, :fast, :slow_threshold, :average_threshold, :fast_threshold,
|
|
26
|
+
:info, :success, :redirect, :bad, :error, :cancelled
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class ActionController < ActiveSupport::LogSubscriber
|
|
30
|
+
ONE = 100...199
|
|
31
|
+
TWO = 200...299
|
|
32
|
+
THREE = 300...399
|
|
33
|
+
FOUR = 400...499
|
|
34
|
+
FIVE = 500...599
|
|
35
|
+
|
|
36
|
+
def process_action(event)
|
|
37
|
+
info do
|
|
38
|
+
payload = event.payload
|
|
39
|
+
additions = ::ActionController::Base.log_process_action(payload)
|
|
40
|
+
status = payload[:status]
|
|
41
|
+
|
|
42
|
+
if status.nil? && (exception_class_name = payload[:exception]&.first)
|
|
43
|
+
status = ::ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
additions << "Allocations: #{event.allocations}"
|
|
47
|
+
|
|
48
|
+
speed_emoji = emoji_speed(event)
|
|
49
|
+
status_emoji = emoji_status(status)
|
|
50
|
+
|
|
51
|
+
message = +"#{speed_emoji * 3} [#{payload[:path]}] Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}#{status_emoji} in #{event.duration.round}ms" \
|
|
52
|
+
" (#{additions.join(" | ")})"
|
|
53
|
+
message << "\n\n" if defined?(::Rails.env) && ::Rails.env.development?
|
|
54
|
+
|
|
55
|
+
message
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def emoji_status(status)
|
|
60
|
+
case status
|
|
61
|
+
when ONE
|
|
62
|
+
" #{EmojiLog.info}"
|
|
63
|
+
when TWO
|
|
64
|
+
" #{EmojiLog.success}"
|
|
65
|
+
when THREE
|
|
66
|
+
" #{EmojiLog.redirect}"
|
|
67
|
+
when FOUR
|
|
68
|
+
" #{EmojiLog.bad}"
|
|
69
|
+
when FIVE
|
|
70
|
+
" #{EmojiLog.error}"
|
|
71
|
+
when 0
|
|
72
|
+
" #{EmojiLog.cancelled}"
|
|
73
|
+
else
|
|
74
|
+
""
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def emoji_speed(event)
|
|
79
|
+
if event.duration <= EmojiLog.fast_threshold
|
|
80
|
+
EmojiLog.fast
|
|
81
|
+
elsif event.duration <= EmojiLog.average_threshold
|
|
82
|
+
EmojiLog.average
|
|
83
|
+
else
|
|
84
|
+
EmojiLog.slow
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
require 'emoji_log/railtie' if defined?(Rails)
|
metadata
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: emoji_log
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- JP Camara
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-03-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5.0'
|
|
27
|
+
description: Quickly scan your logs using the power of emojis.
|
|
28
|
+
email:
|
|
29
|
+
- 48120+jpcamara@users.noreply.github.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- MIT-LICENSE
|
|
35
|
+
- README.md
|
|
36
|
+
- Rakefile
|
|
37
|
+
- app/assets/javascripts/emoji_log.js
|
|
38
|
+
- lib/emoji_log.rb
|
|
39
|
+
- lib/emoji_log/railtie.rb
|
|
40
|
+
- lib/emoji_log/version.rb
|
|
41
|
+
- lib/tasks/emoji_log_tasks.rake
|
|
42
|
+
homepage: https://github.com/jpcamara/emoji_log
|
|
43
|
+
licenses:
|
|
44
|
+
- MIT
|
|
45
|
+
metadata:
|
|
46
|
+
homepage_uri: https://github.com/jpcamara/emoji_log
|
|
47
|
+
source_code_uri: https://github.com/jpcamara/emoji_log
|
|
48
|
+
changelog_uri: https://github.com/jpcamara/emoji_log
|
|
49
|
+
post_install_message:
|
|
50
|
+
rdoc_options: []
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
requirements: []
|
|
64
|
+
rubygems_version: 3.4.6
|
|
65
|
+
signing_key:
|
|
66
|
+
specification_version: 4
|
|
67
|
+
summary: Quickly scan your logs using the power of emojis.
|
|
68
|
+
test_files: []
|