dislogger 0.1.6 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36f02d278c361c1316f47a29bedad900e03183f2f40e750656cf200d01d80f66
4
- data.tar.gz: 2d78928ccb2740d8eca3a15fc81e5cc0168c2730511417b2ece3167a9f973f18
3
+ metadata.gz: 0b7ddd219546d4b47916d9e0cfd1303679ed1a3f4befa6675a7be486ada7de25
4
+ data.tar.gz: '001685aeefc4f82fd7a07f8a539ea9c737de5a1760eebdc0799660ea62c4087d'
5
5
  SHA512:
6
- metadata.gz: 519c66523ab2f57d73f85cd06cbda35ceef6e7ae359164d45df6c2b1b30aadfe5e6828c5aa344c7862b6a89cea8807b46905b9c01bc1e135fc1da7d53a677519
7
- data.tar.gz: 429ebbb1a4ee2faf591092e3cd532a519fc65d47f7a26a51a397298a31e2651dd766b4e0fdbd7cb06df689ba59a5d188f087d4b59a8c1502bd72508a40acf1ca
6
+ metadata.gz: 40495b36577cce4bb00ea8ab38b74019b4792e2ca6452c1edd735f4042557403ab382bb70b08f94e4fb952b7e5240c1828057a5068f76aad4c1da5ba6be1fc41
7
+ data.tar.gz: 2d90483f3e1db1969355be2565384cde9f38f7048e5dd4f7573203a47bb814f3ba45bf11554bf9e0dd71c4751e0d7fcece7d547664afa8f2959bc98fbdba0eb9
data/README.md CHANGED
@@ -7,12 +7,13 @@ A Ruby on Rails gem for elegant error handling and Discord notifications. Automa
7
7
 
8
8
  ## Features
9
9
 
10
- - 🚨 Automatic error handling for Rails applications
10
+ - 🚨 Automatic error handling for Rails applications (both API and regular apps)
11
11
  - 🎯 Discord notifications for errors with customizable formatting
12
12
  - 📝 Detailed error information including backtrace
13
13
  - 🎨 Customizable error colors for different status codes
14
14
  - 🔧 Environment-based configuration
15
15
  - 🛡️ Built-in support for common Rails exceptions
16
+ - ⚡ Works with both `ActionController::API` and `ActionController::Base`
16
17
 
17
18
  ## Installation
18
19
 
@@ -36,6 +37,16 @@ $ gem install dislogger
36
37
 
37
38
  ## Configuration
38
39
 
40
+ ### Quick Start
41
+
42
+ After installing the gem, run the generator to create the configuration file:
43
+
44
+ ```bash
45
+ $ rails generate dislogger:install
46
+ ```
47
+
48
+ This will create an initializer at `config/initializers/dislogger.rb` with all available configuration options and their documentation.
49
+
39
50
  ### Setting up Discord Webhook
40
51
 
41
52
  Before configuring the gem, you need to set up a webhook in your Discord server:
@@ -68,27 +79,27 @@ DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/your-webhook-url
68
79
 
69
80
  Make sure to add `.env` to your `.gitignore` file to keep your webhook URL secure.
70
81
 
71
- ### Additional Configuration Options
82
+ ### Configuration Options
72
83
 
73
- Create an initializer file at `config/initializers/dislogger.rb` with all available options:
84
+ The generator will create an initializer with all available options:
74
85
 
75
86
  ```ruby
76
87
  Dislogger.configure do |config|
77
88
  # Required: Your Discord webhook URL (preferably from environment variables)
78
89
  config.discord_webhook_url = ENV['DISCORD_WEBHOOK_URL']
79
90
 
91
+ # Required: Current environment (defaults to Rails.env if available)
92
+ config.environment = Rails.env
93
+
80
94
  # Optional: Custom bot username (default: 'Error Logger')
81
95
  config.bot_username = 'My App Error Logger'
82
96
 
83
97
  # Optional: Number of backtrace lines to include (default: 5)
84
98
  config.backtrace_lines_limit = 10
85
99
 
86
- # Optional: Environments where notifications are enabled (default: ['production', 'staging'])
100
+ # Optional: Environments where notifications are enabled (default: ['production', 'staging', 'development'])
87
101
  config.enabled_environments = ['production', 'staging', 'development']
88
102
 
89
- # Optional: Current environment (default: Rails.env if available)
90
- config.environment = 'production'
91
-
92
103
  # Optional: Custom error colors (default values shown below)
93
104
  config.error_color_map = {
94
105
  500 => 15158332, # Red
@@ -107,6 +118,12 @@ end
107
118
  The gem automatically includes error handling in your Rails controllers. No additional setup is required!
108
119
 
109
120
  ```ruby
