引导金字塔中的日志记录设置问题
我正在尝试使用 python 2.7.2 和金字塔 1.2.3 在金字塔中进行简单的文件日志记录配置,
它根本无法按照我的预期工作。看起来即使我引导进入金字塔,它也没有加载正确的日志。 test.py 中的具体问题如下:
test.py
from pyramid.paster import bootstrap
env = bootstrap('../test.ini')
import logging
logging.basicConfig() #this apparently makes no difference
log=logging.getLogger('root') #same thing if I do getLogger(__name__) - it doesn't find the proj one.
print log.handlers
>>> []
这很奇怪!没有处理程序?显然这不是我想的日志。
print log
>>> logging.Logger
它不应该是一个RootLogger吗?
print log.parent
>>> [<logging.RootLogger>]
嗯,所以 getLogger('root') 的父级是真正的 RootLogger?让我们看看它的处理程序是什么:
print log.parent.handlers
>>> [<logging.StreamHandler>]
这很奇怪。
测试.ini:
[app:proj]
use = egg:proj
sqlalchemy.url = mysql+mysqldb://proj_staging:pw@localhost/proj_staging?charset=utf8
# This apparently helps avoid mysql gone away errors
sqlalchemy.pool_recycle = 3600
[pipeline:main]
pipeline = proj
[loggers]
keys = root, proj
[handlers]
keys = console, file
[formatters]
keys = generic
[logger_root]
level = INFO
handlers = file
qualname=root
[logger_proj]
level = DEBUG
handlers =
qualname = proj
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[handler_file]
class = FileHandler
args=('../logs/proj.log','a')
formatter = generic
level = INFO
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
I am trying to do simple file logging config in pyramid, with python 2.7.2 and pyramid 1.2.3
It isn't working at all how I expected. It looks like even though i'm bootstrapping into pyramid, it isn't loading the right logs. Specific problems below within test.py:
test.py
from pyramid.paster import bootstrap
env = bootstrap('../test.ini')
import logging
logging.basicConfig() #this apparently makes no difference
log=logging.getLogger('root') #same thing if I do getLogger(__name__) - it doesn't find the proj one.
print log.handlers
>>> []
That's weird! no handlers? Apparently it's not the log I am thinking of.
print log
>>> logging.Logger
shouldn't it be a RootLogger?
print log.parent
>>> [<logging.RootLogger>]
hmm so the parent of getLogger('root') is the real RootLogger? let's see what its handlers are:
print log.parent.handlers
>>> [<logging.StreamHandler>]
that's weird.
test.ini:
[app:proj]
use = egg:proj
sqlalchemy.url = mysql+mysqldb://proj_staging:pw@localhost/proj_staging?charset=utf8
# This apparently helps avoid mysql gone away errors
sqlalchemy.pool_recycle = 3600
[pipeline:main]
pipeline = proj
[loggers]
keys = root, proj
[handlers]
keys = console, file
[formatters]
keys = generic
[logger_root]
level = INFO
handlers = file
qualname=root
[logger_proj]
level = DEBUG
handlers =
qualname = proj
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[handler_file]
class = FileHandler
args=('../logs/proj.log','a')
formatter = generic
level = INFO
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Pyramid 在引导时不会加载日志配置。如果您想提出自己的观点,请在 https://github.com/Pylons 开具票证/pyramid/issues
不管怎样,自己加载日志信息非常简单:
Pyramid doesn't load the logging configuration when bootstrapping. If you want to make an argument that it should, please open a ticket at https://github.com/Pylons/pyramid/issues
Regardless, it's pretty simple to load the logging information yourself: