GoogleAppEngineLauncher在哪里保存本地日志文件? [英] Where does GoogleAppEngineLauncher keep the local log files?

查看:120
本文介绍了GoogleAppEngineLauncher在哪里保存本地日志文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发期间,GoogleAppEngineLauncher可以在我的Mac上运行时显示我的应用程序的本地日志文件。然而,我不能在那里改变字体大小,所以我想用 tail 命令自己查看日志文件。



这是一个耻辱,但我找不到日志文件。它们不在 / var / log / 下,〜/ Library / Logs / Library /日志。你知道它们在哪吗?

(可能没有物理文件,只是python开发环境的标准输出,所以日志只能在启动程序中使用。 )

解决方案

正如你猜测的,可以通过研究源文件 / usr / local / google_appengine /google/appengine/tools/dev_appserver.py ,日志没有被写入磁盘(一个 cStringIO.StringIO 实例用于保存它们在内存中,因为的其余部分是面向将它们写入类似文件的对象)。



我会推荐正在编写自己的应用服务器脚本,该脚本导入 dev_appserver ,子类 dev_appserver.ApplicationLoggingHandler ,并覆盖 1 方法:

  from google.appengine.tools import dev_appserver 

class MyHandler(dev_appserver .ApplicationLoggingHandler):

def __init __(self, * a,** k):
dev_appserver.ApplicationLoggingHandler .__ init __(self,* a,** k)
self.thefile = open('/ tmp / mylog.txt','w')

def emit(self,record):
dev_appserver.ApplicationLoggingHandler(self,record)
self.thefile.write(str(record)+'\\\
')
self.thefile.flush()

您还需要确保使用此类而不是标准的,例如通过派生调度器的子类化或确保您使用其依赖注入功能。 ( dev_appserver_main.py 可以让你更好地控制它,我认为)。



我认为这种定制方法更多(比想象日志写入文件是完全正常的 - 毕竟要么以不同的方式显示它们,要么按照你的意愿显示它们,或者稍后用一些辅助脚本来处理它们),所以我还建议把应用程序引擎的跟踪器上的功能请求: dev_appserver.py 应该接受另一个标志,如果指定了该标志,则会提供将日志写入磁盘的路径。



而且,说实话,如果我现在需要这个功能,我自己会这样做:编辑 .py 文件(及其相关的 _main.py )添加所述标志及其用途。这应该是十几条线,比我刚刚概述的规范方式要容易得多。当然,它是很脏的,因为每当有新的SDK时,你都必须重新应用修补程序,并且一次又一次......这也是为什么 >在GAE的跟踪器上提供补丁,作为我建议的功能请求的一部分,希望它很快被接受!) -

GoogleAppEngineLauncher can display the local log file of my app while it is running on my Mac during development. However, I can't change the font size there so I would like to use the tail command to watch the log file myself.

It's a shame but I can't find the log files. They are not under /var/log/, ~/Library/Logs or /Library/Logs. Do you know where they are?

(Maybe there are no physical files, just the stdout of the python development environment and so the log is only available in the launcher application.)

解决方案

As you surmise, and can confirm by studying the source file /usr/local/google_appengine/google/appengine/tools/dev_appserver.py, the logs are not being written to disk (a cStringIO.StringIO instance is used to keep them in memory, as the rest of the code is oriented to writing them "to a file-like object").

What I would recommend is writing your own app server script, which imports dev_appserver, subclasses dev_appserver.ApplicationLoggingHandler, and overrides just one method:

from google.appengine.tools import dev_appserver

class MyHandler(dev_appserver.ApplicationLoggingHandler):

    def __init__(self, *a, **k):
        dev_appserver.ApplicationLoggingHandler.__init__(self, *a, **k)
        self.thefile = open('/tmp/mylog.txt', 'w')

    def emit(self, record):
        dev_appserver.ApplicationLoggingHandler(self, record)
        self.thefile.write(str(record) + '\n')
        self.thefile.flush()

You also need to ensure this class is used instead of the standard one, e.g. by subclassing the dispatcher or ensuring you use its dependency-injection capability. (dev_appserver_main.py lets you control this better, I think).

I think this customization approach is far more cumbersome than it should be (it's perfectly normal to want the logs written to file, after all -- either to display them differently, as you desire, or to process them later with some auxiliary script), and so I'd also recommend putting a feature request on app engine's tracker: dev_appserver.py should accept one more flag, which, if specified, gives the path on which to write logs to disk.

And, to be honest, if I needed this feature right now, myself, I'd do it the dirty way: editing that .py file (and its related _main.py) to add said flag and its use. That should be a dozen lines in all, much easier than the "canonical" way I just outlined. Of course, it is dirty because every time there's a new SDK you'll have to apply the patch again, and again, and again... which is why one should also propose the patch on GAE's tracker, as part of the feature request I suggested, hoping it gets accepted soon!-)

这篇关于GoogleAppEngineLauncher在哪里保存本地日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