1

zcbuildout 帮助了我的 Flask 应用程序的访问日志和根日志。没关系。现在我想知道如何从我自己的应用程序中获取日志记录。我知道如何使用日志库,但粘贴者只是不要将它记录在控制台或任何地方。

谢谢

这是我的配置:

[loggers]
keys = root, wsgi, myapp

[handlers]
keys = console, accesslog

[formatters]
keys = generic, accesslog

[formatter_generic]
format = %(asctime)s %(levelname)s [%(name)s] %(message)s

[formatter_accesslog]
format = %(message)s

[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic

[handler_accesslog]
class = FileHandler
args = (os.path.join(r'.', 'access.log'), 'a')
level = INFO
formatter = accesslog

[logger_root]
level = INFO
handlers = console

[logger_wsgi]
level = INFO
handlers = accesslog
qualname = wsgi
propagate = 0

[logger_myapp]
level = DEBUG
handlers = console
qualname = myapp

[filter:translogger]
use = egg:Paste#translogger
setup_console_handler = False
logger_name = wsgi

[app:main]
use = egg:myapp#debug
filter-with = translogger
...

这是我尝试记录的方式:

import logging as log

def myfunc():
    log.debug("show me the log")
4

1 回答 1

0

很长一段时间后,这个日志记录问题得到了解决。参考手册,Flask已经配置了自己的logger。所以要进行日志记录,请使用 flask.logger

文档在这里:

http://flask.pocoo.org/docs/api/#flask.Flask.logger

于 2013-12-18T13:14:55.037 回答