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

Inherits:
Object
  • Object
show all
Includes:
Logging::Helper
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

Methods included from Logging::Helper

#handle_exception

Constructor Details

#initialize(path) ⇒ QueryFileLogger

Returns a new instance of QueryFileLogger.



109
110
111
112
113
114
115
116
117
118
# File 'lib/legion/data/connection.rb', line 109

def initialize(path)
  @path = path
  @closed = false
  @mutex = Mutex.new
  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
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



107
108
109
# File 'lib/legion/data/connection.rb', line 107

def path
  @path
end

Instance Method Details

#closeObject



136
137
138
139
140
141
# File 'lib/legion/data/connection.rb', line 136

def close
  @mutex.synchronize do
    @closed = true
    @file.close unless @file.closed?
  end
end

#debug(message) ⇒ Object



120
121
122
# File 'lib/legion/data/connection.rb', line 120

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

#error(message) ⇒ Object



132
133
134
# File 'lib/legion/data/connection.rb', line 132

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

#info(message) ⇒ Object



124
125
126
# File 'lib/legion/data/connection.rb', line 124

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

#warn(message) ⇒ Object



128
129
130
# File 'lib/legion/data/connection.rb', line 128

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