Logging for MongoDB
One nice thing during Drupal 7/8 development is the ability, thanks to the devel
module, to get a list of all SQL queries ran on a page. As I've been working quite a bit on MongoDB in PHP recently, I wondered how to obtain comparable results when using MongoDB in PHP projects. Looking at the D7 implementation, the magic happens in the Database
class:
<span style="color: #000000"><span style="color: #0000BB"><?php<br></span><span style="color: #FF8000">// Start logging on the default database.<br></span><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #0000BB">DB_CHANNEL</span><span style="color: #007700">, </span><span style="color: #DD0000">'my_logging_channel'</span><span style="color: #007700">);<br>\</span><span style="color: #0000BB">Database</span><span style="color: #007700">::</span><span style="color: #0000BB">startLog</span><span style="color: #007700">(</span><span style="color: #0000BB">DB_CHANNEL</span><span style="color: #007700">);<br><br></span><span style="color: #FF8000">// Get the log contents, typically in a shutdown handler.<br></span><span style="color: #0000BB">$log </span><span style="color: #007700">= \</span><span style="color: #0000BB">Database</span><span style="color: #007700">::</span><span style="color: #0000BB">getLog</span><span style="color: #007700">(</span><span style="color: #0000BB">DB_CHANNEL</span><span style="color: #007700">);<br></span><span style="color: #0000BB">?></span></span>
With DBTNG, that's all it takes, and devel puts it to good use UI-wise. So is there be an equivalent mechanism in MongoDB ? Of course there is !