GoogleAppEngineLauncher 在哪里保存本地日志文件?

发布于 2024-09-01 09:24:05 字数 297 浏览 8 评论 0原文

GoogleAppEngineLauncher 可以在开发过程中在我的 Mac 上运行时显示我的应用程序的本地日志文件。但是,我无法更改那里的字体大小,因此我想使用 tail 命令自己查看日志文件。

很遗憾,但我找不到日志文件。它们不在 /var/log/~/Library/Logs/Library/Logs 下。你知道他们在哪里吗?

(也许没有物理文件,只有 python 开发环境的标准输出,因此日志仅在启动器应用程序中可用。)

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.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

旧情别恋 2024-09-08 09:24:05

正如您猜测的那样,并且可以通过研究源文件 /usr/local/google_appengine/google/appengine/tools/dev_appserver.py 来确认,日志并未写入磁盘(cStringIO .StringIO 实例用于将它们保存在内存中,因为代码的其余部分面向将它们写入“类似文件的对象”)。

我建议编写您自己的应用程序服务器脚本,该脚本导入 dev_appserver、子类 dev_appserver.ApplicationLoggingHandler,并仅覆盖一个方法:

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()

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

我认为这种定制方法比应有的要麻烦得多(毕竟,希望将日志写入文件是完全正常的——要么根据需要以不同的方式显示它们,要么稍后使用一些辅助脚本来处理它们),因此,我还建议在应用程序引擎的跟踪器上放置一个功能请求:dev_appserver.py 应该再接受一个标志,如果指定的话,它会给出将日志写入磁盘的路径。

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

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!-)

萝莉病 2024-09-08 09:24:05

其中许多答案现在已经过时了。 :)

在今天的 devappserver 中,如果您想记录到文件(以其本机 sqlite 数据库格式),请使用 --logs_path=LOGS_FILE。或者按照评论中的建议,如果太复杂,只需通过管道传输输出。

由于有日志 API,如果未设置,它现在实际上会将日志条目存储在 --storage_path 中的文件中。 不过,我自己也注意到了一些错误。(我假设它们现在不存在,我已经有一段时间没有使用它了。)

Many of these answers are now outdated. :)

In today's devappserver, use --logs_path=LOGS_FILE if you want to log to a file (in its native sqlite database format). Or as suggested in a comment, simply pipe the output if that's too complicated.

Since there's a log API, it actually now stores log entries in a file in --storage_path if not set. I have noticed a few bugs myself, though. (I'll assume they don't exist now, it's been a while since I used this.)

↘紸啶 2024-09-08 09:24:05

一个简单但又肮脏的修复方法是将以下代码添加到您的 dev_appserver.py 文件中,靠近顶部:

import logging
logging.basicConfig( filename='/tmp/gae.log', filemode='a' )

显然,将您的日志文件更改为您想要的内容。这需要最少的更改,并且在有新版本时最容易提交到您的存储库和差异中。

更新:
稍微好一点的可能是将其变成命令行选项:

def start_logging():
  import logging

  logfile=''
  for item in sys.argv[1:]:
    if re.match('--log_file=', item):
      logfile=item.split('=')[1]
      # Remove this item from sys.argv
      sys.argv.remove(item)
      break

  if logfile:
    print "Please monitor the log file (with tail -f %s)" % logfile
    logging.basicConfig( filename=logfile, filemode='a' ) 

A simple, and also dirty, fix is to add the following code into your dev_appserver.py file, towards the top:

import logging
logging.basicConfig( filename='/tmp/gae.log', filemode='a' )

Obviously, change your logfile to what you want. This requires the least amount of change, and is the easiest to commit into your repo and diff when there's a new release.

Update:
Slightly better might be to make it into a command-line option:

def start_logging():
  import logging

  logfile=''
  for item in sys.argv[1:]:
    if re.match('--log_file=', item):
      logfile=item.split('=')[1]
      # Remove this item from sys.argv
      sys.argv.remove(item)
      break

  if logfile:
    print "Please monitor the log file (with tail -f %s)" % logfile
    logging.basicConfig( filename=logfile, filemode='a' ) 
筑梦 2024-09-08 09:24:05

如果您只想在运行时查看日志,它们会与 HTTP 调用一起打印在命令行上。

logging.debug()logging.error() 不会打印,但向上调用 info 会打印。

有关更多详细信息,请参阅此答案

If you just want to see the logs at runtime, they're printed on the command-line along with the HTTP calls.

logging.debug() and logging.error() are not printed, but calls info upwards are.

See this answer for a little more detail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文