Class: RailsActionTracker::Tracker
- Inherits:
-
Object
- Object
- RailsActionTracker::Tracker
- Defined in:
- lib/rails_action_tracker/tracker.rb
Constant Summary collapse
- THREAD_KEY =
:rails_action_tracker_logs
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
-
.custom_logger ⇒ Object
Returns the value of attribute custom_logger.
Class Method Summary collapse
- .configure(options = {}) ⇒ Object
- .print_summary ⇒ Object
- .start_tracking ⇒ Object
- .stop_tracking ⇒ Object
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
12 13 14 |
# File 'lib/rails_action_tracker/tracker.rb', line 12 def config @config end |
.custom_logger ⇒ Object
Returns the value of attribute custom_logger.
12 13 14 |
# File 'lib/rails_action_tracker/tracker.rb', line 12 def custom_logger @custom_logger end |
Class Method Details
.configure(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rails_action_tracker/tracker.rb', line 14 def configure( = {}) @config = { print_to_rails_log: true, write_to_file: false, log_file_path: nil, print_format: :table, log_format: nil, output_format: nil, # Deprecated: kept for backward compatibility services: [], ignored_tables: %w[pg_attribute pg_index pg_class pg_namespace pg_type ar_internal_metadata schema_migrations], ignored_controllers: [], ignored_actions: {} }.merge() # Handle backward compatibility with output_format if @config[:output_format] && !.key?(:print_format) && !.key?(:log_format) @config[:print_format] = @config[:output_format] @config[:log_format] = @config[:output_format] end # Default log_format to print_format if not specified @config[:log_format] ||= @config[:print_format] # Only setup custom logger for formats that don't write directly to file should_setup_logger = @config[:write_to_file] && @config[:log_file_path] && !%i[json csv].include?(@config[:log_format]) setup_custom_logger if should_setup_logger end |
.print_summary ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/rails_action_tracker/tracker.rb', line 65 def print_summary logs = Thread.current[THREAD_KEY] return unless logs return if should_ignore_controller_action?(logs[:controller], logs[:action]) summary_data = prepare_summary_data(logs) handle_print_output(summary_data) handle_log_file_output(summary_data) end |
.start_tracking ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rails_action_tracker/tracker.rb', line 44 def start_tracking Thread.current[THREAD_KEY] = { read: Set.new, write: Set.new, captured_logs: [], controller: nil, action: nil } subscribe_to_sql_notifications subscribe_to_logger end |
.stop_tracking ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/rails_action_tracker/tracker.rb', line 56 def stop_tracking unsubscribe_from_sql_notifications unsubscribe_from_logger logs = Thread.current[THREAD_KEY] || { read: Set.new, write: Set.new, captured_logs: [], controller: nil, action: nil } Thread.current[THREAD_KEY] = nil logs end |