Class: ActiveRecord::SqlAnalyzer::CompactLogger
- Defined in:
- lib/active_record/sql_analyzer/compact_logger.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#definition_log_file ⇒ Object
readonly
Returns the value of attribute definition_log_file.
-
#logged_shas ⇒ Object
readonly
Returns the value of attribute logged_shas.
Attributes inherited from Logger
#config, #log_file, #log_prefix, #log_root
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize ⇒ CompactLogger
constructor
A new instance of CompactLogger.
- #log(event) ⇒ Object
Methods inherited from Logger
Constructor Details
#initialize ⇒ CompactLogger
Returns a new instance of CompactLogger.
8 9 10 11 12 13 |
# File 'lib/active_record/sql_analyzer/compact_logger.rb', line 8 def initialize(*) super @logged_shas = Set.new @definition_log_file = File.open("#{log_root}/#{log_prefix}_definitions.log", "a+") end |
Instance Attribute Details
#definition_log_file ⇒ Object (readonly)
Returns the value of attribute definition_log_file.
6 7 8 |
# File 'lib/active_record/sql_analyzer/compact_logger.rb', line 6 def definition_log_file @definition_log_file end |
#logged_shas ⇒ Object (readonly)
Returns the value of attribute logged_shas.
6 7 8 |
# File 'lib/active_record/sql_analyzer/compact_logger.rb', line 6 def logged_shas @logged_shas end |
Instance Method Details
#close ⇒ Object
26 27 28 29 |
# File 'lib/active_record/sql_analyzer/compact_logger.rb', line 26 def close @definition_log_file.close rescue nil super end |
#log(event) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_record/sql_analyzer/compact_logger.rb', line 15 def log(event) json = event.to_json sha = json.hash unless logged_shas.include?(sha) definition_log_file.print("#{sha}|#{json}\n") logged_shas << sha end log_file.print("#{Time.now.to_i}|#{sha}\n") end |