faultline-rails 0.4.0 → 0.7.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 (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -0
  3. data/app/assets/stylesheets/faultline/application.css +0 -41
  4. data/app/assets/stylesheets/faultline/dashboard.css +961 -0
  5. data/app/controllers/faultline/logged_exceptions_controller.rb +81 -8
  6. data/app/helpers/faultline/logged_exceptions_helper.rb +84 -5
  7. data/app/javascript/controllers/faultline_controller.js +349 -7
  8. data/app/javascript/faultline/controllers/sidebar_controller.js +21 -0
  9. data/app/javascript/faultline/controllers/theme_controller.js +48 -0
  10. data/app/models/faultline/logged_exception.rb +10 -0
  11. data/app/views/faultline/logged_exceptions/_exceptions.html.erb +132 -84
  12. data/app/views/faultline/logged_exceptions/_show.html.erb +281 -60
  13. data/app/views/faultline/logged_exceptions/index.html.erb +192 -123
  14. data/app/views/faultline/logged_exceptions/show.html.erb +1 -1
  15. data/app/views/layouts/faultline/application.html.erb +116 -51
  16. data/faultline-rails.gemspec +1 -0
  17. data/lib/faultline/cleanup.rb +32 -0
  18. data/lib/faultline/configuration.rb +172 -4
  19. data/lib/faultline/engine.rb +22 -0
  20. data/lib/faultline/logger.rb +188 -0
  21. data/lib/faultline/notifications.rb +80 -0
  22. data/lib/faultline/ransack_config.rb +2 -24
  23. data/lib/faultline/version.rb +1 -1
  24. data/lib/faultline.rb +10 -0
  25. data/lib/generators/faultline/customize_generator.rb +117 -0
  26. data/lib/generators/faultline/install_generator.rb +15 -0
  27. data/lib/generators/faultline/templates/faultline.rb +70 -37
  28. data/lib/generators/faultline/templates/javascript/controllers/faultline_controller.js +310 -0
  29. data/lib/generators/faultline/templates/views/faultline/logged_exceptions/_exceptions.html.erb +124 -0
  30. data/lib/generators/faultline/templates/views/faultline/logged_exceptions/_show.html.erb +83 -0
  31. data/lib/generators/faultline/templates/views/faultline/logged_exceptions/index.html.erb +113 -0
  32. data/lib/generators/faultline/templates/views/layouts/faultline/application.html.erb +133 -0
  33. data/lib/tasks/faultline.rake +147 -0
  34. metadata +15 -1
@@ -0,0 +1,48 @@
1
+ import { Controller } from "@hotwired/stimulus"
2
+
3
+ export default class extends Controller {
4
+ static values = { theme: String }
5
+
6
+ connect() {
7
+ this.apply(this.savedTheme || this.themeValue || "auto")
8
+ }
9
+
10
+ toggle() {
11
+ const current = this.currentTheme
12
+ const next = current === "dark" ? "light" : current === "light" ? "auto" : "dark"
13
+ this.apply(next)
14
+ this.save(next)
15
+ }
16
+
17
+ get currentTheme() {
18
+ if (document.documentElement.classList.contains("dark")) return "dark"
19
+ if (document.documentElement.classList.contains("light")) return "light"
20
+ return "auto"
21
+ }
22
+
23
+ get savedTheme() {
24
+ return localStorage.getItem("faultline-theme")
25
+ }
26
+
27
+ save(theme) {
28
+ localStorage.setItem("faultline-theme", theme)
29
+ }
30
+
31
+ apply(theme) {
32
+ const root = document.documentElement
33
+ root.classList.remove("dark", "light")
34
+
35
+ if (theme === "dark") {
36
+ root.classList.add("dark")
37
+ } else if (theme === "light") {
38
+ root.classList.add("light")
39
+ } else {
40
+ // Auto: follow system preference
41
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
42
+ root.classList.add("dark")
43
+ } else {
44
+ root.classList.add("light")
45
+ }
46
+ }
47
+ }
48
+ }
@@ -5,6 +5,16 @@ module Faultline
5
5
  self.table_name = "faultline_logged_exceptions"
6
6
  HOSTNAME = Socket.gethostname
7
7
 
