clickable_logger 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5aab30a3ed08fd243495a540006b36829dfb64ef625de5b8f354e9d8ba6c9a16
4
+ data.tar.gz: 2d0b246a1f3b7547bdb90b37f3ce7cd6684456565e2560380321cecf96c87189
5
+ SHA512:
6
+ metadata.gz: fb611085d3f5d501fe75ee16b07abbaf17f518c461b4f6251594d6628640ed7964dc74d96cb6540d226ddfd051eacc2abc820315bef33257e34be7ed124c8fc2
7
+ data.tar.gz: d764f5923b31c64ff49263005b24b059ea8e3dff05b723ceb081defa74fb475eac44f6f9f951b12b188508c2a75b20d04d52b05ad7bfebc4f45eb90f635e1e37
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Kasvit
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,65 @@
1
+ # ClickableLogger
2
+
3
+ Increase your productivity in 30 seconds.
4
+
5
+ ClickableLogger is a Rails logger formatter that makes it easy to navigate to the code from the logs.
6
+
7
+ And now you can click "Cmd+Click" on the log message to open the file in your editor.
8
+
9
+ ## Before & After
10
+
11
+ Before:
12
+
13
+ ![Before](./docs/before.png)
14
+
15
+ After:
16
+
17
+ ![After](./docs/after.png)
18
+
19
+ ## Usage
20
+
21
+ 30 seconds to get started:
22
+
23
+ 1. Install the gem
24
+ 2. Generate the initializer
25
+ 3. Start the server
26
+
27
+
28
+ ## Installation
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem "clickable_logger", group: :development
33
+ ```
34
+
35
+ And then execute:
36
+ ```bash
37
+ $ bundle
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ ```bash
43
+ rails g clickable_logger:install
44
+ ```
45
+
46
+ This will create a `config/initializers/clickable_logger.rb` file.
47
+
48
+ ## Testing
49
+
50
+ Run tests with:
51
+ ```bash
52
+ bin/test
53
+ ```
54
+
55
+ ## Contributing
56
+
57
+ You are welcome to contribute to the project.
58
+
59
+ Some ideas:
60
+
61
+ - more matchers
62
+ - more tests
63
+
64
+ ## License
65
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClickableLogger
4
+ module Formatter
5
+ OSC_LINK_PREFIX = "\e]8;;"
6
+
7
+ def call(severity, timestamp, progname, msg)
8
+ text = super(severity, timestamp, progname, msg)
9
+
10
+ # Skip if already hyperlinked
11
+ return text if text.include?(OSC_LINK_PREFIX)
12
+
13
+ # Apply matchers
14
+ ClickableLogger.matchers.reduce(text) do |curr, matcher|
15
+ matcher.match?(curr) ? matcher.process(curr) : curr
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClickableLogger
4
+ class Matcher
5
+ def match?(_msg)
6
+ false
7
+ end
8
+
9
+ def process(msg, _config)
10
+ msg
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClickableLogger
4
+ module Matchers
5
+ class ViewMatcher < Matcher
6
+ VIEW_REGEX = /(?:Rendering|Rendered)\s+(?:layout\s+)?(?<file>\S+?\.[^\s]+)/.freeze
7
+
8
+ def match?(msg)
9
+ msg =~ VIEW_REGEX
10
+ end
11
+
12
+ def process(msg)
13
+ msg.gsub(VIEW_REGEX) do |match|
14
+ file = Regexp.last_match[:file]
15
+ # all views are in <controller>/<action>.html.erb
16
+ full_path = file.include?("/") ? ClickableLogger.code_path.find { |path| path.end_with?(file) } : nil
17
+ full_path ? match.sub(file, full_path) : match
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClickableLogger
4
+ class Railtie < ::Rails::Railtie
5
+ initializer "clickable_logger.configure_logger" do |app|
6
+ ClickableLogger.code_path = Dir.glob("#{Rails.root}/app/**/*.*").map { |p| p.gsub("#{Rails.root}/", "") }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClickableLogger
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,20 @@
1
+ require "clickable_logger/version"
2
+ require "clickable_logger/railtie"
3
+ require "clickable_logger/matcher"
4
+ require "clickable_logger/matchers/view_matcher"
5
+ require "clickable_logger/formatter"
6
+
7
+ module ClickableLogger
8
+ # this will be set by the railtie
9
+ mattr_accessor :code_path # Rails.root/app/**/*.*
10
+
11
+ mattr_accessor :matchers
12
+ @@matchers = [
13
+ Matchers::ViewMatcher.new
14
+ ]
15
+
16
+ # for the future
17
+ def self.configure
18
+ yield self
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClickableLogger
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ def copy_initializer
9
+ template "clickable_logger.rb", "config/initializers/clickable_logger.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # extend the logger formatter to add clickable links to the log messages
2
+
3
+ if defined?(ClickableLogger)
4
+ Rails.logger.formatter.class.send(:prepend, ClickableLogger::Formatter)
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :clickable_logger do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: clickable_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kasvit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-05-17 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: '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: debug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Clickable logger for Rails logs in your editor
42
+ email:
43
+ - kasvit93@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE.txt
49
+ - README.md
50
+ - Rakefile
51
+ - lib/clickable_logger.rb
52
+ - lib/clickable_logger/formatter.rb
53
+ - lib/clickable_logger/matcher.rb
54
+ - lib/clickable_logger/matchers/view_matcher.rb
55
+ - lib/clickable_logger/railtie.rb
56
+ - lib/clickable_logger/version.rb
57
+ - lib/generators/clickable_logger/install_generator.rb
58
+ - lib/generators/clickable_logger/templates/clickable_logger.rb
59
+ - lib/tasks/clickable_logger_tasks.rake
60
+ homepage: https://github.com/kasvit/clickable_logger
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ homepage_uri: https://github.com/kasvit/clickable_logger
65
+ source_code_uri: https://github.com/kasvit/clickable_logger
66
+ changelog_uri: https://github.com/kasvit/clickable_logger/blob/main/CHANGELOG.md
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.1.6
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Clickable logger for Rails
86
+ test_files: []