zcbuildout帮助了我的Flask应用程序的访问日志和根日志。没关系。现在我想知道如何从我自己的应用程序中获取日志。我知道如何使用日志记录库但是paster只是不要在控制台或任何地方登录。
由于
这是我的配置:
[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")
答案 0 :(得分:0)
经过很长一段时间,此日志记录问题已得到解决。参考手册,Flask配置了自己的记录器。所以要记录,请使用flask.logger
文档在这里: