簡體   English   中英

Stackdriver Logging錯過了日志條目

[英]Stackdriver logging misses log entries

我們的團隊使用python記錄了一些用戶訪問活動。

我們創建了本地日志記錄和Google雲日志記錄(Stackdriver)來捕獲異常。

本地日志顯示5個條目

我們團隊的Stackdriver日志顯示2個條目

我還用自己的Google Cloud StackDriver日志進行了測試。 它顯示5次嘗試。

這是代碼:

local_logger = local_logging.getLogger(__name__)
local_logger.setLevel(local_logging.INFO)

handler = local_logging.FileHandler('Azure-user-access-audit-log.log')
handler.setLevel(local_logging.CRITICAL)


local_logging.Formatter.converter = time.gmtime
formatter = local_logging.Formatter('%(asctime)s | %(levelname)s | %(message)s')
handler.setFormatter(formatter)

local_logger.addHandler(handler)

os.environ["GOOGLE_APPLICATION_CREDENTIALS"]  = "my-credential.json"
logging_client = cloud_logging.Client()
log_name = 'Azure-user-access-audit-log'
cloud_logger = logging_client.logger(log_name)

............

   if item['subcriptionType'] == 'Hacker':
        user_log = str(item['cloudName'] + " - " + item['tenantId'] + " | " +
            item['subcriptionType'] + " " + item['principalName'] + " has access to " + item['subscriptionName'] + " as "
            + item['roleDefinitionName'])
        local_logger.critical(user_log)

        # The data to log to Google Cloud
        google_log_message = item['subcriptionType'] + " " + item['principalName'] + " has access to " + item['subscriptionName'] + " as " + item['roleDefinitionName']
        google_log_severity = 'CRITICAL'
        google_log_insert_id = item['cloudName'] + " - " + item['tenantId']
        print(google_log_message)
        print(google_log_severity)
        print(google_log_insert_id)

        # Writes the log entry
        # cloud_logger.log_text(str(google_log_message), severity = str(google_log_severity), insert_id = str(google_log_insert_id))
        #             # cloud_logger.log_struct({
        #             #     'subcriptionType': item['subcriptionType'],
        #             #     'principalName': item['principalName'],
        #             #     'subscriptionName': item['subscriptionName']
        #             # }, severity = str(google_log_severity), insert_id = str(google_log_insert_id))
        cloud_logger.log_text(str(google_log_message))

如果我添加了注釋掉的代碼以獲取嚴重性和insert-id,則不會有任何結果。 我很確定語法是好的。

請幫幫我。 非常感謝你們

您使用的insertId不正確。 Stackdriver Logging API 會將同一項目中具有相同時間戳和相同insertId的所有日志條目視為重復項,可以刪除 您的所有insertId值似乎都相同。 在Stackdriver Logging中看到兩個條目而不是一個的唯一原因是,通過它的兩個條目具有不同的時間戳。

您可以僅省略insertId字段。 API會自動設置一個。

暫無
暫無

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

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