【发布时间】:2016-07-15 01:38:35
【问题描述】:
我在 Google App Engine 的灵活 (VM) 环境中使用以下代码将具有特定格式要求的自定义日志与其他应用程序日志分开:
import logging as std_logging
std_logging.basicConfig()
custom_formatter = std_logging.Formatter('%(created)f\t%(message)s')
custom_handler = std_logging.FileHandler('/var/log/app_engine/custom_logs/custom.log')
custom_handler.setFormatter(custom_formatter)
custom_logging = std_logging.getLogger('custom')
custom_logging.addHandler(custom_handler)
在普通的 Python 环境中,它们会以指定格式的纯文本行写入日志文件。
但是,在将 App Engine 生成的日志转储到 Cloud Storage 后,我注意到 App Engine 已将每个日志都包含了其他信息。
例如(为清晰起见格式化)
{
"insertId":"vsdacv1235jj1",
"log":"appengine.googleapis.com/custom.var.log.app_engine.app.custom_logs.custom.log",
"metadata":{
"labels":{
"appengine.googleapis.com/module_id":"default",
"appengine.googleapis.com/version_id":"1",
"compute.googleapis.com/resource_id":"1234256789901203",
"compute.googleapis.com/resource_name":"bbq23asd123",
"compute.googleapis.com/resource_type":"instance"
},
"projectId":"my-project",
"serviceName":"appengine.googleapis.com",
"timestamp":"2016-06-24T20:16:15Z",
"zone":"us-central1-f"
},
"textPayload":"1466799374933\tthis is my custom message"
}
textPayload 字段的值是我生成的实际日志,但由 App Engine 包装。
有没有办法防止这种行为?不希望重新处理这些日志以正确格式化它们。
【问题讨论】: