rails-pretty-logger 0.2.9 → 0.3.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +215 -35
  3. data/app/assets/javascripts/rails/pretty/logger/application.js +16 -23
  4. data/app/assets/stylesheets/rails/pretty/logger/application.css +1 -15
  5. data/app/assets/stylesheets/rails/pretty/logger/dashboards.css +463 -141
  6. data/app/assets/stylesheets/rails/pretty/logger/list.css +1 -94
  7. data/app/controllers/rails/pretty/logger/application_controller.rb +31 -0
  8. data/app/controllers/rails/pretty/logger/dashboards_controller.rb +9 -4
  9. data/app/controllers/rails/pretty/logger/hourly_logs_controller.rb +36 -4
  10. data/app/helpers/rails/pretty/logger/application_helper.rb +32 -0
  11. data/app/helpers/rails/pretty/logger/dashboards_helper.rb +114 -14
  12. data/app/views/layouts/rails/pretty/logger/application.html.erb +9 -8
  13. data/app/views/partials/_error_pagination.html.erb +12 -10
  14. data/app/views/partials/_log_entries.html.erb +5 -0
  15. data/app/views/partials/_log_filters.html.erb +14 -0
  16. data/app/views/partials/_pretyyloggernavbar.html.erb +14 -9
  17. data/app/views/rails/pretty/logger/dashboards/index.html.erb +37 -20
  18. data/app/views/rails/pretty/logger/dashboards/logs.html.erb +33 -14
  19. data/app/views/rails/pretty/logger/hourly_logs/index.html.erb +49 -25
  20. data/app/views/rails/pretty/logger/hourly_logs/logs.html.erb +35 -14
  21. data/config/locales/rails_pretty_logger.en.yml +35 -0
  22. data/config/locales/rails_pretty_logger.tr.yml +35 -0
  23. data/lib/generators/rails_pretty_logger/install/install_generator.rb +29 -0
  24. data/lib/generators/rails_pretty_logger/install/templates/rails_pretty_logger.rb +20 -0
  25. data/lib/rails/pretty/logger/active_support_logger.rb +3 -7
  26. data/lib/rails/pretty/logger/config/logger_config.rb +0 -16
  27. data/lib/rails/pretty/logger/configuration.rb +18 -0
  28. data/lib/rails/pretty/logger/console_logger.rb +2 -2
  29. data/lib/rails/pretty/logger/engine.rb +22 -4
  30. data/lib/rails/pretty/logger/rails_logger.rb +62 -41
  31. data/lib/rails/pretty/logger/version.rb +1 -1
  32. data/lib/rails/pretty/logger.rb +547 -31
  33. data/lib/tasks/rails/pretty/logger_tasks.rake +36 -23
  34. metadata +79 -38
  35. data/Rakefile +0 -22
  36. data/app/assets/javascripts/rails/pretty/logger/dashboards.js +0 -2
  37. data/app/assets/javascripts/rails/pretty/logger/list.min.js +0 -2
  38. data/app/models/rails/pretty/logger/application_record.rb +0 -9
  39. data/app/assets/config/{rails_pretty_logger_manifest.js → manifest.js} +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11581d7cf70134b2623eeb35225b4098af4bba1b3a3be980c53675c0a5287bf5
4
- data.tar.gz: d09496c5f7a725c73b1439a191766f2ef81de1d7e75be877edf46e6713514b94
3
+ metadata.gz: 3b349a2e93d7e17a110c5aadf4973f914d1f37a357cfb7c5d90c88ad939e2372
4
+ data.tar.gz: 7945dcbafed8fdc6ce349ba544d0c0908b8d75da2362cc2d605276f37d757483
5
5
  SHA512:
6
- metadata.gz: affe4f17285a6e05c29a1f288b8c1ba06ceb4d632b76d7608404162ef9f7d4ace9cca79ecf0948850e4051682add13173efe99536f713246eb3686946a168df2
7
- data.tar.gz: 461fa8378a0583525da0931ce3db1428b2e2afe8ba1ea30e2fe38ca3bc57a0e8d736e2dd90c25c3bbbb0c4d07a96c44d4c2869ace39f7cfa16a6cd00b9c8a310
6
+ metadata.gz: 1747cf60994ce9fb3288d945195a813a76b4971e5a98e436a694b066bc05d8772cc23749907a51543afb9c58ec9b780601037eae6fb7064d22729de08cbfe9d6
7
+ data.tar.gz: 3fe15ee8fdc4d141bcabccfd4ea69f635d07eda077a62a1bd1abbff412931efe88466203c78a39d6fbedd40c1e7ecab0cd8591245abd6e54e8b769187ee9ce15
data/README.md CHANGED
@@ -1,66 +1,246 @@
1
1
  # Rails::Pretty::Logger
2
- Pretty Logger is a logging framework which helps for checking logs from page, with PrettyLogger.highlight method you can easily spot what you seek.If you want to perform hourly log rotation Override logger class with Pretty logger, with file_count parameter kept files can be limited as you wish.
3
2
 
4
- ## Usage
5
- visit http://your-webpage/rails-pretty-logger/dashboards/ then choose your log file, search with date range.
6
- ![](log_file.gif)
3
+ Rails Pretty Logger is a Rails engine for browsing application logs from a mounted dashboard. The current line supports Ruby 3.3+, Rails 7.1, and Rails 8, with log filtering, tailing, request grouping, structured JSON rendering, safe clear actions, and optional hourly log rotation.
4
+
5
+ ## Index
6
+
7
+ - [Feature overview](#feature-overview)
8
+ - [Compatibility](#compatibility)
9
+ - [Installation](#installation)
10
+ - [Usage](#usage)
11
+ - [Dashboard security](#dashboard-security)
12
+ - [Configuration](#configuration)
13
+ - [Custom log formats](#custom-log-formats)
14
+ - [Highlighting](#highlighting)
15
+ - [Hourly log rotation](#hourly-log-rotation)
16
+ - [Performance and safety](#performance-and-safety)
17
+ - [Dependency policy](#dependency-policy)
18
+ - [Asset loading](#asset-loading)
19
+ - [Development and CI](#development-and-ci)
20
+ - [License](#license)
21
+
22
+ ## Feature overview
23
+
24
+ - Mounted Rails engine dashboard for files under `Rails.root/log`.
25
+ - Main log and hourly rotated log browsers.
26
+ - Date range filtering, content search, severity filtering, and configurable pagination.
27
+ - Tail mode that reads the last configured number of lines without loading the whole file.
28
+ - Rails request grouping for `Started ...` / `Completed ...` log blocks.
29
+ - Structured JSON line rendering with extracted timestamp, severity, message, and metadata.
30
+ - Custom parser hook for non-standard log formats.
31
+ - English and Turkish locale files.
32
+ - `[HIGHLIGHT]` helper support for visually marked log entries.
33
+ - Clear log actions with `read_only` protection.
34
+ - Safe log file resolution that rejects missing files, invalid paths, and paths outside the app log directory.
35
+ - Optional file size guard for large logs.
36
+ - Memory and disk-backed line offset indexes for faster pagination and request grouping after the first scan.
37
+
38
+ ## Compatibility
39
+
40
+ | Gem version | Ruby | Rails | Notes |
41
+ | --- | --- | --- | --- |
42
+ | `0.3.x` | `>= 3.3` | `>= 7.1`, `< 9.0` | Current line. CI runs Rails 7.1, 8.0, and 8.1 with Ruby 3.3. |
43
+ | `0.2.8` | `>= 2.2.2` | `>= 5.0`, `<= 6.1.4.1` | Legacy line for older Rails apps. Pin this version if you still need Rails 5 or Rails 6.1 support. |
44
+
45
+ ## Installation
7
46
 
8
- #### How to use debug Highlighter
47
+ Add this line to your application's Gemfile:
9
48
 
49
+ ```ruby
50
+ gem "rails-pretty-logger"
10
51
  ```
11
- PrettyLogger.highlight("lorem ipsum")
52
+
53
+ For Rails 5 or Rails 6.1 applications, pin the legacy version:
54
+
55
+ ```ruby
56
+ gem "rails-pretty-logger", "0.2.8"
57
+ ```
58
+
59
+ Then install the bundle:
60
+
61
+ ```bash
62
+ bundle install
63
+ ```
64
+
65
+ Run the install generator:
66
+
67
+ ```bash
68
+ bin/rails generate rails_pretty_logger:install
12
69
  ```
13
- ![](highlight.gif)
14
70
 
15
- #### Use Hourly Log Rotation
71
+ The generator creates `config/initializers/rails_pretty_logger.rb`, mounts the engine in `config/routes.rb`, and links the engine JavaScript in `app/assets/config/manifest.js` when the host app has a Sprockets manifest.
16
72
 
17
- Add these lines below to environment config file which you want to override its logger, first argument for name of the log file, second argument for keeping hourly logs, file count for limiting the logs files.
73
+ You can also mount the engine manually:
18
74
 
19
- Rails::Pretty::Logger::ConsoleLogger.new("rails-pretty-logger", "hourly", file_count: 48)
75
+ ```ruby
76
+ mount Rails::Pretty::Logger::Engine => "/rails-pretty-logger"
77
+ ```
20
78
 
21
- ```
22
- #/config/environments/development.rb
79
+ ## Usage
23
80
 
24
- require "rails/pretty/logger/config/logger_config"
81
+ Visit `/rails-pretty-logger` or `/rails-pretty-logger/dashboards` after mounting the engine. The exact prefix depends on the path you choose in `config/routes.rb`.
25
82
 
26
- logger_file = ActiveSupport::TaggedLogging.new(Rails::Pretty::Logger::ConsoleLogger.new("rails-pretty-logger", "hourly", file_count: 48))
27
- config.logger = logger_file
28
- ```
29
- ![](hour.gif)
83
+ The dashboard can:
30
84
 
31
- #### Split your old logs by hourly
85
+ - list regular log files from `log/`;
86
+ - list hourly rotated files from `log/hourly/`;
87
+ - filter log lines by date range, content query, and severity;
88
+ - switch between paginated view and tail view;
89
+ - group standard Rails request logs;
90
+ - render JSON line logs as structured entries;
91
+ - clear selected logs when `read_only` is disabled.
32
92
 
33
- If you want split your old log files by hourly you can use this rake task below at terminal
93
+ Severity filtering recognizes `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`, and `UNKNOWN`. For structured JSON logs it checks `severity`, `level`, `log_level`, and nested `log.level` values.
34
94
 
35
- argument takes what will be new files names start with, and with the second one will take the full path of your log file which will be splitted
95
+ ## Dashboard security
36
96
 
37
- for bash usage ```rake app:split_log["new_log_file_name","/path/to/your/log.file"]```
97
+ Rails Pretty Logger does not provide its own authentication system. The dashboard can read application logs and, unless `read_only` is enabled, clear log files. Do not expose it publicly without protecting the mount.
38
98
 
39
- for zch usage ```noglob rake app:split_log["new_log_file_name","/path/to/your/log.file"]```
99
+ For local-only use, mount it only in development:
40
100
 
41
- ## Installation
42
- Add this line to your application's Gemfile:
101
+ ```ruby
102
+ # config/routes.rb
103
+ mount Rails::Pretty::Logger::Engine => "/rails-pretty-logger" if Rails.env.development?
104
+ ```
105
+
106
+ For protected environments, use the authentication or authorization your application already has:
43
107
 
108
+ ```ruby
109
+ # config/initializers/rails_pretty_logger.rb
110
+ Rails::Pretty::Logger.configure do |config|
111
+ config.authenticate_with = -> { authenticate_user! }
112
+ end
44
113
  ```
45
- gem 'rails-pretty-logger'
114
+
115
+ The hook runs inside the engine controller, so application controller helpers such as `authenticate_user!`, `current_user`, `head`, and `redirect_to` are available when your app defines them. For apps without an admin model, keep the engine development-only or use whichever internal access check already exists in the app.
116
+
117
+ ## Configuration
118
+
119
+ Rails Pretty Logger can be configured from an initializer:
120
+
121
+ ```ruby
122
+ # config/initializers/rails_pretty_logger.rb
123
+ Rails::Pretty::Logger.configure do |config|
124
+ config.authenticate_with = -> { authenticate_user! }
125
+ config.read_only = Rails.env.production?
126
+ config.max_file_size = 50.megabytes
127
+ config.tail_lines = 500
128
+ config.log_line_parser = nil
129
+ end
46
130
  ```
47
131
 
48
- And then execute:
49
- ```bash
50
- $ bundle
132
+ | Option | Default | Description |
133
+ | --- | --- | --- |
134
+ | `authenticate_with` | `nil` | Optional callable run before every engine action. |
135
+ | `read_only` | `true` in production, `false` elsewhere | Hides clear buttons and returns `403 Forbidden` from clear endpoints. |
136
+ | `max_file_size` | `nil` in the gem, `50.megabytes` in the generated initializer | Returns `413 Payload Too Large` instead of reading files above the limit. |
137
+ | `tail_lines` | `500` | Number of lines shown in tail mode. |
138
+ | `log_line_parser` | `nil` | Optional callable for extracting metadata from custom log lines. |
139
+
140
+ ## Custom log formats
141
+
142
+ JSON line logs are detected automatically when each line is a JSON object. Common keys such as `@timestamp`, `timestamp`, `time`, `datetime`, `created_at`, `severity`, `level`, `log_level`, `message`, and `msg` are rendered prominently. Other JSON keys are shown as metadata.
143
+
144
+ For non-JSON formats, configure a parser that returns metadata for lines it understands:
145
+
146
+ ```ruby
147
+ Rails::Pretty::Logger.configure do |config|
148
+ config.log_line_parser = ->(line) do
149
+ if (match = line.match(/\A(?<timestamp>\S+) (?<severity>\w+) (?<method>[A-Z]+) (?<path>\S+) (?<message>.*)/))
150
+ {
151
+ timestamp: match[:timestamp],
152
+ severity: match[:severity],
153
+ request_method: match[:method],
154
+ request_path: match[:path]
155
+ }
156
+ end
157
+ end
158
+ end
51
159
  ```
52
160
 
53
- Or install it yourself as:
161
+ Supported parser keys include `:timestamp`, `:time`, `:datetime`, `:created_at`, `:severity`, `:level`, `:log_level`, `:request_method`, `:method`, `:request_path`, `:path`, `:request_ip`, `:ip`, `:request_started_at`, `:started_at`, `:response_status`, `:status`, `:duration`, and `:request_duration`.
162
+
163
+ These keys power date filtering, severity filtering, request grouping, and request summaries.
164
+
165
+ ## Highlighting
166
+
167
+ Use the helper below to write a highlighted log entry:
168
+
169
+ ```ruby
170
+ Rails::Pretty::Logger::PrettyLogger.highlight("lorem ipsum")
171
+ ```
172
+
173
+ Highlighted lines are written with the `[HIGHLIGHT]` tag and rendered with dashboard highlight styling.
174
+
175
+ ## Hourly log rotation
176
+
177
+ Rails Pretty Logger can replace the Rails logger with a logger that rotates files hourly:
178
+
179
+ ```ruby
180
+ # config/environments/development.rb
181
+ require "rails/pretty/logger/console_logger"
182
+
183
+ config.logger = ActiveSupport::TaggedLogging.new(
184
+ Rails::Pretty::Logger::ConsoleLogger.new("rails-pretty-logger", "hourly", file_count: 48)
185
+ )
186
+ ```
187
+
188
+ Hourly files are moved under `log/hourly/YYYY/MM/DD/`. `file_count` controls how many rotated hourly files are kept for that logger prefix. Rotation uses a lock file under `tmp/rails_pretty_logger/` and removes empty date directories when old hourly files are deleted.
189
+
190
+ To split an existing log file into hourly files, use the rake task below. The first argument is the new file prefix and the second argument is the full path of the log file to split.
191
+
192
+ For bash:
193
+
54
194
  ```bash
55
- $ gem install rails-pretty-logger
195
+ bin/rails 'split_log[new_log_file_name,/path/to/your/log.file]'
56
196
  ```
57
- Mount the engine in your config/routes.rb:
58
197
 
198
+ For zsh:
199
+
200
+ ```zsh
201
+ noglob bin/rails split_log[new_log_file_name,/path/to/your/log.file]
59
202
  ```
60
- mount Rails::Pretty::Logger::Engine => "/rails-pretty-logger"
203
+
204
+ ## Performance and safety
205
+
206
+ Log file paths are resolved under `Rails.root/log`; invalid paths, missing files, and symlinks that escape the log directory are rejected.
207
+
208
+ Paginated reads and request grouping use line offset indexes instead of keeping the full selected page in memory. Indexes are cached in memory and persisted under `tmp/cache/rails_pretty_logger/line_indexes`. Cache entries are keyed by the file signature, filters, and parser identity, and clear actions invalidate the related indexes.
209
+
210
+ The first index build still scans the selected log once. Tail mode avoids that cost when you only need the latest entries because it reads backwards from the end of the file.
211
+
212
+ ## Dependency policy
213
+
214
+ Runtime dependencies are limited to Rails framework gems:
215
+
216
+ - `actionpack`
217
+ - `actionview`
218
+ - `activesupport`
219
+ - `railties`
220
+
221
+ The dashboard JavaScript is plain JavaScript and does not require a runtime Node package manager dependency. Browser tests use Playwright only in development/test.
222
+
223
+ ## Asset loading
224
+
225
+ The engine layout loads its JavaScript directly with `javascript_include_tag "rails/pretty/logger/application"`. The install generator links this file in `app/assets/config/manifest.js` when the host app has a Sprockets manifest.
226
+
227
+ Importmap pins are not generated because the engine does not use the host app's JavaScript entrypoint. For standard Rails asset pipeline apps, no manual importmap setup is needed. If your app has a custom asset setup or strict CSP, make sure `rails/pretty/logger/application.js` is available through the asset pipeline and allowed by your policy.
228
+
229
+ ## Development and CI
230
+
231
+ This project uses a Nix flake and direnv for local development. After allowing direnv once, commands run inside the project shell automatically:
232
+
233
+ ```bash
234
+ direnv allow
235
+ bundle install
236
+ bundle exec rails test
237
+ bundle exec ruby -Itest test/system/rails_pretty_logger_interaction_test.rb
238
+ gem build rails-pretty-logger.gemspec
61
239
  ```
62
240
 
63
- ## Contributing
241
+ System tests use Capybara with Playwright Chromium.
242
+
243
+ GitHub Actions runs on pull requests and pushes to `main` or `master`. The CI matrix runs Rails 7.1, 8.0, and 8.1 on Ruby 3.3, then executes Ruby tests, browser tests, and gem build checks inside the Nix shell.
64
244
 
65
245
  1. [Fork][fork] the [official repository][repo].
66
246
  2. [Create a topic branch.][branch]
@@ -69,10 +249,10 @@ mount Rails::Pretty::Logger::Engine => "/rails-pretty-logger"
69
249
  5. [Submit a pull request.][pr]
70
250
 
71
251
  ## License
72
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
73
252
 
253
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
74
254
 
75
- [repo]: https://github.com/kekik/rails-pretty-logger/tree/master
255
+ [repo]: https://github.com/MehmetCelik4/rails-pretty-logger/tree/master
76
256
  [fork]: https://help.github.com/articles/fork-a-repo/
77
257
  [branch]: https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
78
258
  [pr]: https://help.github.com/articles/using-pull-requests/
@@ -1,27 +1,20 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
- //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require rails/pretty/logger/list.min
14
- //= require rails-ujs
15
- //= require_tree .
1
+ (function () {
2
+ function confirmMessage(element) {
3
+ return element.dataset.turboConfirm || element.dataset.confirm;
4
+ }
16
5
 
6
+ document.addEventListener("click", function (event) {
7
+ var element = event.target.closest("a[data-confirm], a[data-turbo-confirm]");
17
8
 
18
- window.onload = function(){
9
+ if (!element) return;
19
10
 
20
- var options = {
21
- valueNames: [ 'name'],
22
- page: 12,
23
- pagination: true
24
- };
11
+ var message = confirmMessage(element);
12
+ if (message && !window.confirm(message)) event.preventDefault();
13
+ });
25
14
 
26
- var logList = new List('hourly', options);
27
- }
15
+ document.addEventListener("submit", function (event) {
16
+ var message = confirmMessage(event.target);
17
+
18
+ if (message && !window.confirm(message)) event.preventDefault();
19
+ });
20
+ })();
@@ -1,15 +1 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
- * files in this directory. Styles in this file should be added after the last require_* statement.
11
- * It is generally better to create a new file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
1
+ /* Compatibility logical asset for applications that reference rails/pretty/logger/application.css. */