Class: Legion::Data::Connection::QueryFileLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/data/connection.rb

Overview

File-based query logger that writes all SQL to a dedicated log file. Isolated from the main Legion::Logging domain.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ QueryFileLogger

Returns a new instance of QueryFileLogger.



57
58
59
60
61
62
63
64
65
# File 'lib/legion/data/connection.rb', line 57

def initialize(path)
  @path = path
  dir = File.dirname(path)
  FileUtils.mkdir_p(dir)
  FileUtils.chmod(0o700, dir) if File.directory?(dir)
  @file = File.open(path, File::WRONLY | File::APPEND | File::CREAT, 0o600)
  @file.sync = true
  @mutex = Mutex.new
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



55
56
57
# File 'lib/legion/data/connection.rb', line 55

def path
  @path
end

Instance Method Details

#closeObject



83
84
85
# File 'lib/legion/data/connection.rb', line 83

def close
  @mutex.synchronize { @file.close unless @file.closed? }
end

#debug(message) ⇒ Object



67
68
69
# File 'lib/legion/data/connection.rb', line 67

def debug(message)
  write('DEBUG', message)
end

#error(message) ⇒ Object



79
80
81
# File 'lib/legion/data/connection.rb', line 79

def error(message)
  write('ERROR', message)
end

#info(message) ⇒ Object



71
72
73
# File 'lib/legion/data/connection.rb', line 71

def info(message)
  write('INFO', message)
end

#warn(message) ⇒ Object



75
76
77
# File 'lib/legion/data/connection.rb', line 75

def warn(message)
  write('WARN', message)
end