121
+ # For API applications
122
+ class ApplicationController < ActionController::API
123
+ # Error handling is automatically included
124
+ end
125
+
126
+ # For regular Rails applications
110
127
  class ApplicationController < ActionController::Base
111
128
  # Error handling is automatically included
112
129
  end
@@ -13,7 +13,7 @@ module Dislogger
13
13
  @discord_webhook_url = nil
14
14
  @bot_username = 'Error Logger'
15
15
  @backtrace_lines_limit = 5
16
- @enabled_environments = %w[production staging]
16
+ @enabled_environments = %w[production staging development]
17
17
  @environment = nil
18
18
  @error_color_map = {
19
19
  500 => 15158332, # Red for server errors
@@ -2,9 +2,23 @@
2
2
 
3
3
  module Dislogger
4
4
  class Railtie < Rails::Railtie
5
- initializer 'dislogger.configure_rails_initialization' do
5
+ initializer 'dislogger.configure_rails_initialization' do |app|
6
+ # Configurar el ambiente por defecto si no está configurado
7
+ ActiveSupport.on_load(:before_configuration) do
8
+ Dislogger.configure do |config|
9
+ config.environment ||= Rails.env
10
+ end
11
+ end
12
+
13
+ # Incluir el ErrorHandler en los controladores
6
14
  ActiveSupport.on_load(:action_controller) do
7
- ActionController::Base.include Dislogger::ErrorHandler
15
+ if defined?(ActionController::API)
16
+ ActionController::API.include(Dislogger::ErrorHandler)
17
+ end
18
+
19
+ if defined?(ActionController::Base)
20
+ ActionController::Base.include(Dislogger::ErrorHandler)
21
+ end
8
22
  end
9
23
  end
10
24
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dislogger
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
5
5
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dislogger
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path('templates', __dir__)
7
+
8
+ def create_initializer_file
9
+ template 'dislogger.rb', 'config/initializers/dislogger.rb'
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dislogger.configure do |config|
4
+ # Configura la URL del webhook de Discord (requerido)
5
+ config.discord_webhook_url = ENV['DISCORD_WEBHOOK_URL']
6
+
7
+ # Configura el ambiente actual (requerido)
8
+ config.environment = Rails.env
9
+
10
+ # Configura el nombre del bot (opcional, por defecto: 'Error Logger')
11
+ # config.bot_username = 'Mi App Error Logger'
12
+
13
+ # Configura el número de líneas del backtrace (opcional, por defecto: 5)
14
+ # config.backtrace_lines_limit = 10
15
+
16
+ # Configura los ambientes donde las notificaciones están habilitadas
17
+ # (opcional, por defecto: ['production', 'staging', 'development'])
18
+ # config.enabled_environments = ['production', 'staging', 'development']
19
+
20
+ # Configura los colores de los errores (opcional)
21
+ # config.error_color_map = {
22
+ # 500 => 15158332, # Rojo para errores del servidor
23
+ # 404 => 3447003, # Azul para no encontrado
24
+ # 422 => 16776960, # Amarillo para errores de validación
25
+ # 403 => 15105570, # Naranja para prohibido
26
+ # default: 10181046 # Gris para otros
27
+ # }
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dislogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nelson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-20 00:00:00.000000000 Z
11
+ date: 2025-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -192,6 +192,8 @@ files:
192
192
  - lib/dislogger/notifiers/discord_notifier.rb
193
193
  - lib/dislogger/railtie.rb
194
194
  - lib/dislogger/version.rb
195
+ - lib/generators/dislogger/install/install_generator.rb
196
+ - lib/generators/dislogger/install/templates/dislogger.rb
195
197
  - sig/dislogger.rbs
196
198
  homepage: https://github.com/nduartex/dislogger
197
199
  licenses: