python 操作 mongodb 输出执行命令的日志

  • started() - 记录 MongoDB 命令开始执行的内容
  • succeeded() - 记录 MongoDB 命令成功执行的内容(当前被注释掉)
  • failed() - 记录 MongoDB 命令执行失败的内容
py 复制代码
import logging
from pymongo import monitoring

logging.basicConfig(level=logging.DEBUG)

class CommandLogger(monitoring.CommandListener):
    def started(self, event):
        logging.debug(f"MongoDB command started: {event.command_name} - {event.command}")

    def succeeded(self, event):
        logging.info(f"MongoDB command succeeded: {event.command_name} - {event.reply}")

    def failed(self, event):
        logging.error(f"MongoDB command failed: {event.command_name} - {event.failure}")

# 注册监听器
monitoring.register(CommandLogger())
相关推荐
Gary Studio9 分钟前
安卓HAL C++基础-智能指针
开发语言·c++
啧不应该啊21 分钟前
Day1 Python 与 C 的类型区别
c语言·开发语言
多思考少编码42 分钟前
PAT甲级真题1001 - 1005题详细题解(C++)(个人题解)
c++·python·最短路·pat·算法竞赛
cen__y1 小时前
Linux07(信号01)
linux·运维·服务器·c语言·开发语言
ZhengEnCi1 小时前
M5-markconv自定义CSS样式指南 📝
前端·css·python
xingpanvip1 小时前
星盘接口开发文档:星相日历接口指南
android·开发语言·前端·css·php·lua
ZhengEnCi1 小时前
M4-更新日志v0.1.3-Mermaid图表支持 📝
python
guygg881 小时前
基于遗传算法的双层规划模型求解MATLAB实现
开发语言·matlab
hsjcjh1 小时前
多模态长文本协同:用Gemini 3.1 Pro镜像官网破解复杂办公场景的效率困局(国内实测方案)
python
凯瑟琳.奥古斯特2 小时前
SQLAlchemy核心功能解析
开发语言·python·flask