Logging raw queries Generated by MongoEngine Logging raw queries Generated by MongoEngine mongodb mongodb

Logging raw queries Generated by MongoEngine


I used pymongo.monitoring in my project.

import loggingfrom pymongo import monitoringclass CommandLogger(monitoring.CommandListener):    def started(self, event):        log.debug("Command {0.command}".format(event))        logging.info("Command {0.command_name} with request id "                 "{0.request_id} started on server "                 "{0.connection_id}".format(event))    def succeeded(self, event):        logging.info("Command {0.command_name} with request id "                 "{0.request_id} on server {0.connection_id} "                 "succeeded in {0.duration_micros} "                 "microseconds".format(event))    def failed(self, event):        logging.info("Command {0.command_name} with request id "                 "{0.request_id} on server {0.connection_id} "                 "failed in {0.duration_micros} "                 "microseconds".format(event))monitoring.register(CommandLogger())

More detailed see: