Class: ActiveRecord::SqlAnalyzer::Logger

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

Direct Known Subclasses

CompactLogger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_root, log_prefix) ⇒ Logger

Returns a new instance of Logger.



6
7
8
9
10
11
12
# File 'lib/active_record/sql_analyzer/logger.rb', line 6

def initialize(log_root, log_prefix)
  @log_prefix = log_prefix
  @log_root = log_root
  @config = SqlAnalyzer.config

  @log_file = File.open("#{log_root}/#{log_prefix}.log", "a")
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



4
5
6
# File 'lib/active_record/sql_analyzer/logger.rb', line 4

def config
  @config
end

#log_fileObject (readonly)

Returns the value of attribute log_file.



4
5
6
# File 'lib/active_record/sql_analyzer/logger.rb', line 4

def log_file
  @log_file
end

#log_prefixObject (readonly)

Returns the value of attribute log_prefix.



4
5
6
# File 'lib/active_record/sql_analyzer/logger.rb', line 4

def log_prefix
  @log_prefix
end

#log_rootObject (readonly)

Returns the value of attribute log_root.



4
5
6
# File 'lib/active_record/sql_analyzer/logger.rb', line 4

def log_root
  @log_root
end

Instance Method Details

#closeObject



24
25
26
# File 'lib/active_record/sql_analyzer/logger.rb', line 24

def close
  @log_file.close rescue nil
end

#filter_event(event) ⇒ Object

Further redact or remove any other information from an event



20
21
22
# File 'lib/active_record/sql_analyzer/logger.rb', line 20

def filter_event(event)
  event
end

#log(event) ⇒ Object

Log the raw event data directly to disk



15
16
17
# File 'lib/active_record/sql_analyzer/logger.rb', line 15

def log(event)
  log_file.puts(event.to_json)
end