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 =
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 46
def initialize( = {}) @options = end
Instance Attribute Details
#options ⇒ Hash
(readonly)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 28
attr_reader :
#truncating? ⇒ Boolean
(readonly, private)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 127
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 91
def failed(event) if logger.debug? log_debug("#{prefix(event)} | FAILED | #{event.} | #{event.duration}s") end end
#format_command(args) (private)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 99
def format_command(args) begin truncating? ? truncate(args) : args.inspect rescue Exception '<Unable to inspect arguments>' end end
#prefix(event, connection_generation: nil, connection_id: nil, server_connection_id: nil) (private)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 107
def prefix(event, connection_generation: nil, connection_id: nil, server_connection_id: nil ) extra = [connection_generation, connection_id].compact.join(':') if extra == '' extra = nil else extra = "conn:#{extra}" end if server_connection_id extra += " sconn:#{server_connection_id}" end "#{event.address.to_s} 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 58
def started(event) if 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 end
#succeeded(event)
Handle the command succeeded event.
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 77
def succeeded(event) if logger.debug? log_debug("#{prefix(event)} | SUCCEEDED | #{'%.3f' % event.duration}s") end end
#truncate(command) (private)
# File 'lib/mongo/monitoring/command_log_subscriber.rb', line 123
def truncate(command) ((s = command.inspect).length > LOG_STRING_LIMIT) ? "#{s[0..LOG_STRING_LIMIT]}..." : s end