log_bench 0.2.1 → 0.2.3

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: 37e0b36b93e67867c1e1524dc36a3f4fd5ebe6143dca4bfe7f1645b234a62cc7
4
- data.tar.gz: 95a0ca9581718731be542e1eb274c9a7001a27344d75d9aa7e607f13b49cd367
3
+ metadata.gz: c3d418b0832252146580022464c8b6401766ee056fb89642c42840d723a835e9
4
+ data.tar.gz: 8f98119ed45ffe24bbffc947388598dd90be1643ed87b25bb1981e3e81effcd5
5
5
  SHA512:
6
- metadata.gz: 7d62363f382b6fa2ea5a83271c45af9804448afa66414132aeb8faa9ec40a684b1b88b26fd34ec9f0d024a8bd54d9a96f2147fc3aaf6837d34e86b3e65af3b96
7
- data.tar.gz: a561e7aa4c690b0fa4cb1505686450e8ea869d2634c8b9c0ce641b43f3a9e8945296cc616009a45b5c746baf379ba2ded6fa5f6cad83d2da6573884fc3b4c349
6
+ metadata.gz: 47681831e5f88acea414d1f1825849ce715a4b227e9180c3d290e98de6571ca886c26e889cb053c32dd267bd80a7ae32ca9a2f36286767afb238c754953382e3
7
+ data.tar.gz: b261d76dd28d336a516f3245e6533551e6d6003e743ffc774686f12a7ef6b48852caf90eb8cc516ba569a47cea5644d08b41e9e4e645bb9181e456746099c371
data/README.md CHANGED
@@ -52,18 +52,20 @@ To customize LogBench behavior, create `config/initializers/log_bench.rb`:
52
52
 
53
53
  ```ruby
54
54
  # config/initializers/log_bench.rb
55
- LogBench.setup do |config|
56
- # Enable/disable LogBench (default: true in development, false elsewhere)
57
- config.enabled = Rails.env.development? # or any other condition
58
-
59
- # Disable automatic lograge configuration (if you want to configure lograge manually)
60
- # config.configure_lograge_automatically = false # (default: true)
61
-
62
- # Customize initialization message
63
- # config.show_init_message = :min # :full, :min, or :none (default: :full)
64
-
65
- # Specify which controllers to inject request_id tracking
66
- # config.base_controller_classes = %w[CustomBaseController] # (default: %w[ApplicationController, ActionController::Base])
55
+ if defined?(LogBench)
56
+ LogBench.setup do |config|
57
+ # Enable/disable LogBench (default: true in development, false elsewhere)
58
+ config.enabled = Rails.env.development? # or any other condition
59
+
60
+ # Disable automatic lograge configuration (if you want to configure lograge manually)
61
+ # config.configure_lograge_automatically = false # (default: true)
62
+
63
+ # Customize initialization message
64
+ # config.show_init_message = :min # :full, :min, or :none (default: :full)
65
+
66
+ # Specify which controllers to inject request_id tracking
67
+ # config.base_controller_classes = %w[CustomBaseController] # (default: %w[ApplicationController, ActionController::Base])
68
+ end
67
69
  end
68
70
  ```
69
71
 
@@ -73,9 +75,11 @@ If you already have lograge configured or want to manage it manually:
73
75
 
74
76
  ```ruby
75
77
  # config/initializers/log_bench.rb
76
- LogBench.setup do |config|
77
- # ... other config ...
78
- config.configure_lograge_automatically = false # Don't touch my lograge config!
78
+ if defined?(LogBench)
79
+ LogBench.setup do |config|
80
+ # ... other config ...
81
+ config.configure_lograge_automatically = false # Don't touch my lograge config!
82
+ end
79
83
  end
80
84
 
81
85
  # Then configure lograge yourself in config/environments/development.rb or an initializer,
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
+ require "logger"
4
5
 
5
6
  module LogBench
6
7
  # A simple JSON formatter for Rails loggers that creates LogBench-compatible
8
+ # JSON logs. Extends TaggedLogging::Formatter for full Rails compatibility.
7
9
  class JsonFormatter < ::Logger::Formatter
10
+ include ActiveSupport::TaggedLogging::Formatter
11
+
8
12
  def call(severity, timestamp, progname, message)
9
13
  log_entry = build_log_entry(severity, timestamp, progname, message)
10
14
  log_entry.to_json + "\n"
@@ -17,16 +21,22 @@ module LogBench
17
21
 
18
22
  def build_log_entry(severity, timestamp, progname, message)
19
23
  entry = message_to_hash(message)
24
+ tags = current_tags
20
25
  entry = parse_lograge_message(entry[:message]) if lograge_message?(entry)
21
26
  request_id = current_request_id
22
27
 
23
- entry.merge!(
28
+ base_entry = {
24
29
  level: severity,
25
30
  timestamp: timestamp.utc.iso8601(3),
26
31
  time: timestamp.to_f,
27
32
  request_id: request_id,
28
33
  progname: progname
29
- ).compact
34
+ }
35
+
36
+ # Add tags if present
37
+ base_entry[:tags] = tags if tags.any?
38
+
39
+ entry.merge!(base_entry).compact
30
40
  end
31
41
 
32
42
  def message_to_hash(message)
@@ -26,7 +26,7 @@ module LogBench
26
26
  end
27
27
 
28
28
  # Show success message when Rails starts in development
29
- initializer "log_bench.show_instructions", after: :load_config_initializers do
29
+ initializer "log_bench.show_instructions", after: "log_bench.configure" do
30
30
  next unless Rails.env.development? && LogBench.configuration.enabled
31
31
 
32
32
  print_configured_init_message
@@ -37,12 +37,17 @@ module LogBench
37
37
  puts LINE
38
38
  end
39
39
 
40
- # Single after_initialize for ALL setup that needs to happen after Rails is ready
41
- config.after_initialize do |app|
40
+ # Configure lograge after the gem was already configured
41
+ initializer "log_bench.configure_lograge", after: "log_bench.configure" do |app|
42
42
  if LogBench.configuration.enabled
43
43
  LogBench::Railtie.setup_lograge(app)
44
- LogBench::Railtie.setup_current_attributes
44
+ end
45
+ end
46
+
47
+ config.after_initialize do
48
+ if LogBench.configuration.enabled
45
49
  LogBench::Railtie.setup_rails_logger_final
50
+ LogBench::Railtie.setup_current_attributes
46
51
  LogBench::Railtie.validate_configuration!
47
52
  end
48
53
  end
@@ -69,7 +74,6 @@ module LogBench
69
74
  end
70
75
  end
71
76
 
72
- # Setup Rails logger by re-wrapping with TaggedLogging
73
77
  def setup_rails_logger_final
74
78
  # Get the underlying logger (unwrap TaggedLogging if present)
75
79
  base_logger = Rails.logger.respond_to?(:logger) ? Rails.logger.logger : Rails.logger
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LogBench
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_bench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamín Silva
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-26 00:00:00.000000000 Z
10
+ date: 2025-07-08 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: zeitwerk