Class: ActiveRecord::SqlAnalyzer::CompactLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/active_record/sql_analyzer/compact_logger.rb

Direct Known Subclasses

RedactedLogger

Instance Attribute Summary collapse

Attributes inherited from Logger

#config, #log_file, #log_prefix, #log_root

Instance Method Summary collapse

Methods inherited from Logger

#filter_event

Constructor Details

#initializeCompactLogger

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_fileObject (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_shasObject (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

#closeObject



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