Class: Dbviewer::Logger
- Inherits:
-
Object
- Object
- Dbviewer::Logger
- Includes:
- Singleton
- Defined in:
- lib/dbviewer/logger.rb
Overview
Logger captures and analyzes SQL queries for debugging and performance monitoring
Instance Method Summary collapse
-
#clear ⇒ Object
Clear all stored queries.
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
-
#recent_queries(limit: 100, table_filter: nil, request_id: nil, min_duration: nil) ⇒ Object
Get recent queries, optionally filtered.
-
#stats ⇒ Object
Get stats about all queries.
-
#stats_for_queries(queries) ⇒ Object
Calculate stats for a specific set of queries (can be filtered).
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
6 7 8 9 10 11 12 13 14 |
# File 'lib/dbviewer/logger.rb', line 6 def initialize @request_counter = 0 @current_request_id = nil @last_query_time = nil @mutex = Mutex.new setup_storage subscribe_to_sql_notifications end |
Instance Method Details
#clear ⇒ Object
Clear all stored queries
17 18 19 |
# File 'lib/dbviewer/logger.rb', line 17 def clear @storage.clear end |
#recent_queries(limit: 100, table_filter: nil, request_id: nil, min_duration: nil) ⇒ Object
Get recent queries, optionally filtered
22 23 24 25 26 27 28 29 |
# File 'lib/dbviewer/logger.rb', line 22 def recent_queries(limit: 100, table_filter: nil, request_id: nil, min_duration: nil) @storage.filter( limit: limit, table_filter: table_filter, request_id: request_id, min_duration: min_duration ) end |
#stats ⇒ Object
Get stats about all queries
32 33 34 |
# File 'lib/dbviewer/logger.rb', line 32 def stats stats_for_queries(@storage.all) end |
#stats_for_queries(queries) ⇒ Object
Calculate stats for a specific set of queries (can be filtered)
37 38 39 |
# File 'lib/dbviewer/logger.rb', line 37 def stats_for_queries(queries) QueryAnalyzer.generate_stats(queries) end |