代码之家  ›  专栏  ›  技术社区  ›  Koen Bok

从appengine下载日志,包括python日志语句

  •  18
  • Koen Bok  · 技术社区  · 15 年前

    我知道您可以使用appcfg.py下载原始访问日志,但我对特定请求的所有信息非常感兴趣,比如python日志记录语句、异常和API统计信息(就像在线日志查看器)。有人知道有没有其他的方法来获取信息,然后自己去构建它?

    如果有人想知道,我们要对问题进行连续统计分析,并将其显示在办公室墙上的大屏幕上。

    4 回复  |  直到 6 年前
        1
  •  21
  •   Nick Johnson    15 年前

    当然-只需将--severity标志传递给appcfg.py:

    $ appcfg.py help request_logs
    Usage: appcfg.py [options] request_logs <directory> <output_file>
    
    Write request logs in Apache common log format.
    
    The 'request_logs' command exports the request logs from your application
    to a file.  It will write Apache common log format records ordered
    chronologically.  If output file is '-' stdout will be written.
    
    Options:
      -h, --help            Show the help message and exit.
      -q, --quiet           Print errors only.
      -v, --verbose         Print info level logs.
      --noisy               Print all logs.
      -s SERVER, --server=SERVER
                            The server to connect to.
      --insecure            Use HTTP when communicating with the server.
      -e EMAIL, --email=EMAIL
                            The username to use. Will prompt if omitted.
      -H HOST, --host=HOST  Overrides the Host header sent with all RPCs.
      --no_cookies          Do not save authentication cookies to local disk.
      --passin              Read the login password from stdin.
      -A APP_ID, --application=APP_ID
                            Override application from app.yaml file.
      -V VERSION, --version=VERSION
                            Override (major) version from app.yaml file.
      -n NUM_DAYS, --num_days=NUM_DAYS
                            Number of days worth of log data to get. The cut-off
                            point is midnight UTC. Use 0 to get all available
                            logs. Default is 1, unless --append is also given;
                            then the default is 0.
      -a, --append          Append to existing file.
      --severity=SEVERITY   Severity of app-level log messages to get. The range
                            is 0 (DEBUG) through 4 (CRITICAL). If omitted, only
                            request logs are returned.
      --vhost=VHOST         The virtual host of log messages to get. If omitted,
                            all log messages are returned.
      --include_vhost       Include virtual host in log messages.
      --end_date=END_DATE   End date (as YYYY-MM-DD) of period for log data.
                            Defaults to today.
    
        2
  •  15
  •   Matt Infinite Internship    6 年前

    这对我们来说非常有效:

    appcfg.py --append --num_days=0 --include_all request_logs /path/to/your/app/ /var/log/gae/yourapp.log
    

    无论如何,如果您以前执行过日志文件,上面的行将获取所有日志记录并将它们附加到日志文件中,否则,它将创建一个新的日志文件。它实际上会查看您现有的日志(如果有),并且不会得到任何重复的日志。你可以在没有 --append 如果需要,但如果要自动下载日志,请使用它。

    这里的钥匙是 --include_all 似乎未登记的标志。如果使用GAE的Web日志查看器,此标志将获取您看到的所有数据。因此,您将得到如下字段:ms=71 cpu_ms=32 api_cpu_ms=12 cpm_usd=0.000921…等。

    好吧,我希望这能帮助别人。

    顺便说一句,我们写了一篇关于这个的博文,看看吧。 here .

        3
  •  3
  •   user1086572    11 年前

    我好像用APPCFG跑进了100米的极限。我最终使用了LogServiceAPI来获取日志

    这是密码- https://github.com/manasg/gae-log-fetcher

        4
  •  0
  •   okigan    10 年前

    这里有一种访问原始日志的方法,这样您就可以在不进行自定义解析的情况下进行进一步的处理(同样,对于我来说,请求日志并没有下载指定时间段内的所有数据)。

    这是一个应用程序,运行在appengine本身: https://gaelogapp.appspot.com/

    通过更新app.yaml和copy logs.py,您可以轻松地将此功能添加到应用程序中: https://github.com/okigan/gaelogapp