簡體   English   中英

Google App Engine靈活環境中的原始自定義日志

[英]Raw Custom Logs in Google App Engine Flexible Environment

我在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生成的日志轉儲到雲存儲之后,我注意到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包裝。

有沒有辦法防止這種行為? 不希望重新處理這些日志以便正確格式化它們。

額外的信息實際上非常方便,特別是在appengine環境中,模塊/服務,版本或instance_id上​​的過濾可以真正幫助您調查問題。

如果重新處理日志是你的問題,我建議將導出到BigQuery功能 日志將不斷流式傳輸到BigQuery並立即查詢。 這里的好處是你可以只查詢text_payload屬性並輕松地將這個結果集導出到csv,text,json等。

至於從日志中只輸出文本行,我不相信這是可能的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM