简体   繁体   English

python日志记录不适用于使用Google App Engine的Web应用程序

[英]python logging does not work for web app using google app engine

I have a web app that uses google app engine .In ubuntu ,I start the app engine using 我有一个使用Google App Engine的网络应用程序。在ubuntu中,我使用

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

In the mycode folder ,I have app.yml and the python files of the web app.In the web app code,I have used logging to write values of some variables like 在mycode文件夹中,我有app.yml和Web应用程序的python文件。在Web应用程序代码中,我使用日志记录来写入某些变量的值,例如

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)

I have set chmod 777 for the logs directory..Still no logs are created there.I am at a loss as to how any log can be viewed when google app engine runs..Since it is in linux,I don't have a launcher with gui ..which makes it difficult to see the app engine logs if any are generated 我已经设定chmod 777的directory..Still没有日志创建.......我日志是在不知如何任何日志可以在谷歌应用程序引擎runs..Since它是在Linux下看,我没有launcher with gui ..的launcher with gui如果生成任何应用程序日志,则很难查看

If someone can help me solve this,it would be great. 如果有人可以帮助我解决这个问题,那就太好了。

I have the same environment (Ubuntu, python, gae) and ran into similar issues with logging. 我在相同的环境(Ubuntu,python,gae)中遇到了与日志记录类似的问题。

You can't log to local file as stated here: https://developers.google.com/appengine/docs/python/overview 您无法按照此处所述登录到本地文件: 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. " “开发服务器在本地计算机上运行您的应用程序以测试您的应用程序。该服务器模拟App Engine数据存储区,服务和沙箱限制。”

I was able to getting console logging to work as follows: 我能够使控制台日志记录如下工作:

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

您是否阅读过此https://developers.google.com/appengine/articles/logging ,据我了解,您不得声明自己的日志文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM