databricks pyspark -blobstoragerotatingfilehandler log到单个文件中的azure blob容器

发布于 2025-02-08 16:54:39 字数 662 浏览 3 评论 0原文

我正在使用BlobStoragerotatingFileHandler将日志从数据链球上写入Azure Blob容器。我的代码有3个日志语句,我希望将所有3个写入一个文件,但是每个语句都写入BLOB容器中的单独文件。如何在一个文件中获取所有日志语句?

import logging
from azure_storage_logging.handlers import BlobStorageRotatingFileHandler

log = logging.getLogger('service_logger')
log.setLevel(logging.DEBUG)
azure_blob_handler = BlobStorageRotatingFileHandler(filename = "name.csv",account_name="xyz",account_key="&&&",maxBytes=5000,container="abc")
azure_blob_handler.setLevel(logging.DEBUG)
log.addHandler(azure_blob_handler)
log.info("Start processing file....")
log.info("Processsed file successfully")
log.info("End file successfully")

I am using BlobStorageRotatingFileHandler to write logs from databricks to an Azure blob container. My code has 3 log statements and I want all 3 to be written to a single file, but each statement is being written to a separate file in the blob container. How do I get all log statements in one file?

import logging
from azure_storage_logging.handlers import BlobStorageRotatingFileHandler

log = logging.getLogger('service_logger')
log.setLevel(logging.DEBUG)
azure_blob_handler = BlobStorageRotatingFileHandler(filename = "name.csv",account_name="xyz",account_key="&&&",maxBytes=5000,container="abc")
azure_blob_handler.setLevel(logging.DEBUG)
log.addHandler(azure_blob_handler)
log.info("Start processing file....")
log.info("Processsed file successfully")
log.info("End file successfully")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏の忆 2025-02-15 16:54:40

根据这一点>直到日志内容未达到maxbytes并在超过maxbytes时继续上传多个文件之前,请勿上传日志。

当填充此文件时,将其关闭并重命名为app.log.1,如果文件app.log.1,app.log.2等。

。以某种方式附加了时间戳(即,日志上载的时间)。

您可以尝试的解决方法之一就是使用blobStoragerotatingFileHandler您可以尝试使用tableStorageHandler,其中结果以下面的格式显示。

PartitionKeyRowkey时间戳消息
xxxxxxxxxxxxxxxyyyy-mm-ddyyyy-mm-dd
xxxxxxxxxxxxxxxyyyy-mm-ddyyyy-mm-dd
xxxxxxxxxxxxxxxyyyy-mm-ddyyyy-mm-dd

REFERENCES: < a href="https://pypi.org/project/azure-storage-logging/#:%7E:text=The%20BlobStorageRotatingFileHandler%20class%20is%20a%20subclass%20of%20logging.handlers.RotatingFileHandler,when%20the %20元%20FILE%20REACHES%20A%20 caution%20尺。” rel =“ nofollow noreferrer”> azure-nordoraging-loging

According to this document, RotatingFileHandler does not upload the log until the log content does not reach the maxBytes and proceeds to upload multiple files consequently when it exceeds the maxBytes.

When this file is filled, it is closed and renamed to app.log.1, and if files app.log.1, app.log.2, etc.

Another reason you are facing this issue is because the filename of the blob is somehow getting appended with the timestamp (i.e., the time at which the log is getting uploaded).

One of the workarounds that you can try is instead of using BlobStorageRotatingFileHandler you can try using TableStorageHandler where the results are displayed in the below format.

PartitionKeyRowKeyTimestampmessage
XXXXXXXXXXXXXXYYYY-MM-DDYYYY-MM-DD
XXXXXXXXXXXXXXYYYY-MM-DDYYYY-MM-DD
XXXXXXXXXXXXXXYYYY-MM-DDYYYY-MM-DD

REFERENCES: azure-storage-logging

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文