Class: Mongo::Monitoring::CommandLogSubscriber
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
::Mongo::Loggable
|
|
| Inherits: | Object |
| Defined in: | lib/mongo/monitoring/command_log_subscriber.rb |
Overview
Subscribes to command events and logs them.
Constant Summary
-
LOG_STRING_LIMIT =
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 32
Constant for the max number of characters to print when inspecting a query field.
250
::Mongo::Loggable - Included
Class Method Summary
-
.new(options = {}) ⇒ CommandLogSubscriber
constructor
Create the new log subscriber.
Instance Attribute Summary
- #options ⇒ Hash readonly
- #truncating? ⇒ Boolean readonly private
Instance Method Summary
-
#failed(event)
Handle the command failed event.
-
#started(event)
Handle the command started event.
-
#succeeded(event)
Handle the command succeeded event.
- #format_command(args) private
- #prefix(event, connection_generation: nil, connection_id: nil, server_connection_id: nil) private
- #truncate(command) private
::Mongo::Loggable - Included
| #log_debug | Convenience method to log debug messages with the standard prefix. |
| #log_error | Convenience method to log error messages with the standard prefix. |
| #log_fatal | Convenience method to log fatal messages with the standard prefix. |
| #log_info | Convenience method to log info messages with the standard prefix. |
| #log_warn | Convenience method to log warn messages with the standard prefix. |
| #logger | Get the logger instance. |
| #_mongo_log_prefix, #format_message | |
Constructor Details
.new(options = {}) ⇒ CommandLogSubscriber
Create the new log subscriber.
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 44
def initialize( = {}) @options = end
Instance Attribute Details
#options ⇒ Hash (readonly)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 26
attr_reader :
#truncating? ⇒ Boolean (readonly, private)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 119
def truncating? @truncating ||= ([:truncate_logs] != false) end
Instance Method Details
#failed(event)
Handle the command failed event.
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 88
def failed(event) return unless logger.debug? log_debug("#{prefix(event)} | FAILED | #{event.} | #{event.duration}s") end
#format_command(args) (private)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 96
def format_command(args) truncating? ? truncate(args) : args.inspect rescue Exception '<Unable to inspect arguments>' end
#prefix(event, connection_generation: nil, connection_id: nil, server_connection_id: nil) (private)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 102
def prefix(event, connection_generation: nil, connection_id: nil, server_connection_id: nil) extra = [ connection_generation, connection_id ].compact.join(':') extra = if extra == '' nil else "conn:#{extra}" end extra += " sconn:#{server_connection_id}" if server_connection_id "#{event.address} req:#{event.request_id}#{extra && " #{extra}"} | " + "#{event.database_name}.#{event.command_name}" end
#started(event)
Handle the command started event.
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 56
def started(event) return unless logger.debug? _prefix = prefix(event, connection_generation: event.connection_generation, connection_id: event.connection_id, server_connection_id: event.server_connection_id) log_debug("#{_prefix} | STARTED | #{format_command(event.command)}") end
#succeeded(event)
Handle the command succeeded event.
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 74
def succeeded(event) return unless logger.debug? log_debug("#{prefix(event)} | SUCCEEDED | #{'%.3f' % event.duration}s") end
#truncate(command) (private)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 115
def truncate(command) ((s = command.inspect).length > LOG_STRING_LIMIT) ? "#{s[0..LOG_STRING_LIMIT]}..." : s end