Class: Legion::Data::Connection::QueryFileLogger
- Inherits:
-
Object
- Object
- Legion::Data::Connection::QueryFileLogger
- 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
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
- #debug(message) ⇒ Object
- #error(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(path) ⇒ QueryFileLogger
constructor
A new instance of QueryFileLogger.
- #warn(message) ⇒ Object
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
#path ⇒ Object (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
#close ⇒ Object
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() write('DEBUG', ) end |
#error(message) ⇒ Object
79 80 81 |
# File 'lib/legion/data/connection.rb', line 79 def error() write('ERROR', ) end |
#info(message) ⇒ Object
71 72 73 |
# File 'lib/legion/data/connection.rb', line 71 def info() write('INFO', ) end |
#warn(message) ⇒ Object
75 76 77 |
# File 'lib/legion/data/connection.rb', line 75 def warn() write('WARN', ) end |