首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Stackdriver日志记录缺少日志条目

Stackdriver日志记录缺少日志条目
EN

Stack Overflow用户
提问于 2019-03-05 05:57:10
回答 1查看 241关注 0票数 0

我们的团队使用python来记录一些用户访问活动。

我们创建了本地日志和google cloud logging (Stackdriver)来捕获异常。

Local log shows 5 entries

Our team's Stackdriver log shows 2 entries

我还使用自己的google cloud stackdriver日志进行了测试。它显示了5次尝试。

代码如下:

代码语言:javascript
复制
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添加了注释掉的代码,那么什么都不会发生。我非常确定语法是好的。

请帮帮我。非常感谢你们

EN

回答 1

Stack Overflow用户

发布于 2019-04-30 05:18:19

您错误地使用了insertId。堆栈驱动程序日志API considers all log entries in the same project, with the same timestamp, and with the same insertId to be duplicates which can be removed。您的所有insertId值似乎都是相同的。在Stackdriver日志中看到两个条目而不是一个条目的唯一原因是,这两个条目具有不同的时间戳。

您可以省略insertId字段。API将自动设置一个。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54992174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档