8
+ def self.ransackable_attributes(auth_object = nil)
9
+ %w[action_name backtrace controller_name created_at environment
10
+ exception_class id message remote_ip request
11
+ updated_at user_agent user_info]
12
+ end
13
+
14
+ def self.ransackable_associations(auth_object = nil)
15
+ []
16
+ end
17
+
8
18
  class << self
9
19
  def create_from_exception(controller, exception, data)
10
20
  message = exception.message.to_s
@@ -1,106 +1,154 @@
1
- <div id="exceptions-content" class="bg-white shadow rounded-lg overflow-hidden">
2
- <%# Header %>
3
- <div class="px-6 py-4 border-b border-gray-200 sm:flex sm:items-center sm:justify-between">
4
- <div>
5
- <h2 class="text-lg font-medium text-gray-900">
6
- <%= t(".heading") %>
7
- <% if filtered? %>
8
- <span class="text-sm font-normal text-gray-500">(<%= t(".filtered") %>)</span>
9
- <% end %>
10
- </h2>
11
- <p class="mt-1 text-sm text-gray-500"><%= t(".count", count: @exceptions.total_entries) %></p>
12
- </div>
13
- <div class="mt-4 sm:mt-0">
14
- <%= link_to t(".delete_visible"), destroy_all_logged_exceptions_path(params_filters),
15
- class: "inline-flex items-center px-3 py-2 border border-red-300 text-sm leading-4 font-medium rounded-md text-red-700 bg-white hover:bg-red-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500",
16
- data: { turbo_method: :post, turbo_confirm: t(".confirm_delete_visible"), turbo_stream: true } %>
17
- </div>
18
- </div>
19
-
1
+ <div id="exceptions-content" class="fl-card overflow-hidden">
20
2
  <% if @exceptions.empty? %>
21
- <div class="px-6 py-12 text-center">
22
- <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
23
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
24
- </svg>
25
- <p class="mt-2 text-sm text-gray-500"><%= t(".empty") %></p>
3
+ <div class="py-16 text-center">
4
+ <div class="w-12 h-12 rounded-full flex items-center justify-center mx-auto" style="background: var(--fl-success-light)">
5
+ <svg class="w-6 h-6" style="color: var(--fl-success)" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
6
+ <path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
7
+ </svg>
8
+ </div>
9
+ <p class="mt-3 text-sm font-medium" style="color: var(--fl-text)"><%= t(".empty") %></p>
10
+ <p class="mt-1 text-xs" style="color: var(--fl-text-muted)">No exceptions match your current filters.</p>
11
+ <% if filtered? %>
12
+ <%= link_to "Clear filters", logged_exceptions_path, class: "mt-3 inline-block text-xs font-medium", style: "color: var(--fl-primary)" %>
13
+ <% end %>
26
14
  </div>
27
15
  <% else %>
28
- <div class="overflow-x-auto">
29
- <table class="min-w-full divide-y divide-gray-200">
30
- <thead class="bg-gray-50">
16
+ <%# ─── Table Header Bar ───────────────────────────────────── %>
17
+ <div class="px-4 py-2.5 flex items-center justify-between" style="background: var(--fl-bg-secondary); border-bottom: 1px solid var(--fl-border-light)">
18
+ <div class="flex items-center gap-3">
19
+ <span class="text-xs font-medium" style="color: var(--fl-text-secondary)">
20
+ <span class="font-semibold" style="color: var(--fl-text)"><%= @exceptions.total_entries %></span> exceptions
21
+ <% if filtered? %>
22
+ <span style="color: var(--fl-text-muted)">(filtered)</span>
23
+ <% end %>
24
+ </span>
25
+
26
+ <%# Page size selector %>
27
+ <div class="flex items-center gap-1">
28
+ <span class="text-xs" style="color: var(--fl-text-muted)">Show</span>
29
+ <% Faultline.configuration.page_size_options.each do |size| %>
30
+ <%= link_to size.to_s,
31
+ logged_exceptions_path(params_filters.merge(per_page: size)),
32
+ class: "fl-btn fl-btn-xs #{params[:per_page].to_i == size || (!params[:per_page] && size == Faultline.configuration.per_page) ? 'fl-btn-primary' : 'fl-btn-ghost'}",
33
+ data: { turbo_frame: "exceptions" } %>
34
+ <% end %>
35
+ </div>
36
+ </div>
37
+
38
+ <div class="flex items-center gap-2">
39
+ <%# Keyboard hint %>
40
+ <span class="text-xs flex items-center gap-1" style="color: var(--fl-text-muted)">
41
+ <span class="fl-kbd">?</span> shortcuts
42
+ </span>
43
+
44
+ <%= link_to destroy_all_logged_exceptions_path(params_filters),
45
+ class: "fl-btn fl-btn-ghost fl-btn-sm",
46
+ style: "color: var(--fl-danger); border-color: var(--fl-danger)",
47
+ data: { turbo_method: :post, turbo_confirm: t(".confirm_delete_visible"), turbo_stream: true } do %>
48
+ <svg class="w-3 h-3" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" /></svg>
49
+ Delete all
50
+ <% end %>
51
+ </div>
52
+ </div>
53
+
54
+ <%# ─── Exception Table ────────────────────────────────────── %>
55
+ <div class="fl-table-wrap">
56
+ <table class="fl-table">
57
+ <thead>
31
58
  <tr>
