python 日志记录不适用于使用谷歌应用引擎的网络应用程序

标签 python google-app-engine logging

我有一个使用谷歌应用引擎的网络应用程序。在 ubuntu 中,我使用

./dev_appserver.py /home/me/dev/mycode

在 mycode 文件夹中,我有 app.yml 和网络应用程序的 python 文件。在网络应用程序代码中,我使用日志记录来写入一些变量的值,例如

import logging
LOG_FILENAME = '/home/me/logs/mylog.txt'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)


class Handler(webapp2.RequestHandler):
    ....

class Welcome(Handler):
    def get(self):
        if self.user:
            logging.debug('rendering welcome page for user')            
            self.render('welcome.html',username= self.user.name)
        else:
            logging.debug('redirect to signup')            
            self.redirect('/signup')
class MainPage(Handler):
        def get(self):
            self.redirect('/welcome')
app = webapp2.WSGIApplication([('/', MainPage),('/signup', Register),('/welcome', Welcome)], debug=True)

我已经为日志目录设置了chmod 777..仍然没有在那里创建日志。我不知道谷歌应用引擎运行时如何查看任何日志..因为它在 linux 中,我没有带有 gui 的 launcher ..这使得很难看到应用引擎日志(如果有的话)

如果有人能帮我解决这个问题,那就太好了。

最佳答案

我有相同的环境(Ubuntu、python、gae)并且遇到了类似的日志记录问题。

您不能按照此处所述登录到本地文件:https://developers.google.com/appengine/docs/python/overview

"The sandbox ensures that apps can only perform actions that do not interfere with the performance and scalability of other apps. For instance, an app cannot write data to the local file system or make arbitrary network connections."

"The development server runs your application on your local computer for testing your application. The server simulates the App Engine datastore, services and sandbox restrictions. "

我能够让控制台日志记录按如下方式工作:

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

关于python 日志记录不适用于使用谷歌应用引擎的网络应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10649623/

相关文章:

java - GAE fetchAsync 是否会比请求的生命周期更长?

java - Logback JNDI 连接源

c# - 从控制台应用程序记录 SOAP 消息

python - 当我在循环之前使用枚举时,如何获得空列表?

python - 如何将 python 程序插入 bash 脚本?

android - 插入新实体时 id 不能为零错误

python - App Engine 正则表达式问题将 URL 定向到脚本和处理程序

python - 继承一个补丁类

Python自身属性重命名

java - Log4j2在java程序中断之前不会写入文件