Comments (7)
日志记录与django-db-connection-pool无关,可以通过配置对应的logger来调整日志的输出,例如你可以新增一个logger:"sqlalchemy.pool": {
"handlers": [
# 此处指向你的日志 handler
"database",
],
"level": "INFO",
"propagate": false
}
from django-db-connection-pool.
您好:
是有日志是有设置的。但是现在是不知道这个日志设置不知道是设置到哪里。
在Django项目里设置试过,并没有效果。如下:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/home/debug.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
'sqlalchemy.pool':{
'handlers': ['file'],
"level":"INFO",
"propagate":False
}
},
}
所以想问是设置到Django项目里、还是sqlalchemy里还是django-db-connection-pool里?
刚入门,小白问题麻烦您说清楚点,非常感谢。
from django-db-connection-pool.
这是 python logging 日志级别的定义
CRITICAL = 50
FATAL = CRITICAL
ERROR = 40
WARNING = 30
WARN = WARNING
INFO = 20
DEBUG = 10
NOTSET = 0
跳过 INFO 级别只想输出 WARNING 和 DEBUG ,逻辑上是有问题的
另外,如果想屏蔽 sqlalchemy 的 console 日志输出,可以在调用 dj_db_conn_pool.setup 时,传递 echo=False 来屏蔽 sqlalchemy 的 console 输出
from django-db-connection-pool.
不好意思,说错了。应该是不输出INFO级别以下的,输出WARNING 、ERROR这些应该是没问题吧?之前说成了单跳过INFO。
如果只输出WARNING 及以上级别的日志该怎么设置呢?设置在哪里呢?求教。
还有您说:“如果想屏蔽 sqlalchemy 的 console 日志输出,可以在调用 dj_db_conn_pool.setup 时,传递 echo=False 来屏蔽 sqlalchemy 的 console 输出”
这里的调用指哪一步啊?您的包只有将数据库的配置改改成这个啊:
MySQL
change django.db.backends.mysql to dj_db_conn_pool.backends.mysql:
DATABASES = {
'default': {
...
'ENGINE': 'dj_db_conn_pool.backends.mysql'
...
}
}
所以您指的调用时时加参数,是指改包代码中的调用?
再次感谢您耐心的解答,小白基础比较差望勿介意。谢谢
from django-db-connection-pool.
不客气。
如果只想输出 WARNING 及以上,应该将级别设置成 WARNING:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/home/debug.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
'sqlalchemy.pool': {
'handlers': ['file'],
# 这里需要修改日志级别
'level': 'WARNING',
'propagate': False
}
},
}
屏蔽 sqlalchemy 的 console 日志输出,可以在你的项目 settings 或者顶级 __init__.py
中添加调用 dj_db_conn_pool.setup(echo=False)
来实现,这个调用必须在 django 获取数据库连接前。
from django-db-connection-pool.
sorry,又来打扰你了。
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/home/debug.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
'sqlalchemy.pool': {
'handlers': ['file'],
# 这里需要修改日志级别
'level': 'WARNING',
'propagate': False
}
},
}
并没有什么用,反而还报错了。
项目 settings 中添加调用 dj_db_conn_pool.setup(echo=False)也报错,数据库链接就出错了。
麻烦您帮帮忙看看只显示WARNING以上的日志怎么设置。
非常感谢
from django-db-connection-pool.
建议查阅python官方文档:https://docs.python.org/zh-cn/3.6/tutorial/stdlib2.html#logging
from django-db-connection-pool.
Related Issues (20)
- postgresl无法正常插入或更新数据库 HOT 1
- New release? HOT 1
- Re-try connect in case of (specific?) errors with new connection? HOT 4
- 2006, 'MySQL server has gone away' 2013, 'Lost connection to MySQL server during query HOT 3
- save does not committing when using pool HOT 4
- dj_db_conn_pool make migrations HOT 1
- Install: pg_config executable not found. HOT 1
- django 连接oceanbase Mysql租户,make migrantions 失败, HOT 5
- I am already using a custom engine -- geodjango -- how can I also use django-db-connection-pool? HOT 1
- Test case run fails with the documented setup HOT 3
- OperationalError SSL SYSCALL error: EOF detected HOT 3
- The _ConnectionFairy.connection attribute is deprecated HOT 2
- Django 4.2 incompatibility HOT 1
- 1.2.3 is broken. HOT 4
- ORA-01036: illegal variable name/number HOT 1
- Django doesnt respect the pool configuration when using "gevent" class HOT 4
- dj_db_conn_pool.backends.postgis problem with python manage.py CMD HOT 3
- Postgis backend broken (python 3.12.1, django==5.0.1, psycopg[binary,pool]==3.1.17, sqlalchemy==2.0.25) HOT 1
- Does not detects psycopg[binary]. Tries to install psycopg2[binary]. HOT 2
- What is the difference between this and pgbouncer / other connection pooling alternatives? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-db-connection-pool.