32
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
33
- <%= sort_link @q, :exception_class, "Exception", data: { turbo_frame: "exceptions" } %>
34
- </th>
35
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
36
- <%= sort_link @q, :controller_name, "Controller", data: { turbo_frame: "exceptions" } %>
37
- </th>
38
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
39
- <%= sort_link @q, :action_name, "Action", data: { turbo_frame: "exceptions" } %>
40
- </th>
41
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
42
- Message
43
- </th>
44
- <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
45
- <%= sort_link @q, :created_at, "Date", data: { turbo_frame: "exceptions" } %>
46
- </th>
47
- <th class="relative px-6 py-3">
48
- <span class="sr-only"><%= t(".actions") %></span>
49
- </th>
59
+ <th style="width: 1rem"></th>
60
+ <th>Exception</th>
61
+ <th>Source</th>
62
+ <th>Message</th>
63
+ <th>Count</th>
64
+ <th>Time</th>
65
+ <th style="text-align: right"><span class="sr-only">Actions</span></th>
50
66
  </tr>
51
67
  </thead>
52
- <tbody class="bg-white divide-y divide-gray-200">
53
- <% @exceptions.each do |exception| %>
54
- <tr id="<%= dom_id(exception) %>" class="hover:bg-gray-50">
55
- <td class="px-6 py-4 whitespace-nowrap">
56
- <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
57
- <%= exception.exception_class %>
68
+ <tbody data-faultline-target="exceptionList">
69
+ <% @exceptions.each_with_index do |exception, index| %>
70
+ <tr id="<%= dom_id(exception) %>"
71
+ class="group"
72
+ style="cursor: pointer; position: relative"
73
+ data-action="click->faultline#selectRow"
74
+ data-url="<%= logged_exception_path(exception) %>"
75
+ data-index="<%= index %>"
76
+ data-faultline-index-param="<%= index %>">
77
+
78
+ <%# Severity indicator dot %>
79
+ <td>
80
+ <span class="fl-count-indicator fl-badge-<%= severity_for(exception) %>"
81
+ style="background: var(--fl-<%= severity_for(exception) %>-light); color: var(--fl-<%= severity_for(exception) %>); width: 0.5rem; height: 0.5rem; min-width: 0; padding: 0; border-radius: 50%">
58
82
  </span>
59
83
  </td>
60
- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
61
- <%= exception.controller_name %>
84
+
85
+ <%# Exception class with severity badge %>
86
+ <td>
87
+ <span class="fl-badge fl-badge-<%= severity_for(exception) %>"><%= exception.exception_class %></span>
62
88
  </td>
63
- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
64
- <%= exception.action_name %>
89
+
90
+ <%# Source (controller + action) %>
91
+ <td>
92
+ <div class="flex items-center gap-1.5">
93
+ <span class="fl-mono text-xs" style="color: var(--fl-text-secondary)"><%= exception.controller_name %></span>
94
+ <span class="fl-mono text-xs" style="color: var(--fl-text-muted)">#<%= exception.action_name %></span>
95
+ </div>
65
96
  </td>
66
- <td class="px-6 py-4 text-sm text-gray-500 max-w-xs truncate">
67
- <%= link_to exception.message&.truncate(100), logged_exception_path(exception),
68
- class: "text-indigo-600 hover:text-indigo-900",
69
- data: { turbo_frame: "exception-details" } %>
97
+
98
+ <%# Message (truncated) %>
99
+ <td>
100
+ <div class="fl-msg">
101
+ <%= exception.message&.truncate(120) %>
102
+ </div>
70
103
  </td>
71
- <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
72
- <%= pretty_exception_date(exception) %>
104
+
105
+ <%# Occurrence count %>
106
+ <td>
107
+ <% count = exception_count_for(exception.exception_class) %>
108
+ <span class="fl-badge fl-badge-muted"><%= count %></span>
73
109
  </td>
74
- <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
75
- <%= link_to t(".delete"), logged_exception_path(exception),
76
- class: "text-red-600 hover:text-red-900",
77
- data: { turbo_method: :delete, turbo_confirm: t(".confirm_delete"), turbo_stream: true } %>
110
+
111
+ <%# Time (relative) %>
112
+ <td class="fl-date"><%= pretty_exception_date(exception) %></td>
113
+
114
+ <%# Actions (delete on hover) %>
115
+ <td style="text-align: right">
116
+ <div class="flex items-center justify-end gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
117
+ <%= link_to logged_exception_path(exception),
118
+ class: "fl-icon-btn",
119
+ style: "color: var(--fl-text-muted)",
120
+ title: "View details",
121
+ data: { turbo_frame: "exception-details", action: "click->faultline#stopPropagation" } do %>
122
+ <svg class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M13.5 6H5.25A2.25 2.25 0 003 8.25v10.5A2.25 2.25 0 005.25 21h10.5A2.25 2.25 0 0018 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25" /></svg>
123
+ <% end %>
124
+ <%= link_to logged_exception_path(exception),
125
+ class: "fl-icon-btn",
126
+ style: "color: var(--fl-danger)",
127
+ title: "Delete",
128
+ data: { turbo_method: :delete, turbo_confirm: t(".confirm_delete"), turbo_stream: true, action: "click->faultline#stopPropagation" } do %>
129
+ <svg class="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" /></svg>
130
+ <% end %>
131
+ </div>
78
132
  </td>
79
133
  </tr>
80
134
  <% end %>
81
135
  </tbody>
82
136
  </table>
83
137
  </div>
84
- <% end %>
85
138
 
86
- <%# Pagination %>
87
- <div class="bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6">
88
- <div class="flex-1 flex justify-between sm:hidden">
89
- <%= will_paginate @exceptions, params: { controller: "logged_exceptions", action: "index" }.merge(params_filters),
90
- inner_window: 1, outer_window: 0, previous_label: "Previous", next_label: "Next" %>
91
- </div>
92
- <div class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
93
- <div>
94
- <p class="text-sm text-gray-700">
95
- Showing <span class="font-medium"><%= @exceptions.offset + 1 %></span>
96
- to <span class="font-medium"><%= @exceptions.offset + @exceptions.length %></span>
97
- of <span class="font-medium"><%= @exceptions.total_entries %></span> exceptions
139
+ <%# ─── Pagination ─────────────────────────────────────────── %>
140
+ <% if @exceptions.respond_to?(:total_pages) && @exceptions.total_pages > 1 %>
141
+ <div class="fl-pagination">
142
+ <p class="text-xs" style="color: var(--fl-text-muted)">
143
+ Showing <span class="font-medium" style="color: var(--fl-text-secondary)"><%= @exceptions.offset + 1 %></span>
144
+ to <span class="font-medium" style="color: var(--fl-text-secondary)"><%= [@exceptions.offset + @exceptions.length, @exceptions.total_entries].min %></span>
145
+ of <span class="font-medium" style="color: var(--fl-text-secondary)"><%= @exceptions.total_entries %></span>
98
146
  </p>
147
+ <div>
148
+ <%= will_paginate @exceptions, params: { controller: "logged_exceptions", action: "index" }.merge(params_filters),
149
+ inner_window: 2, outer_window: 1, previous_label: "&laquo;", next_label: "&raquo;" %>
150
+ </div>
99
151
  </div>
100
- <div>
101
- <%= will_paginate @exceptions, params: { controller: "logged_exceptions", action: "index" }.merge(params_filters),
102
- inner_window: 2, outer_window: 1, previous_label: "&laquo;", next_label: "&raquo;" %>
103
- </div>
104
- </div>
105
- </div>
152
+ <% end %>
153
+ <% end %>
106
154
  </div>