Google App Engine: Logging in dev console?

2019-01-17 22:18发布

Does logging work on the dev server? This code doesn't raise an exception, but I can't see where to view the logs in the devserver console. Perhaps I'm looking in the wrong place?

logging.error("error has occurred")

3条回答
干净又极端
2楼-- · 2019-01-17 22:42

Yes, logging works on the dev server. When dev_appserver.py is run from the command-line, you should see output from logging calls such as the one you mentioned whenever they are called.

By default, only logging messages of INFO level and higher are printed.

Also, logging.error() does not raise an exception when called. It simply logs the string you pass at the "error" level - on the development server, this basically just means it will print "ERROR" as part of the logging message on the development server.

查看更多
Explosion°爆炸
3楼-- · 2019-01-17 22:46

You can configure the default logging level when starting the development server:

dev_appserver.py --log_level=debug ...

From dev_appserver.py command-line arguments:

--log_level=...

The lowest logging level at which logging messages will be written to the console; messages of the specified logging level or higher will be output. Possible values are debug, info, warning, error, and critical.

查看更多
淡お忘
4楼-- · 2019-01-17 22:57

Make sure you create your logger. This should work.

Code

import logging

logging.getLogger().setLevel(logging.DEBUG)

logging.error("uuu")
logging.info("ggg")

Launching from the CLI

$dev_appserver.py ~/workspace/helloworld/

The logs I got on the CLI...

ERROR    2012-11-26 03:02:25,467 helloworld.py:89] uuu
INFO     2012-11-26 03:02:25,467 helloworld.py:90] ggg

Note that this also works for me in Tornado.

查看更多
登录 后发表回答