lib/semantic_logger/appender/mongodb.rb in semantic_logger-2.16.0 vs lib/semantic_logger/appender/mongodb.rb in semantic_logger-2.17.0

- old
+ new

@@ -26,10 +26,13 @@ # exception: { # name: 'MyException', # message: 'Invalid value', # stack_trace: [] # } + # # When a backtrace is captured + # file_name: 'my_class.rb' + # line_number: 42 # class MongoDB < SemanticLogger::Appender::Base attr_reader :db, :collection_name, :collection attr_accessor :host_name, :write_concern, :application @@ -153,14 +156,23 @@ document[:application] = application if application document[:message] = self.class.strip_colorizing(log.message) if log.message document[:duration] = log.duration if log.duration document[:tags] = log.tags if log.tags && (log.tags.size > 0) document[:payload] = log.payload if log.payload - document[:exception] = { - name: log.exception.class.name, - message: log.exception.message, - stack_trace: log.exception.backtrace - } if log.exception + if log.exception + document[:exception] = { + name: log.exception.class.name, + message: log.exception.message, + stack_trace: log.exception.backtrace + } + end + if log.backtrace || log.exception + backtrace = log.backtrace || log.exception.backtrace + location = backtrace[0].split('/').last + file, line = location.split(':') + document[:file_name] = file + document[:line_number] = line.to_i + end document end end # Strip the standard Rails colorizing from the logged message