Class: Legion::Data::Connection::QueryFileLogger
- Inherits:
-
Object
- Object
- Legion::Data::Connection::QueryFileLogger
- 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
-
#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
Methods included from Logging::Helper
Constructor Details
#initialize(path) ⇒ QueryFileLogger
Returns a new instance of QueryFileLogger.
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/legion/data/connection.rb', line 104 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
#path ⇒ Object (readonly)
Returns the value of attribute path.
102 103 104 |
# File 'lib/legion/data/connection.rb', line 102 def path @path end |
Instance Method Details
#close ⇒ Object
131 132 133 134 135 136 |
# File 'lib/legion/data/connection.rb', line 131 def close @mutex.synchronize do @closed = true @file.close unless @file.closed? end end |
#debug(message) ⇒ Object
115 116 117 |
# File 'lib/legion/data/connection.rb', line 115 def debug() write('DEBUG', ) end |
#error(message) ⇒ Object
127 128 129 |
# File 'lib/legion/data/connection.rb', line 127 def error() write('ERROR', ) end |
#info(message) ⇒ Object
119 120 121 |
# File 'lib/legion/data/connection.rb', line 119 def info() write('INFO', ) end |
#warn(message) ⇒ Object
123 124 125 |
# File 'lib/legion/data/connection.rb', line 123 def warn() write('WARN', ) end |