我知道您可以使用appcfg.py下载原始访问日志,但我真的对围绕特定请求的所有信息感兴趣,例如python日志记录语句,异常和api统计信息(就像在线日志查看器一样).有没有人知道是否有办法以另一种方式获取该信息,然后自己构建它?
如果有人想知道,我们想对问题进行一些连续统计分析,并将它们显示在办公室墙上的大屏幕上.
当然 - 只需将--severity标志传递给appcfg.py:
$ appcfg.py help request_logs Usage: appcfg.py [options] request_logsWrite 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.
这对我们非常有用:
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 ...等.
好的,我希望能有所帮助.
顺便说一句,我们写了一篇关于此的博文,请在这里查看.