作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想记录 psycopg2 进行的查询,但是 psycopg2 documentation并没有真正指定应该如何使用 LoggingConnection。
import logging
from psycopg2.extras import LoggingConnection
db_settings = {
"user": "abcd",
"password": "efgh",
"host": "postgres.db",
"database": "dev",
}
conn = LoggingConnection(**db_settings)
报错
LoggingConnection(**db_settings) TypeError: function takes at most 2 arguments (5 given)
最佳答案
似乎设置 connection_factory=LoggingConnection
有效
import logging
import psycopg2
from psycopg2.extras import LoggingConnection
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
db_settings = {
"user": "abcd",
"password": "efgh",
"host": "postgres.db",
"database": "dev",
}
conn = psycopg2.connect(connection_factory=LoggingConnection, **db_settings)
conn.initialize(logger)
cur = conn.cursor()
cur.execute("SELECT * FROM table LIMIT 5")
关于python - 我如何使用 Psycopg2 的 LoggingConnection?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28950212/
我想记录 psycopg2 进行的查询,但是 psycopg2 documentation并没有真正指定应该如何使用 LoggingConnection。 import logging from ps
我在 Postgres 上使用 SQLAlchemy 0.9.7,以 psyopg2 作为驱动程序。 我有一个未正确关闭的杂散事务,为了调试它,我想记录所有发送到数据库的操作。 psycopg2.ex
我是一名优秀的程序员,十分优秀!