Class: DatabaseLogger
- Inherits:
-
Object
- Object
- DatabaseLogger
- Defined in:
- lib/loggers/database_logger.rb
Class Method Summary collapse
Class Method Details
.log(severity, message, context, events, metadata) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/loggers/database_logger.rb', line 4 def self.log(severity, , context, events, ) log = nil context = context.merge({ :metadata => }) unless .empty? = Log::Utils.(, true) # In order to prevent logs from being deleted by a rollback, we need to create a new database connection (a new transaction doesn't work). # The only way to create a new database connection is to open a new thread. # Connection must be manually closed at the end of the thread. This only closes the thread's connection, not the main one. Thread.new do begin log = create_log(severity, , context, events) ensure ActiveRecord::Base.connection.close # must be done manually on new threads end end.join # we need the result of this operation before moving on. return { :db_log_id => log.id } end |