@@ -41,7 +41,10 @@ logging subscriber used internally by the driver:
41
41
include Mongo::Loggable
42
42
43
43
def started(event)
44
- log_debug("#{prefix(event)} | STARTED | #{format_command(event.command)}")
44
+ # The default inspection of a command which is a BSON document gets
45
+ # truncated in the middle. To get the full rendering of the command, the
46
+ # ``to_json`` method can be called on the document.
47
+ log_debug("#{prefix(event)} | STARTED | #{format_command(event.command.to_json)}")
45
48
end
46
49
47
50
def succeeded(event)
@@ -137,35 +140,35 @@ can look like the following:
137
140
format("SDAM | %s".freeze, message)
138
141
end
139
142
end
140
-
143
+
141
144
class TopologyOpeningLogSubscriber < SDAMLogSubscriber
142
145
private
143
-
146
+
144
147
def format_event(event)
145
148
"Topology type '#{event.topology.display_name}' initializing."
146
149
end
147
150
end
148
-
151
+
149
152
class ServerOpeningLogSubscriber < SDAMLogSubscriber
150
153
private
151
-
154
+
152
155
def format_event(event)
153
156
"Server #{event.address} initializing."
154
157
end
155
158
end
156
-
159
+
157
160
class ServerDescriptionChangedLogSubscriber < SDAMLogSubscriber
158
161
private
159
-
162
+
160
163
def format_event(event)
161
164
"Server description for #{event.address} changed from " +
162
165
"'#{event.previous_description.server_type}' to '#{event.new_description.server_type}'."
163
166
end
164
167
end
165
-
168
+
166
169
class TopologyChangedLogSubscriber < SDAMLogSubscriber
167
170
private
168
-
171
+
169
172
def format_event(event)
170
173
if event.previous_topology != event.new_topology
171
174
"Topology type '#{event.previous_topology.display_name}' changed to " +
@@ -176,18 +179,18 @@ can look like the following:
176
179
end
177
180
end
178
181
end
179
-
182
+
180
183
class ServerClosedLogSubscriber < SDAMLogSubscriber
181
184
private
182
-
185
+
183
186
def format_event(event)
184
187
"Server #{event.address} connection closed."
185
188
end
186
189
end
187
-
190
+
188
191
class TopologyClosedLogSubscriber < SDAMLogSubscriber
189
192
private
190
-
193
+
191
194
def format_event(event)
192
195
"Topology type '#{event.topology.display_name}' closed."
193
196
end
@@ -228,7 +231,7 @@ since the events may be published during the client's construction:
228
231
topology_changed_subscriber = TopologyChangedLogSubscriber.new
229
232
server_closed_subscriber = ServerClosedLogSubscriber.new
230
233
topology_closed_subscriber = TopologyClosedLogSubscriber.new
231
-
234
+
232
235
sdam_proc = Proc.new do |client|
233
236
client.subscribe(Mongo::Monitoring::TOPOLOGY_OPENING,
234
237
topology_opening_subscriber)
@@ -316,9 +319,9 @@ The following is an example logging heartbeat event subscriber:
316
319
def failed(event)
317
320
log_debug("#{event.address} | FAILED | #{event.error.class}: #{event.error.message} | #{event.duration}s")
318
321
end
319
-
322
+
320
323
private
321
-
324
+
322
325
def logger
323
326
Mongo::Logger.logger
324
327
end
0 commit comments